|
| 1 | +# mcp-check |
| 2 | + |
1 | 3 | <p align="center"> |
2 | 4 | <a href="https://x.com/fveiras_"> |
3 | 5 | <img width="1033" height="204" alt="ascii-art-image (1)" src="https://github.com/user-attachments/assets/e77a1383-c0af-4c04-92f6-ed4b941043a3" /> |
|
8 | 10 | <a href="https://www.npmjs.com/package/mcp-check"><img alt="npm" src="https://img.shields.io/npm/v/mcp-check?style=flat-square" /></a> |
9 | 11 | </p> |
10 | 12 |
|
11 | | -### Installation |
| 13 | +A TypeScript library for testing MCP (Model Context Protocol) servers with AI models. This library allows you to execute prompts against MCP servers using various AI models (Claude, GPT) and verify tool usage and results. |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install mcp-check |
| 19 | +# or |
| 20 | +pnpm add mcp-check |
| 21 | +``` |
| 22 | + |
| 23 | +## Quick Start |
| 24 | + |
| 25 | +```typescript |
| 26 | +import { client, McpServer } from "mcp-check"; |
| 27 | + |
| 28 | +// Configure your MCP server |
| 29 | +const mcpServer = new McpServer({ |
| 30 | + url: "https://example.com/api/mcp", |
| 31 | + authorizationToken: process.env.MCP_TOKEN!, |
| 32 | + name: "example-server", |
| 33 | + type: "url", |
| 34 | +}); |
| 35 | + |
| 36 | +// Execute a prompt with AI models |
| 37 | +const agent = await client(mcpServer, ["claude-3-haiku-20240307"]) |
| 38 | + .prompt("Update the content using the available tools.") |
| 39 | + .execute(); |
| 40 | + |
| 41 | +// Check which tools were used |
| 42 | +console.log("Used tools:", agent.usedTools); |
| 43 | +console.log("Tool calls:", agent.toolCalls); |
| 44 | +``` |
| 45 | + |
| 46 | +## API Reference |
| 47 | + |
| 48 | +### McpServer |
| 49 | + |
| 50 | +Configure your MCP server connection: |
| 51 | + |
| 52 | +```typescript |
| 53 | +const mcpServer = new McpServer({ |
| 54 | + url: string, // MCP server URL |
| 55 | + authorizationToken: string, // Authorization token |
| 56 | + name: string, // Server name |
| 57 | + type: string, // Server type (e.g., "url") |
| 58 | +}); |
| 59 | +``` |
| 60 | + |
| 61 | +### client(mcpServer, models) |
| 62 | + |
| 63 | +Create a client instance to execute prompts: |
| 64 | + |
| 65 | +```typescript |
| 66 | +const agent = client(mcpServer, ["claude-3-haiku-20240307", "gpt-4"]) |
| 67 | + .prompt("Your prompt here") |
| 68 | + .execute(); |
| 69 | +``` |
| 70 | + |
| 71 | +**Parameters:** |
| 72 | +- `mcpServer`: Configured MCP server instance |
| 73 | +- `models`: Array of AI model names to use |
| 74 | + |
| 75 | +**Supported Models:** |
| 76 | +- Claude models: `claude-3-haiku-20240307`, `claude-3-5-sonnet-20240620`, etc. |
| 77 | +- OpenAI models: `gpt-4`, `gpt-3.5-turbo`, etc. |
| 78 | + |
| 79 | +### Agent Methods |
| 80 | + |
| 81 | +#### `.prompt(text: string)` |
| 82 | +Set the prompt to execute against the MCP server. |
| 83 | + |
| 84 | +#### `.execute()` |
| 85 | +Execute the prompt and return results with tool usage tracking. |
| 86 | + |
| 87 | +### Agent Properties |
| 88 | + |
| 89 | +After execution, the agent provides: |
| 90 | + |
| 91 | +#### `usedTools` |
| 92 | +Record of tools used by each model: |
| 93 | +```typescript |
| 94 | +agent.usedTools["claude-3-haiku-20240307"] // ["query_content", "update_blocks"] |
| 95 | +``` |
| 96 | + |
| 97 | +#### `toolCalls` |
| 98 | +Detailed tool call information including arguments and results: |
| 99 | +```typescript |
| 100 | +agent.toolCalls["claude-3-haiku-20240307"]["update_blocks"][0].result |
| 101 | +``` |
| 102 | + |
| 103 | +## Testing Example |
| 104 | + |
| 105 | +```typescript |
| 106 | +import { client, McpServer } from "mcp-check"; |
| 107 | + |
| 108 | +const mcpServer = new McpServer({ |
| 109 | + url: "https://example.com/api/mcp", |
| 110 | + authorizationToken: process.env.MCP_TOKEN!, |
| 111 | + name: "example-server", |
| 112 | + type: "url", |
| 113 | +}); |
| 114 | + |
| 115 | +describe("MCP Server Tests", () => { |
| 116 | + test("should use expected tools", async () => { |
| 117 | + const agent = await client(mcpServer, ["claude-3-haiku-20240307"]) |
| 118 | + .prompt("Update the content using the available tools.") |
| 119 | + .execute(); |
| 120 | + |
| 121 | + // Verify tools were used |
| 122 | + expect(agent.usedTools).toHaveProperty("claude-3-haiku-20240307"); |
| 123 | + expect(agent.usedTools["claude-3-haiku-20240307"]!).toEqual( |
| 124 | + expect.arrayContaining([ |
| 125 | + "query_content", |
| 126 | + "get_content_structure", |
| 127 | + "update_blocks", |
| 128 | + ]), |
| 129 | + ); |
| 130 | + |
| 131 | + // Verify tool calls |
| 132 | + const queryCalls = |
| 133 | + agent.toolCalls?.["claude-3-haiku-20240307"]?.["query_content"] ?? []; |
| 134 | + expect(queryCalls.length).toBeGreaterThan(0); |
| 135 | + |
| 136 | + const updateBlocks = |
| 137 | + agent.toolCalls?.["claude-3-haiku-20240307"]?.["update_blocks"] ?? []; |
| 138 | + expect(updateBlocks.length).toBeGreaterThan(0); |
| 139 | + expect(updateBlocks[0]?.result).toBeDefined(); |
| 140 | + }, 90000); |
| 141 | +}); |
| 142 | +``` |
| 143 | + |
| 144 | +## Environment Variables |
| 145 | + |
| 146 | +Set the following environment variables for AI model authentication: |
| 147 | + |
| 148 | +```bash |
| 149 | +ANTHROPIC_API_KEY=your_anthropic_key_here |
| 150 | +OPENAI_API_KEY=your_openai_key_here |
| 151 | +MCP_TOKEN=your_mcp_server_token_here |
| 152 | +``` |
0 commit comments