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
38 changes: 38 additions & 0 deletions src/server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,44 @@ describe("registerAppTool schema forms", () => {
});
});

describe("registerAppTool icons", () => {
it("lists the tool's icons in tools/list", async () => {
const icons = [
{
src: "https://example.com/weather-light.svg",
mimeType: "image/svg+xml",
sizes: ["any"],
theme: "light" as const,
},
{
src: "https://example.com/weather-dark.svg",
mimeType: "image/svg+xml",
sizes: ["any"],
theme: "dark" as const,
},
];
const server = new RealMcpServer({ name: "test", version: "0.0.0" });
registerAppTool(
server,
"weather",
{
description: "Get weather forecast",
icons,
_meta: { ui: { resourceUri: "ui://weather/view.html" } },
},
async () => ({ content: [{ type: "text", text: "sunny" }] }),
);
const client = new Client({ name: "client", version: "0.0.0" });
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
await server.connect(serverTransport);
await client.connect(clientTransport);

const { tools } = await client.listTools();
expect(tools[0].icons).toEqual(icons);
});
});

describe("registerAppResource", () => {
it("should register a resource with default MIME type", () => {
let capturedName: string | undefined;
Expand Down
3 changes: 3 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "../constants.js";
import type {
CallToolResult,
ClientCapabilities,
Icon,
InputRequiredResult,
McpServer,
ReadResourceResult,
Expand Down Expand Up @@ -103,6 +104,8 @@ export interface ToolConfig {
inputSchema?: ZodRawShape | StandardSchemaWithJSON;
outputSchema?: ZodRawShape | StandardSchemaWithJSON;
annotations?: ToolAnnotations;
/** Icons a client can show for the tool, listed in `tools/list` as given. */
icons?: Icon[];
_meta?: Record<string, unknown>;
}

Expand Down