javascript
// Example of integrating with Claude
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
import Anthropic from "@anthropic-ai/sdk";
// Setup MCP client
const mcpClient = new Client(...);
await mcpClient.connect(transport);
// Get available tools
const tools = await mcpClient.listTools();
const toolDefinitions = tools.map(tool => ({
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema
}));
// Setup Claude client
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
// Create message with tools
const message = await anthropic.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 1000,
messages: [{ role: "user", content: "What's the latest block on Nexus?" }],
tools: toolDefinitions
});
// Handle tool calls from Claude
for (const content of message.content) {
if (content.type === 'tool_use') {
const result = await mcpClient.callTool({
name: content.name,
arguments: content.input
});
// Send tool result back to Claude
// ...
}
}