Skip to content

Commit d5a94c1

Browse files
committed
Remove JSRPC tools, replace with standard sdk
1 parent e8a1ab7 commit d5a94c1

File tree

1 file changed

+14
-33
lines changed
  • src/content/docs/agents/model-context-protocol/mcp-server

1 file changed

+14
-33
lines changed

src/content/docs/agents/model-context-protocol/mcp-server/tools.mdx

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,26 @@ import { Render } from "~/components";
99

1010
Model Context Protocol (MCP) tools are functions that a [MCP Server](/agents/model-context-protocol/mcp-server) provides and MCP clients can call.
1111

12-
When you build MCP Servers with the `@cloudflare/model-context-protocol` package, you can define tools by writing JavaScript or TypeScript methods and decorating them with the `@mcp.tool` [decorator](https://github.com/tc39/proposal-decorators). This removes the need to manually implement the tool discovery, serialization, and invocation logic.
12+
When you build MCP Servers with the `@cloudflare/model-context-protocol` package, you can define tools using the `@modelcontextprotocol/typescript-sdk` package.
1313

1414
For example, the following code defines a simple MCP server that adds two numbers together:
1515

1616
{/* TODO: Reference code in Github, link to a runnable example, use Deploy to Workers button */}
1717

1818
```ts title="src/index.ts"
19-
import { WorkerEntrypoint, env } from "cloudflare:workers";
20-
import { WorkersMCP, mcp } from "@cloudflare/model-context-protocol";
21-
22-
@mcp({ name: "My MCP Server", version: "1.0.0", route: "/mcp" })
23-
class McpEntrypoint extends WorkerEntrypoint {
24-
@mcp.tool(`
25-
Add two numbers the way only MCP can
26-
27-
@param a {number} The first number
28-
@param b {number} The second number
29-
@returns {number} The sum of the two numbers
30-
`)
31-
add(a: number, b: number) {
32-
return a + b;
19+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
20+
import { DurableMCP } from "@cloudflare/model-context-protocol";
21+
22+
export class MyMCP extends DurableMCP {
23+
server = new McpServer({ name: "Demo", version: "1.0.0" });
24+
async init() {
25+
this.server.tool(
26+
"add",
27+
{ a: z.number(), b: z.number() },
28+
async ({ a, b }) => ({
29+
content: [{ type: "text", text: String(a + b) }],
30+
}),
31+
);
3332
}
3433
}
3534
```
36-
37-
In this example, the `add` method is decorated with the `@mcp.tool` decorator, which adds the tool to the MCP server and provides the tool's description, input parameters, and return type.
38-
39-
:::note
40-
Because decorators are a [Stage 3 TC39 proposed addition to the JavaScript language](https://github.com/tc39/proposal-decorators), to use decorators in your code, and to use the Cloudflare MCP Server SDK, you must use Wrangler v4.0.0 or later, or [`@cloudflare/vite-plugin`](https://www.npmjs.com/package/@cloudflare/vite-plugin). This ensures that decorators in your code are automatically transpiled into code that the [Cloudflare Workers runtime](/workers/reference/how-workers-works/) can understand.
41-
:::
42-
43-
### How it works
44-
45-
WIP
46-
47-
- Explain what is functionally happening here with decorators
48-
- You add JSDOC to `@mcp.tool` to describe the tool
49-
- The MCP Server SDK parses the JSDOC to extract the tool's description, input parameters, and return type
50-
- The MCP Server SDK then uses the tool's description, input parameters, and return type to serialize and deserialize the tool's input and output
51-
- The MCP Server SDK then uses the serialized input and output to call the tool
52-
53-
- Show the equivalent before/after using the raw @modelcontextprotocol/typescript-sdk — and ideally move this up to the top so that the reader "gets it" — maybe use tabs?

0 commit comments

Comments
 (0)