|
| 1 | +# @codelytv/mcp-test-client |
| 2 | + |
| 3 | +A TypeScript test client for Model Context Protocol (MCP) servers that provides a convenient way to test MCP functionality in your test suites. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install --save-dev @codelytv/mcp-test-client |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +### Basic Example |
| 14 | + |
| 15 | +```typescript |
| 16 | +import { McpTestClient } from '@codelytv/mcp-test-client'; |
| 17 | + |
| 18 | +const mcpClient = new McpTestClient("stdio", [ |
| 19 | + "npx", |
| 20 | + "ts-node", |
| 21 | + "./src/app/mcp/server.ts", |
| 22 | +]); |
| 23 | + |
| 24 | +await mcpClient.connect(); |
| 25 | + |
| 26 | +// List available tools |
| 27 | +const tools = await mcpClient.listTools(); |
| 28 | +console.log('Available tools:', tools.names()); |
| 29 | + |
| 30 | +// Call a tool |
| 31 | +const response = await mcpClient.callTool('search-course-by-id', { id: 'course-123' }); |
| 32 | + |
| 33 | +// List resources |
| 34 | +const resources = await mcpClient.listResources(); |
| 35 | +console.log('Available resources:', resources.uris()); |
| 36 | + |
| 37 | +// Read a resource |
| 38 | +const resource = await mcpClient.readResource('courses://all'); |
| 39 | + |
| 40 | +await mcpClient.disconnect(); |
| 41 | +``` |
| 42 | + |
| 43 | +### HTTP Transport |
| 44 | + |
| 45 | +```typescript |
| 46 | +const mcpClient = new McpTestClient("http", ["http://localhost:3000/mcp"]); |
| 47 | +``` |
| 48 | + |
| 49 | +## API |
| 50 | + |
| 51 | +### McpTestClient |
| 52 | + |
| 53 | +The main client class for interacting with MCP servers. |
| 54 | + |
| 55 | +#### Constructor |
| 56 | + |
| 57 | +- `new McpTestClient(transport: "stdio" | "http", args: string[])` |
| 58 | + |
| 59 | +#### Methods |
| 60 | + |
| 61 | +- `connect()` - Connect to the MCP server |
| 62 | +- `disconnect()` - Disconnect from the MCP server |
| 63 | +- `listTools()` - List available tools |
| 64 | +- `callTool(name: string, args?: Record<string, unknown>)` - Call a tool |
| 65 | +- `listResources()` - List available resources |
| 66 | +- `readResource(uri: string)` - Read a resource |
| 67 | +- `listResourceTemplates()` - List resource templates |
| 68 | +- `completeResourceTemplateParam(uri: string, paramName: string, textToComplete: string)` - Complete resource template parameters |
| 69 | +- `listPrompts()` - List available prompts |
| 70 | +- `getPrompt(name: string, args?: Record<string, unknown>)` - Get a prompt |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +MIT |
0 commit comments