Skip to content

Commit 0ffa9eb

Browse files
add icons and website URL support to MCP server implementation (#459)
* add icons and website URL support to MCP server implementation * update biome schema, import types from SDK directly, and allow all CORS origins * cleanup * beep boop * Delete inspector-jesse * Create clear-mice-serve.md --------- Co-authored-by: Sunil Pai <spai@cloudflare.com>
1 parent 5ebaeb2 commit 0ffa9eb

File tree

9 files changed

+2974
-2739
lines changed

9 files changed

+2974
-2739
lines changed

.changeset/clear-mice-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
update mcp sdk

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
33
"assist": {
44
"actions": {
55
"source": {

examples/mcp-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "vite dev"
99
},
1010
"dependencies": {
11-
"@modelcontextprotocol/sdk": "^1.17.5",
11+
"@modelcontextprotocol/sdk": "^1.18.0",
1212
"nanoid": "^5.1.5"
1313
},
1414
"keywords": []

examples/mcp-elicitation-demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "",
33
"dependencies": {
4-
"@modelcontextprotocol/sdk": "^1.17.5",
4+
"@modelcontextprotocol/sdk": "^1.18.0",
55
"nanoid": "^5.1.5",
66
"react": "^19.1.1",
77
"react-dom": "^19.1.1",

examples/mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"mcp-remote": "^0.1.29"
55
},
66
"devDependencies": {
7-
"@modelcontextprotocol/sdk": "^1.17.5"
7+
"@modelcontextprotocol/sdk": "^1.18.0"
88
},
99
"keywords": [],
1010
"name": "@cloudflare/agents-mcp-example",

examples/mcp/src/server.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,33 @@ type State = { counter: number };
1111
export class MyMCP extends McpAgent<Env, State, {}> {
1212
server = new McpServer({
1313
name: "Demo",
14-
version: "1.0.0"
14+
version: "1.0.0",
15+
// Add icons and website URL to the server implementation
16+
icons: [
17+
{
18+
src: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIj48cmVjdCB4PSIzIiB5PSIzIiB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHJ4PSIyIiByeT0iMiI+PC9yZWN0PjxsaW5lIHgxPSI5IiB5MT0iOSIgeDI9IjE1IiB5Mj0iOSI+PC9saW5lPjxsaW5lIHgxPSI5IiB5MT0iMTUiIHgyPSIxNSIgeTI9IjE1Ij48L2xpbmU+PC9zdmc+",
19+
sizes: "any",
20+
mimeType: "image/svg+xml"
21+
}
22+
],
23+
websiteUrl: "https://github.com/cloudflare/agents"
1524
});
1625

1726
initialState: State = {
1827
counter: 1
1928
};
2029

2130
async init() {
31+
// Register resource - Note: Current MCP SDK doesn't support icons in resource method yet
32+
// Icons are supported at the server implementation level
2233
this.server.resource("counter", "mcp://resource/counter", (uri) => {
2334
return {
2435
contents: [{ text: String(this.state.counter), uri: uri.href }]
2536
};
2637
});
2738

39+
// Register tool - Note: Current MCP SDK doesn't support icons in tool method yet
40+
// Icons are supported at the server implementation level
2841
this.server.tool(
2942
"add",
3043
"Add to the counter, stored in the MCP",
@@ -42,6 +55,27 @@ export class MyMCP extends McpAgent<Env, State, {}> {
4255
};
4356
}
4457
);
58+
59+
// Note: To fully support icons on tools and resources, you would need to use
60+
// the server's setRequestHandler method to manually implement the list handlers
61+
// with icon metadata, as shown in the commented example below:
62+
63+
/*
64+
this.server.server.setRequestHandler("tools/list", async () => {
65+
return {
66+
tools: [{
67+
name: "add",
68+
description: "Add to the counter, stored in the MCP",
69+
inputSchema: { type: "object", properties: { a: { type: "number" } }, required: ["a"] },
70+
icons: [{
71+
src: "data:image/svg+xml;base64,...",
72+
mimeType: "image/svg+xml",
73+
sizes: "any"
74+
}]
75+
}]
76+
};
77+
});
78+
*/
4579
}
4680

4781
onStateUpdate(state: State) {

0 commit comments

Comments
 (0)