Skip to content

Commit 3d92bcd

Browse files
feat: support SDK-backed MCP tools (#31)
* feat: support SDK-backed MCP tools Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> * docs: document MCP tool support Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --------- Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent ecdf53c commit 3d92bcd

10 files changed

Lines changed: 1261 additions & 53 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ Returned by `createSession()` and `resumeSession()`. Key methods:
280280
- **`updateSettings(params)`** — update model, autonomy level, etc.
281281
- **`enterSpecMode(params?)`** — switch the current session into spec mode
282282
- **`forkSession()`** — create a forked server-side session and return its new session ID
283-
- **`addMcpServer(params)`** / **`removeMcpServer(params)`** — manage MCP servers
283+
- **`addMcpServer(params)`** / **`removeMcpServer(params)`** / **`toggleMcpServer(params)`** — manage MCP servers
284+
- **`listMcpServers()`** / **`listMcpTools()`** / **`authenticateMcpServer(params)`** — inspect and authenticate MCP servers
284285
- **`listTools(params?)`** — inspect the exec tool catalog and current allow/deny state
285286
- **`renameSession(params)`** — rename the current session
286287
- **`sessionId`** — the session ID
@@ -318,6 +319,9 @@ if (msg.type === DroidMessageType.AssistantTextDelta) {
318319
| `create_message` | Full assistant message created |
319320
| `turn_complete` | Sentinel: agent turn finished |
320321
| `session_title_updated` | Session title changed |
322+
| `mcp_status_changed` | MCP server status changed |
323+
| `mcp_auth_required` | MCP authentication required |
324+
| `mcp_auth_completed` | MCP authentication completed |
321325
| `error` | Error event from the process |
322326

323327
### Options
@@ -332,6 +336,7 @@ if (msg.type === DroidMessageType.AssistantTextDelta) {
332336
- **`reasoningEffort`**`ReasoningEffort` enum value
333337
- **`specModeModelId`** — override model used in spec mode
334338
- **`specModeReasoningEffort`** — override reasoning level used in spec mode
339+
- **`mcpServers`** — initial MCP server configurations, including SDK-backed MCP servers from `createSdkMcpServer()`
335340
- **`enabledToolIds`** — explicit exec tool allowlist
336341
- **`disabledToolIds`** — explicit exec tool denylist
337342
- **`permissionHandler`** — callback for tool confirmations
@@ -367,6 +372,7 @@ See the [`examples/`](./examples) directory for runnable examples:
367372
- **[`spec-mode-same-session.ts`](./examples/spec-mode-same-session.ts)** — approve a spec and continue in the same session
368373
- **[`spec-mode-new-session.ts`](./examples/spec-mode-new-session.ts)** — approve a spec and hand off implementation to a new session
369374
- **[`tool-controls.ts`](./examples/tool-controls.ts)** — configure allow/deny lists and inspect tool availability
375+
- **[`sdk-mcp-tool.ts`](./examples/sdk-mcp-tool.ts)** — expose SDK-defined tools to Droid through MCP
370376
- **[`fork-session.ts`](./examples/fork-session.ts)** — fork a session and continue from the new session ID
371377
- **[`list-sessions.ts`](./examples/list-sessions.ts)** — discover droid sessions saved on disk
372378

examples/sdk-mcp-tool.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { z } from 'zod';
2+
3+
import {
4+
ToolConfirmationOutcome,
5+
createSession,
6+
createSdkMcpServer,
7+
tool,
8+
} from '../src/index.js';
9+
10+
const execPath = process.env['DROID_EXEC_PATH'] ?? 'droid';
11+
12+
const sdkTools = createSdkMcpServer({
13+
name: 'sdk-tools',
14+
tools: [
15+
tool(
16+
'favorite_number',
17+
'Returns a favorite number for a person',
18+
{ name: z.string() },
19+
({ name }) => `${name}'s favorite number is 42.`
20+
),
21+
],
22+
});
23+
24+
const session = await createSession({
25+
execPath,
26+
mcpServers: [sdkTools],
27+
cwd: process.cwd(),
28+
permissionHandler: () => ToolConfirmationOutcome.ProceedOnce,
29+
});
30+
31+
try {
32+
const result = await session.send(
33+
'Use the favorite_number tool for Ada and tell me the answer.'
34+
);
35+
console.log(result.text);
36+
} finally {
37+
await session.close();
38+
}

0 commit comments

Comments
 (0)