Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 21c15e7

Browse files
committed
docs: add TypeScript MCP elicitation examples
1 parent cde8d07 commit 21c15e7

2 files changed

Lines changed: 78 additions & 2 deletions

File tree

src/content/docs/user-guide/concepts/tools/mcp-tools.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,55 @@ For more information on elicitation, see the [MCP specification](https://modelco
492492
</Tab>
493493
<Tab label="TypeScript">
494494

495-
```ts
496-
// Not supported in TypeScript
495+
An MCP server can request additional information from the user by sending an elicitation request. Set up an elicitation callback to handle these requests:
496+
497+
```typescript
498+
// server.ts
499+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
500+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
501+
import { z } from 'zod'
502+
503+
const server = new McpServer({
504+
name: 'File Tools',
505+
version: '1.0.0',
506+
})
507+
508+
server.tool(
509+
'delete_files',
510+
'Delete the given files after getting user approval.',
511+
{
512+
paths: z.array(z.string()),
513+
},
514+
async ({ paths }) => {
515+
const result = await server.server.elicitInput({
516+
message: `Do you want to delete ${paths.join(', ')}?`,
517+
requestedSchema: {
518+
type: 'object',
519+
properties: {
520+
username: { type: 'string', description: 'Who is approving?' },
521+
},
522+
required: ['username'],
523+
},
524+
})
525+
526+
if (result.action !== 'accept') {
527+
return { content: [{ type: 'text', text: `User ${result.action}ed deletion` }] }
528+
}
529+
530+
// Perform deletion...
531+
const username = (result.content as { username: string }).username
532+
return { content: [{ type: 'text', text: `User ${username} approved deletion` }] }
533+
}
534+
)
535+
536+
await server.connect(new StdioServerTransport())
497537
```
538+
539+
```typescript
540+
--8<-- "user-guide/concepts/tools/mcp-tools.ts:elicitation"
541+
```
542+
543+
For more information on elicitation, see the [MCP specification](https://modelcontextprotocol.io/specification/draft/client/elicitation).
498544
</Tab>
499545
</Tabs>
500546

src/content/docs/user-guide/concepts/tools/mcp-tools.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,36 @@ const transport = new StdioServerTransport()
143143
await server.connect(transport)
144144
// --8<-- [end:mcp_server]
145145

146+
// --8<-- [start:elicitation]
147+
// client.ts
148+
import type { ElicitationCallback } from '@strands-agents/sdk'
149+
150+
const elicitationCallback: ElicitationCallback = async (_context, params) => {
151+
console.log(`ELICITATION: ${params.message}`)
152+
// Get user confirmation...
153+
return {
154+
action: 'accept',
155+
content: { username: 'myname' },
156+
}
157+
}
158+
159+
const elicitClient = new McpClient({
160+
transport: new StdioClientTransport({
161+
command: 'npx',
162+
args: ['tsx', '/path/to/server.ts'],
163+
}),
164+
elicitationCallback,
165+
})
166+
167+
const agentElicit = new Agent({
168+
tools: [elicitClient],
169+
})
170+
171+
await agentElicit.invoke("Delete 'a/b/c.txt' and share the name of the approver")
172+
173+
await elicitClient.disconnect()
174+
// --8<-- [end:elicitation]
175+
146176
// --8<-- [start:tools_overview_example]
147177
// Create MCP client with stdio transport
148178
const mcpClientOverview = new McpClient({

0 commit comments

Comments
 (0)