You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-server/tools.mdx
+14-33Lines changed: 14 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,45 +9,26 @@ import { Render } from "~/components";
9
9
10
10
Model Context Protocol (MCP) tools are functions that a [MCP Server](/agents/model-context-protocol/mcp-server) provides and MCP clients can call.
11
11
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.
13
13
14
14
For example, the following code defines a simple MCP server that adds two numbers together:
15
15
16
16
{/* TODO: Reference code in Github, link to a runnable example, use Deploy to Workers button */}
server =newMcpServer({ 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
+
);
33
32
}
34
33
}
35
34
```
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