Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,26 @@ describe('mcp adapter (in-memory)', () => {
}
})

it('calls a tool and returns the text content', async () => {
it('returns text and structured content for a tool with an output schema', async () => {
const { ctx, client, cleanup } = await bootPair()
try {
ctx.agent.registerTool({
id: 'echo',
description: 'Echo.',
outputSchema: {
type: 'object',
properties: { echoed: { type: 'object' } },
required: ['echoed'],
},
handler: args => ({ echoed: args }),
})

await client.listTools()
const result = await client.callTool({ name: 'echo', arguments: { foo: 'bar' } })
const content = result.content as Array<{ type: string, text: string }>
expect(content[0]!.type).toBe('text')
expect(JSON.parse(content[0]!.text)).toEqual({ echoed: { foo: 'bar' } })
expect(result.structuredContent).toEqual({ echoed: { foo: 'bar' } })
Comment thread
webfansplz marked this conversation as resolved.
}
finally {
await cleanup()
Expand Down
5 changes: 5 additions & 0 deletions packages/devframe/src/adapters/mcp/build-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ function registerToolHandlers(server: Server, ctx: DevframeNodeContext): void {
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params
try {
const tool = ctx.agent.getTool(name)
const outputSchema = tool
? tool.outputSchema ?? computeOutputSchema(tool, ctx)
: undefined
const result = await ctx.agent.invoke(name, args ?? {})
return {
content: [
Expand All @@ -162,6 +166,7 @@ function registerToolHandlers(server: Server, ctx: DevframeNodeContext): void {
text: stringifyForMcp(result),
},
],
...(outputSchema ? { structuredContent: result as Record<string, unknown> } : {}),
Comment thread
webfansplz marked this conversation as resolved.
}
Comment thread
webfansplz marked this conversation as resolved.
}
catch (error) {
Expand Down