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
5 changes: 5 additions & 0 deletions .changeset/add-tool-icons-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/server': patch
---

Added `icons` field support to `registerTool()` and `registerToolTask()` APIs, matching the `ToolSchema` spec definition. Icons are now included in `tools/list` responses and can be updated via `tool.update()`.
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 @@ -21,6 +21,7 @@ interface McpServerInternal {
description: string | undefined,
inputSchema: StandardSchemaWithJSON | undefined,
outputSchema: StandardSchemaWithJSON | undefined,
icons: Icon[] | undefined,
annotations: ToolAnnotations | undefined,
execution: ToolExecution | undefined,
_meta: Record<string, unknown> | undefined,
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 @@ -130,6 +134,7 @@ export class ExperimentalMcpServerTasks {
config.description,
config.inputSchema,
config.outputSchema,
config.icons,
config.annotations,
execution,
config._meta,
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 @@ -770,6 +772,7 @@ export class McpServer {
description: string | undefined,
inputSchema: StandardSchemaWithJSON | undefined,
outputSchema: StandardSchemaWithJSON | undefined,
icons: Icon[] | undefined,
annotations: ToolAnnotations | undefined,
execution: ToolExecution | undefined,
_meta: Record<string, unknown> | undefined,
Expand All @@ -787,6 +790,7 @@ export class McpServer {
inputSchema,
outputSchema,
annotations,
icons,
execution,
_meta,
handler: handler,
Expand Down Expand Up @@ -823,6 +827,7 @@ export class McpServer {

if (updates.outputSchema !== undefined) registeredTool.outputSchema = updates.outputSchema;
if (updates.annotations !== undefined) registeredTool.annotations = updates.annotations;
if (updates.icons !== undefined) registeredTool.icons = updates.icons;
if (updates._meta !== undefined) registeredTool._meta = updates._meta;
if (updates.enabled !== undefined) registeredTool.enabled = updates.enabled;
this.sendToolListChanged();
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,14 +884,15 @@ 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,
title,
description,
inputSchema,
outputSchema,
icons,
annotations,
{ taskSupport: 'forbidden' },
_meta,
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
155 changes: 155 additions & 0 deletions test/integration/test/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,161 @@ 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' },
{ src: 'https://example.com/icon.svg', mimeType: 'image/svg+xml' }
]
},
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' },
{ src: 'https://example.com/icon.svg', mimeType: 'image/svg+xml' }
]);
});

/***
* Test: Tool Registration with Icons and Annotations
*/
test('should register tool with icons and annotations', 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 and annotations',
inputSchema: z.object({ name: z.string() }),
icons: [{ src: 'https://example.com/icon.png', mimeType: 'image/png' }],
annotations: { title: 'Test Tool', readOnlyHint: true }
},
async ({ name }) => ({
content: [{ type: 'text', text: `Hello, ${name}!` }]
})
);

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' }
]);
expect(result.tools[0]!.annotations).toEqual({
title: 'Test Tool',
readOnlyHint: true
});
});

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

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

// Update icons
tool.update({
icons: [{ src: 'https://example.com/new-icon.svg', mimeType: 'image/svg+xml' }]
});

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]!.icons).toEqual([
{ src: 'https://example.com/new-icon.svg', mimeType: 'image/svg+xml' }
]);
});

/***
* Test: Tool without Icons should not include icons in listing
*/
test('should not include icons in listing when not provided', 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 without icons' },
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]!.icons).toBeUndefined();
});

/***
* Test: Tool Argument Validation
*/
Expand Down
Loading