Skip to content

Commit 1ff6146

Browse files
committed
Basic tools docs
1 parent 32a4fc5 commit 1ff6146

File tree

1 file changed

+29
-0
lines changed
  • src/content/docs/agents/model-context-protocol/mcp-server

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,32 @@ sidebar:
66
---
77

88
import { Render } from "~/components";
9+
10+
{/* Need to note that you must use Wrangler v4 since this uses decorators */}
11+
12+
Model Context Protocol (MCP) tools are functions that a [MCP Server](/agents/model-context-protocol/mcp-server) provides and MCP clients can call.
13+
14+
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. This removes the need to manually implement the tool discovery, serialization, and invocation logic.
15+
16+
For example, the following code defines a simple MCP server that adds two numbers together:
17+
18+
```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;
33+
}
34+
}
35+
```
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.

0 commit comments

Comments
 (0)