Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Rspack Bundle Analysis
Main CompilerSource:
Total emitted JS: 6.33 MB Runtime CompilerSource:
Total emitted JS: 5.36 MB Package Footprint (npm pack + npm install)
|
|
| Filename | Overview |
|---|---|
| packages/xmcp/src/runtime/utils/tool-registry.ts | New ToolRegistry class; transformToolHandler recreated on every call() and extra passed to called tools lacks augmented listTools/callTool methods. |
| packages/xmcp/src/runtime/utils/tools.ts | Injects listTools/callTool via wrappedHandler but passes original extra to registry.call(), breaking nested callTool usage. |
| examples/code-mode-http/src/tools/execute.ts | execute meta-tool; JSON.parse(args) unguarded, will throw SyntaxError on invalid JSON instead of returning a clean isError response. |
| apps/website/content/docs/guides/code-mode.mdx | New Code Mode guide; quickstart execute snippet has the same unguarded JSON.parse issue. |
| packages/xmcp/src/types/tool.ts | Adds internal flag, ToolInfo, CallToolResultCompat, and listTools/callTool signatures — clean, well-typed additions. |
| examples/code-mode-http/src/utils/search-utils.ts | Standalone TF-IDF + Levenshtein fuzzy search utility; logic is sound. |
| examples/code-mode-http/src/tools/search.ts | search meta-tool with tag pre-filtering and lazy index caching; correct. |
| packages/xmcp/src/index.ts | Exports ToolInfo and CallToolResultCompat — minimal, correct change. |
Comments Outside Diff (3)
-
examples/code-mode-http/src/tools/execute.ts, line 377-378 (link)JSON.parsecan throw an uncaughtSyntaxErrorJSON.parse(args)will throw aSyntaxErrorif the agent passes a malformed JSON string (e.g."{name: World}"). Because it's not wrapped in a try/catch, this exception propagates up rather than returning a cleanisError: trueresponse — contradicting the "never throws" contract ofcallTool.Prompt To Fix With AI
This is a comment left during a code review. Path: examples/code-mode-http/src/tools/execute.ts Line: 377-378 Comment: **`JSON.parse` can throw an uncaught `SyntaxError`** `JSON.parse(args)` will throw a `SyntaxError` if the agent passes a malformed JSON string (e.g. `"{name: World}"`). Because it's not wrapped in a try/catch, this exception propagates up rather than returning a clean `isError: true` response — contradicting the "never throws" contract of `callTool`. How can I resolve this? If you propose a fix, please make it concise.
-
packages/xmcp/src/runtime/utils/tools.ts, line 914-916 (link)Nested
callToolcalls inside a called tool will failregistry.call(name, toolArgs, extra)passes the original MCPextraobject (withoutlistToolsorcallToolon it). The inner tool's handler consequently receives rawextra, so if that tool also tries to useextra.callTool(...)orextra.listTools(), those methods won't exist — causing a silent runtime TypeError.The PR description explicitly shows tool chaining as a feature (e.g.
onboardUsercallingcreate-userthensend-welcome-email). If any of those called tools themselves need to invoke other tools, it will break.The fix is to pass
augmentedExtrainstead ofextraso the augmented methods are propagated through the call chain:const augmentedExtra: any = { ...extra, listTools: () => registry.list(), callTool: (name: string, toolArgs: Record<string, unknown>) => registry.call(name, toolArgs, augmentedExtra), };
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/xmcp/src/runtime/utils/tools.ts Line: 914-916 Comment: **Nested `callTool` calls inside a called tool will fail** `registry.call(name, toolArgs, extra)` passes the original MCP `extra` object (without `listTools` or `callTool` on it). The inner tool's handler consequently receives raw `extra`, so if that tool also tries to use `extra.callTool(...)` or `extra.listTools()`, those methods won't exist — causing a silent runtime TypeError. The PR description explicitly shows tool chaining as a feature (e.g. `onboardUser` calling `create-user` then `send-welcome-email`). If any of those called tools themselves need to invoke other tools, it will break. The fix is to pass `augmentedExtra` instead of `extra` so the augmented methods are propagated through the call chain: ```typescript const augmentedExtra: any = { ...extra, listTools: () => registry.list(), callTool: (name: string, toolArgs: Record<string, unknown>) => registry.call(name, toolArgs, augmentedExtra), }; ``` How can I resolve this? If you propose a fix, please make it concise.
-
packages/xmcp/src/runtime/utils/tool-registry.ts, line 843-848 (link)Transformed handler is recreated on every
call()invocationtransformToolHandler(entry.handler, ...)returns a new closure on every call. For high-throughput servers (manycallToolinvocations), this allocates an unnecessary new function object each time. Consider caching the transformed handler inToolRegistryEntryat registration time instead.Prompt To Fix With AI
This is a comment left during a code review. Path: packages/xmcp/src/runtime/utils/tool-registry.ts Line: 843-848 Comment: **Transformed handler is recreated on every `call()` invocation** `transformToolHandler(entry.handler, ...)` returns a new closure on every call. For high-throughput servers (many `callTool` invocations), this allocates an unnecessary new function object each time. Consider caching the transformed handler in `ToolRegistryEntry` at registration time instead. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: examples/code-mode-http/src/tools/execute.ts
Line: 377-378
Comment:
**`JSON.parse` can throw an uncaught `SyntaxError`**
`JSON.parse(args)` will throw a `SyntaxError` if the agent passes a malformed JSON string (e.g. `"{name: World}"`). Because it's not wrapped in a try/catch, this exception propagates up rather than returning a clean `isError: true` response — contradicting the "never throws" contract of `callTool`.
```suggestion
let parsedArgs: Record<string, unknown>;
try {
parsedArgs = JSON.parse(args);
} catch (e) {
return {
content: [{ type: "text", text: `Invalid JSON in args: ${e instanceof Error ? e.message : String(e)}` }],
isError: true,
};
}
return await extra.callTool(toolName, parsedArgs);
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/xmcp/src/runtime/utils/tools.ts
Line: 914-916
Comment:
**Nested `callTool` calls inside a called tool will fail**
`registry.call(name, toolArgs, extra)` passes the original MCP `extra` object (without `listTools` or `callTool` on it). The inner tool's handler consequently receives raw `extra`, so if that tool also tries to use `extra.callTool(...)` or `extra.listTools()`, those methods won't exist — causing a silent runtime TypeError.
The PR description explicitly shows tool chaining as a feature (e.g. `onboardUser` calling `create-user` then `send-welcome-email`). If any of those called tools themselves need to invoke other tools, it will break.
The fix is to pass `augmentedExtra` instead of `extra` so the augmented methods are propagated through the call chain:
```typescript
const augmentedExtra: any = {
...extra,
listTools: () => registry.list(),
callTool: (name: string, toolArgs: Record<string, unknown>) =>
registry.call(name, toolArgs, augmentedExtra),
};
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/xmcp/src/runtime/utils/tool-registry.ts
Line: 843-848
Comment:
**Transformed handler is recreated on every `call()` invocation**
`transformToolHandler(entry.handler, ...)` returns a new closure on every call. For high-throughput servers (many `callTool` invocations), this allocates an unnecessary new function object each time. Consider caching the transformed handler in `ToolRegistryEntry` at registration time instead.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: apps/website/content/docs/guides/code-mode.mdx
Line: 98-99
Comment:
**Docs quickstart example also has unguarded `JSON.parse`**
The same `JSON.parse(args)` issue present in the example `execute.ts` appears in the documentation code snippet. Users copying this quickstart will inherit the same silent-failure behavior for invalid JSON input. The snippet should wrap the parse in a try/catch so the documented pattern is safe by default.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Update pnpm-lock.yaml" | Re-trigger Greptile
Code Mode: Tool Introspection & Inter-Tool Calling
Adds two new primitives to xmcp's extra parameter, enabling the Code Mode hundreds of tools are exposed through just 2 meta-tools (search + execute), reducing context window token usage by 99%+.
Core changes