Skip to content

Commit 4ba2abb

Browse files
bryankthompsonweb-flowclaude
authored
feat: Add tool annotations for improved LLM tool understanding (#210)
* feat: Add tool annotations for improved LLM tool understanding Add readOnlyHint and title annotations to all 13 tools to help LLMs better understand tool behavior and make safer decisions. Changes: - Added annotations property to Tool interface - Added readOnlyHint: true to all read-only tools - Added title annotations for human-readable display - Updated server.tool() call to pass annotations to MCP SDK All tools are read-only operations: - fetch_documentation / fetch_*_docs (fetches docs) - search_documentation / search_*_docs (searches docs) - search_code / search_*_code (searches code) - fetch_generic_url_content (fetches URL content) - match_common_libs_owner_repo_mapping (library lookup) - ThreeJS-specific tools (reference docs, content fetch) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: Remove unnecessary type assertions per review Remove explicit 'as ToolAnnotations' type casts that TypeScript can infer from the Tool interface. This follows best practices by letting TypeScript handle type checking naturally rather than using explicit assertions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: triepod-ai <noreply@github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3763ee8 commit 4ba2abb

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

src/api/tools/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getRepoData } from "../../shared/repoData.js";
33
import { fetchUrlContent } from "./commonTools.js";
44
import { getHandlerByRepoData } from "./repoHandlers/handlers.js";
55
import type { Tool } from "./repoHandlers/RepoHandler.js";
6+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
67

78
export function getMcpTools(
89
env: Env,
@@ -25,6 +26,10 @@ export function getMcpTools(
2526
cb: async ({ url }) => {
2627
return fetchUrlContent({ url, env });
2728
},
29+
annotations: {
30+
title: "Fetch URL Content",
31+
readOnlyHint: true,
32+
},
2833
},
2934
];
3035
}

src/api/tools/repoHandlers/DefaultRepoHandler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { z } from "zod";
1414
import type { RepoData } from "../../../shared/repoData.js";
1515
import type { RepoHandler, Tool } from "./RepoHandler.js";
16+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
1617

1718
class DefaultRepoHandler implements RepoHandler {
1819
name = "default";
@@ -34,6 +35,10 @@ class DefaultRepoHandler implements RepoHandler {
3435
cb: async () => {
3536
return fetchDocumentation({ repoData, env, ctx });
3637
},
38+
annotations: {
39+
title: "Fetch Documentation",
40+
readOnlyHint: true,
41+
},
3742
},
3843
{
3944
name: searchToolName,
@@ -51,6 +56,10 @@ class DefaultRepoHandler implements RepoHandler {
5156
ctx,
5257
});
5358
},
59+
annotations: {
60+
title: "Search Documentation",
61+
readOnlyHint: true,
62+
},
5463
},
5564
{
5665
name: codeSearchToolName,
@@ -75,6 +84,10 @@ class DefaultRepoHandler implements RepoHandler {
7584
ctx,
7685
});
7786
},
87+
annotations: {
88+
title: "Search Code",
89+
readOnlyHint: true,
90+
},
7891
},
7992
];
8093
}

src/api/tools/repoHandlers/GenericRepoHandler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "../commonTools.js";
99
import { incrementRepoViewCount } from "../../utils/badge.js";
1010
import rawMapping from "./generic/static-mapping.json";
11+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
1112

1213
const badgeCountAllowedRepos = ["mcp-ui", "git-mcp"];
1314

@@ -82,6 +83,10 @@ class GenericRepoHandler implements RepoHandler {
8283
],
8384
};
8485
},
86+
annotations: {
87+
title: "Match Library to Repository",
88+
readOnlyHint: true,
89+
},
8590
},
8691
{
8792
name: "fetch_generic_documentation",
@@ -102,6 +107,10 @@ class GenericRepoHandler implements RepoHandler {
102107
};
103108
return fetchDocumentation({ repoData, env, ctx });
104109
},
110+
annotations: {
111+
title: "Fetch Generic Documentation",
112+
readOnlyHint: true,
113+
},
105114
},
106115
{
107116
name: "search_generic_documentation",
@@ -125,6 +134,10 @@ class GenericRepoHandler implements RepoHandler {
125134
};
126135
return searchRepositoryDocumentation({ repoData, query, env, ctx });
127136
},
137+
annotations: {
138+
title: "Search Generic Documentation",
139+
readOnlyHint: true,
140+
},
128141
},
129142
{
130143
name: "search_generic_code",
@@ -154,6 +167,10 @@ class GenericRepoHandler implements RepoHandler {
154167
};
155168
return searchRepositoryCode({ repoData, query, page, env, ctx });
156169
},
170+
annotations: {
171+
title: "Search Generic Code",
172+
readOnlyHint: true,
173+
},
157174
},
158175
];
159176
}

src/api/tools/repoHandlers/ReactRouterRepoHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { RepoData } from "../../../shared/repoData.js";
88
import type { RepoHandler, Tool } from "./RepoHandler.js";
99
import { getDefaultRepoHandler } from "./DefaultRepoHandler.js";
1010
import { z } from "zod";
11+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
1112

1213
class ReactRouterRepoHandler implements RepoHandler {
1314
name = "react-router";
@@ -34,6 +35,10 @@ class ReactRouterRepoHandler implements RepoHandler {
3435
ctx,
3536
});
3637
},
38+
annotations: {
39+
title: "Search Documentation",
40+
readOnlyHint: true,
41+
},
3742
};
3843

3944
// Filter out the default search tool and add our specific implementation

src/api/tools/repoHandlers/RepoHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { RepoData } from "../../../shared/repoData.js";
2+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
23

34
export interface Tool {
45
name: string;
56
description: string;
67
paramsSchema: any;
78
cb: (args: any) => Promise<any>;
9+
annotations?: ToolAnnotations;
810
}
911

1012
export interface RepoHandler {

src/api/tools/repoHandlers/ThreejsRepoHandler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
fetchThreeJsUrlsAsMarkdown,
88
} from "./threejs/utils.js";
99
import { searchRepositoryDocumentation } from "../commonTools.js";
10+
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
1011

1112
const GET_REFERENCE_DOCS_LIST_TOOL_NAME = "get_threejs_reference_docs_list";
1213
const GET_SPECIFIC_DOCS_CONTENT_TOOL_NAME = "get_threejs_specific_docs_content";
@@ -25,6 +26,10 @@ class ThreejsRepoHandler implements RepoHandler {
2526
cb: async () => {
2627
return await getReferenceDocsListAsMarkdown({ env });
2728
},
29+
annotations: {
30+
title: "Get Three.js Reference Docs List",
31+
readOnlyHint: true,
32+
},
2833
},
2934
{
3035
name: GET_SPECIFIC_DOCS_CONTENT_TOOL_NAME,
@@ -47,6 +52,10 @@ class ThreejsRepoHandler implements RepoHandler {
4752
documents: args.documents,
4853
});
4954
},
55+
annotations: {
56+
title: "Get Three.js Specific Docs Content",
57+
readOnlyHint: true,
58+
},
5059
},
5160
{
5261
name: "search_threejs_documentation",
@@ -66,6 +75,10 @@ class ThreejsRepoHandler implements RepoHandler {
6675
fallbackSearch: noopFallbackSearch,
6776
});
6877
},
78+
annotations: {
79+
title: "Search Three.js Documentation",
80+
readOnlyHint: true,
81+
},
6982
},
7083
{
7184
name: "fetch_threejs_urls_inside_docs",
@@ -87,6 +100,10 @@ class ThreejsRepoHandler implements RepoHandler {
87100
cb: async ({ urls }) => {
88101
return await fetchThreeJsUrlsAsMarkdown(urls);
89102
},
103+
annotations: {
104+
title: "Fetch Three.js URLs Inside Docs",
105+
readOnlyHint: true,
106+
},
90107
},
91108
];
92109
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class MyMCP extends McpAgent {
103103
withViewTracking(env, ctx, repoData, async (args: any) => {
104104
return tool.cb(args);
105105
}),
106+
tool.annotations ? { annotations: tool.annotations } : undefined,
106107
);
107108
});
108109
}

0 commit comments

Comments
 (0)