Developer Platform von Cloudflare
MCP-Server mit dem Agents SDK bauen
Das Agents SDK unterstützt jetzt den Bau von Remote-MCP-Servern über eine neue Klasse, die Ressourcen und Tools über das MCP-Protokoll bereitstellt und Autorisierung sowie Authentifizierung ermöglicht.
The Agents SDK now includes built-in support for building remote MCP (Model Context Protocol) servers directly as part of your Agent. This allows you to easily create and manage MCP servers, without the need for additional infrastructure or configuration.
The SDK includes a new MCPAgent class that extends the Agent class and allows you to expose resources and tools over the MCP protocol, as well as authorization and authentication to enable remote MCP servers.
export class MyMCP extends McpAgent {
server = new McpServer({
name: "Demo",
version: "1.0.0",
});
async init() {
this.server.resource(`counter`, `mcp://resource/counter`, (uri) => {
// ...
});
this.server.tool(
"add",
"Add two numbers together",
{ a: z.number(), b: z.number() },
async ({ a, b }) => {
// ...
},
);
}
}
export class MyMCP extends McpAgent<Env> {
server = new McpServer({
name: "Demo",
version: "1.0.0",
});
async init() {
this.server.resource(`counter`, `mcp://resource/counter`, (uri) => {
// ...
});
this.server.tool(
"add",
"Add two numbers together",
{ a: z.number(), b: z.number() },
async ({ a, b }) => {
// ...
},
);
}
}
``` …