The Anthropic Model Context Protocol (MCP) is a standardized protocol designed to facilitate structured interactions between AI models and external tools or APIs. This extension integrates MCP with AgentKit, enabling AI agents to seamlessly perform onchain actions.
Integrating MCP with AgentKit provides several key benefits:
Standardized Protocol: MCP provides a structured, standardized way for AI models to interact with external tools, ensuring consistency and reliability.
Onchain Capabilities: Enables AI agents to perform blockchain operations such as token transfers, smart contract interactions, and more.
Flexible Integration: Easily integrates with existing agent workflows and infrastructure.
Here’s a basic example demonstrating how to set up an MCP server integrated with AgentKit:
Copy
Ask AI
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";// Initialize AgentKit with your CDP API keysconst agentKit = await AgentKit.from({ cdpApiKeyName: process.env.CDP_API_KEY_NAME, cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,});// Retrieve MCP-compatible tools from AgentKitconst { tools, toolHandler } = await getMcpTools(agentKit);// Create MCP server instanceconst server = new Server( { name: "agentkit", version: "0.1.0", }, { capabilities: { tools: {}, }, },);// Handle requests to list available toolsserver.setRequestHandler(ListToolsRequestSchema, async () => { return { tools, };});// Handle requests to execute specific toolsserver.setRequestHandler(CallToolRequestSchema, async (request) => { try { return toolHandler(request.params.name, request.params.arguments); } catch (error) { throw new Error(`Tool ${request.params.name} failed: ${error}`); }});// Set up standard input/output transport for the serverconst transport = new StdioServerTransport();// Connect the server to the transportawait server.connect(transport);