Skip to content

Commit e2ecb3e

Browse files
committed
fix(server): include registered tool icons
1 parent 7cccc2a commit e2ecb3e

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

.changeset/register-tool-icons.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Add `icons` support to `McpServer.registerTool()` and task tool registration, and include tool icons in `tools/list` responses.

packages/server/src/experimental/tasks/mcpServer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @experimental
66
*/
77

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

1010
import type { AnyToolHandler, McpServer, RegisteredTool } from '../../server/mcp.js';
1111
import type { ToolTaskHandler } from './interfaces.js';
@@ -21,6 +21,7 @@ interface McpServerInternal {
2121
description: string | undefined,
2222
inputSchema: StandardSchemaWithJSON | undefined,
2323
outputSchema: StandardSchemaWithJSON | undefined,
24+
icons: Icon[] | undefined,
2425
annotations: ToolAnnotations | undefined,
2526
execution: ToolExecution | undefined,
2627
_meta: Record<string, unknown> | undefined,
@@ -82,6 +83,7 @@ export class ExperimentalMcpServerTasks {
8283
title?: string;
8384
description?: string;
8485
outputSchema?: OutputArgs;
86+
icons?: Icon[];
8587
annotations?: ToolAnnotations;
8688
execution?: TaskToolExecution;
8789
_meta?: Record<string, unknown>;
@@ -96,6 +98,7 @@ export class ExperimentalMcpServerTasks {
9698
description?: string;
9799
inputSchema: InputArgs;
98100
outputSchema?: OutputArgs;
101+
icons?: Icon[];
99102
annotations?: ToolAnnotations;
100103
execution?: TaskToolExecution;
101104
_meta?: Record<string, unknown>;
@@ -110,6 +113,7 @@ export class ExperimentalMcpServerTasks {
110113
description?: string;
111114
inputSchema?: InputArgs;
112115
outputSchema?: OutputArgs;
116+
icons?: Icon[];
113117
annotations?: ToolAnnotations;
114118
execution?: TaskToolExecution;
115119
_meta?: Record<string, unknown>;
@@ -130,6 +134,7 @@ export class ExperimentalMcpServerTasks {
130134
config.description,
131135
config.inputSchema,
132136
config.outputSchema,
137+
config.icons,
133138
config.annotations,
134139
execution,
135140
config._meta,

packages/server/src/server/mcp.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
CreateTaskResult,
99
CreateTaskServerContext,
1010
GetPromptResult,
11+
Icon,
1112
Implementation,
1213
ListPromptsResult,
1314
ListResourcesResult,
@@ -141,6 +142,7 @@ export class McpServer {
141142
name,
142143
title: tool.title,
143144
description: tool.description,
145+
icons: tool.icons,
144146
inputSchema: tool.inputSchema
145147
? (standardSchemaToJsonSchema(tool.inputSchema, 'input') as Tool['inputSchema'])
146148
: EMPTY_OBJECT_JSON_SCHEMA,
@@ -770,6 +772,7 @@ export class McpServer {
770772
description: string | undefined,
771773
inputSchema: StandardSchemaWithJSON | undefined,
772774
outputSchema: StandardSchemaWithJSON | undefined,
775+
icons: Icon[] | undefined,
773776
annotations: ToolAnnotations | undefined,
774777
execution: ToolExecution | undefined,
775778
_meta: Record<string, unknown> | undefined,
@@ -786,6 +789,7 @@ export class McpServer {
786789
description,
787790
inputSchema,
788791
outputSchema,
792+
icons,
789793
annotations,
790794
execution,
791795
_meta,
@@ -822,6 +826,7 @@ export class McpServer {
822826
}
823827

824828
if (updates.outputSchema !== undefined) registeredTool.outputSchema = updates.outputSchema;
829+
if (updates.icons !== undefined) registeredTool.icons = updates.icons;
825830
if (updates.annotations !== undefined) registeredTool.annotations = updates.annotations;
826831
if (updates._meta !== undefined) registeredTool._meta = updates._meta;
827832
if (updates.enabled !== undefined) registeredTool.enabled = updates.enabled;
@@ -869,6 +874,7 @@ export class McpServer {
869874
description?: string;
870875
inputSchema?: InputArgs;
871876
outputSchema?: OutputArgs;
877+
icons?: Icon[];
872878
annotations?: ToolAnnotations;
873879
_meta?: Record<string, unknown>;
874880
},
@@ -878,14 +884,15 @@ export class McpServer {
878884
throw new Error(`Tool ${name} is already registered`);
879885
}
880886

881-
const { title, description, inputSchema, outputSchema, annotations, _meta } = config;
887+
const { title, description, inputSchema, outputSchema, icons, annotations, _meta } = config;
882888

883889
return this._createRegisteredTool(
884890
name,
885891
title,
886892
description,
887893
inputSchema,
888894
outputSchema,
895+
icons,
889896
annotations,
890897
{ taskSupport: 'forbidden' },
891898
_meta,
@@ -1094,6 +1101,7 @@ export type RegisteredTool = {
10941101
description?: string;
10951102
inputSchema?: StandardSchemaWithJSON;
10961103
outputSchema?: StandardSchemaWithJSON;
1104+
icons?: Icon[];
10971105
annotations?: ToolAnnotations;
10981106
execution?: ToolExecution;
10991107
_meta?: Record<string, unknown>;
@@ -1109,6 +1117,7 @@ export type RegisteredTool = {
11091117
description?: string;
11101118
paramsSchema?: StandardSchemaWithJSON;
11111119
outputSchema?: StandardSchemaWithJSON;
1120+
icons?: Icon[];
11121121
annotations?: ToolAnnotations;
11131122
_meta?: Record<string, unknown>;
11141123
callback?: ToolCallback<StandardSchemaWithJSON>;

test/integration/test/server/mcp.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,57 @@ describe('Zod v4', () => {
10381038
});
10391039
});
10401040

1041+
/***
1042+
* Test: Tool Registration with Icons
1043+
*/
1044+
test('should register tool with icons', async () => {
1045+
const mcpServer = new McpServer({
1046+
name: 'test server',
1047+
version: '1.0'
1048+
});
1049+
const client = new Client({
1050+
name: 'test client',
1051+
version: '1.0'
1052+
});
1053+
1054+
mcpServer.registerTool(
1055+
'test',
1056+
{
1057+
icons: [
1058+
{
1059+
src: 'https://example.com/icon.png',
1060+
mimeType: 'image/png'
1061+
}
1062+
]
1063+
},
1064+
async () => ({
1065+
content: [
1066+
{
1067+
type: 'text',
1068+
text: 'Test response'
1069+
}
1070+
]
1071+
})
1072+
);
1073+
1074+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1075+
1076+
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
1077+
1078+
const result = await client.request({
1079+
method: 'tools/list'
1080+
});
1081+
1082+
expect(result.tools).toHaveLength(1);
1083+
expect(result.tools[0]!.name).toBe('test');
1084+
expect(result.tools[0]!.icons).toEqual([
1085+
{
1086+
src: 'https://example.com/icon.png',
1087+
mimeType: 'image/png'
1088+
}
1089+
]);
1090+
});
1091+
10411092
/***
10421093
* Test: Tool Registration with Parameters and Annotations
10431094
*/

0 commit comments

Comments
 (0)