Skip to content
Open
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
7 changes: 6 additions & 1 deletion packages/server/src/experimental/tasks/mcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @experimental
*/

import type { StandardSchemaWithJSON, TaskToolExecution, ToolAnnotations, ToolExecution } from '@modelcontextprotocol/core';
import type { Icon, StandardSchemaWithJSON, TaskToolExecution, ToolAnnotations, ToolExecution } from '@modelcontextprotocol/core';

import type { AnyToolHandler, McpServer, RegisteredTool } from '../../server/mcp.js';
import type { ToolTaskHandler } from './interfaces.js';
Expand All @@ -23,6 +23,7 @@ interface McpServerInternal {
outputSchema: StandardSchemaWithJSON | undefined,
annotations: ToolAnnotations | undefined,
execution: ToolExecution | undefined,
icons: Icon[] | undefined,
_meta: Record<string, unknown> | undefined,
handler: AnyToolHandler<StandardSchemaWithJSON | undefined>
): RegisteredTool;
Expand Down Expand Up @@ -83,6 +84,7 @@ export class ExperimentalMcpServerTasks {
description?: string;
outputSchema?: OutputArgs;
annotations?: ToolAnnotations;
icons?: Icon[];
execution?: TaskToolExecution;
_meta?: Record<string, unknown>;
},
Expand All @@ -97,6 +99,7 @@ export class ExperimentalMcpServerTasks {
inputSchema: InputArgs;
outputSchema?: OutputArgs;
annotations?: ToolAnnotations;
icons?: Icon[];
execution?: TaskToolExecution;
_meta?: Record<string, unknown>;
},
Expand All @@ -111,6 +114,7 @@ export class ExperimentalMcpServerTasks {
inputSchema?: InputArgs;
outputSchema?: OutputArgs;
annotations?: ToolAnnotations;
icons?: Icon[];
execution?: TaskToolExecution;
_meta?: Record<string, unknown>;
},
Expand All @@ -132,6 +136,7 @@ export class ExperimentalMcpServerTasks {
config.outputSchema,
config.annotations,
execution,
config.icons,
config._meta,
handler as AnyToolHandler<StandardSchemaWithJSON | undefined>
);
Expand Down
11 changes: 10 additions & 1 deletion packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
CreateTaskResult,
CreateTaskServerContext,
GetPromptResult,
Icon,
Implementation,
ListPromptsResult,
ListResourcesResult,
Expand Down Expand Up @@ -145,6 +146,7 @@ export class McpServer {
? (standardSchemaToJsonSchema(tool.inputSchema, 'input') as Tool['inputSchema'])
: EMPTY_OBJECT_JSON_SCHEMA,
annotations: tool.annotations,
icons: tool.icons,
execution: tool.execution,
_meta: tool._meta
};
Expand Down Expand Up @@ -772,6 +774,7 @@ export class McpServer {
outputSchema: StandardSchemaWithJSON | undefined,
annotations: ToolAnnotations | undefined,
execution: ToolExecution | undefined,
icons: Icon[] | undefined,
_meta: Record<string, unknown> | undefined,
handler: AnyToolHandler<StandardSchemaWithJSON | undefined>
): RegisteredTool {
Expand All @@ -788,6 +791,7 @@ export class McpServer {
outputSchema,
annotations,
execution,
icons,
_meta,
handler: handler,
executor: createToolExecutor(inputSchema, handler),
Expand Down Expand Up @@ -822,6 +826,7 @@ export class McpServer {
}

if (updates.outputSchema !== undefined) registeredTool.outputSchema = updates.outputSchema;
if (updates.icons !== undefined) registeredTool.icons = updates.icons;
if (updates.annotations !== undefined) registeredTool.annotations = updates.annotations;
if (updates._meta !== undefined) registeredTool._meta = updates._meta;
if (updates.enabled !== undefined) registeredTool.enabled = updates.enabled;
Expand Down Expand Up @@ -870,6 +875,7 @@ export class McpServer {
inputSchema?: InputArgs;
outputSchema?: OutputArgs;
annotations?: ToolAnnotations;
icons?: Icon[];
_meta?: Record<string, unknown>;
},
cb: ToolCallback<InputArgs>
Expand All @@ -878,7 +884,7 @@ export class McpServer {
throw new Error(`Tool ${name} is already registered`);
}

const { title, description, inputSchema, outputSchema, annotations, _meta } = config;
const { title, description, inputSchema, outputSchema, annotations, icons, _meta } = config;

return this._createRegisteredTool(
name,
Expand All @@ -888,6 +894,7 @@ export class McpServer {
outputSchema,
annotations,
{ taskSupport: 'forbidden' },
icons,
_meta,
cb as ToolCallback<StandardSchemaWithJSON | undefined>
);
Expand Down Expand Up @@ -1095,6 +1102,7 @@ export type RegisteredTool = {
inputSchema?: StandardSchemaWithJSON;
outputSchema?: StandardSchemaWithJSON;
annotations?: ToolAnnotations;
icons?: Icon[];
execution?: ToolExecution;
_meta?: Record<string, unknown>;
handler: AnyToolHandler<StandardSchemaWithJSON | undefined>;
Expand All @@ -1110,6 +1118,7 @@ export type RegisteredTool = {
paramsSchema?: StandardSchemaWithJSON;
outputSchema?: StandardSchemaWithJSON;
annotations?: ToolAnnotations;
icons?: Icon[];
_meta?: Record<string, unknown>;
callback?: ToolCallback<StandardSchemaWithJSON>;
enabled?: boolean;
Expand Down
52 changes: 52 additions & 0 deletions test/integration/test/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,58 @@ describe('Zod v4', () => {
});
});

/***
* Test: Tool Registration with Icons
*/
test('should register tool with icons', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const client = new Client({
name: 'test client',
version: '1.0'
});

mcpServer.registerTool(
'test',
{
description: 'A tool with icons',
icons: [
{
src: 'https://example.com/icon.png',
mimeType: 'image/png'
}
]
},
async () => ({
content: [
{
type: 'text',
text: 'Test response'
}
]
})
);

const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();

await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);

const result = await client.request({
method: 'tools/list'
});

expect(result.tools).toHaveLength(1);
expect(result.tools[0]!.name).toBe('test');
expect(result.tools[0]!.icons).toEqual([
{
src: 'https://example.com/icon.png',
mimeType: 'image/png'
}
]);
});

/***
* Test: Tool Registration with Parameters and Annotations
*/
Expand Down
Loading