Anthropic Model Context Protocol (MCP) extension of AgentKit. Enables agentic workflows to interact with onchain actions.
npm install @coinbase/agentkit-model-context-protocol @coinbase/agentkit @modelcontextprotocol/sdk
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { getMcpTools } from "@coinbase/agentkit-model-context-protocol";
import { AgentKit } from "@coinbase/agentkit";
const agentKit = await AgentKit.from({
cdpApiKeyName: "CDP API KEY NAME",
cdpApiKeyPrivateKey: "CDP API KEY PRIVATE KEY",
});
const { tools, toolHandler } = await getMcpTools(agentKit);
const server = new Server(
{
name: "agentkit",
version: "0.1.0",
},
{
capabilities: {
tools: {},
},
},
);
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools,
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
return toolHandler(request.params.name, request.params.arguments);
} catch (error) {
throw new Error(`Tool ${name} failed: ${error}`);
}
});
const transport = new StdioServerTransport();
await server.connect(transport);
See CONTRIBUTING.md for detailed setup instructions and contribution guidelines.