|
| 1 | +# MCP Conformance Test Server |
| 2 | + |
| 3 | +A reference implementation of an MCP server that implements all features required for conformance testing. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +This server implements: |
| 8 | + |
| 9 | +### Tools |
| 10 | +- `test_simple_text` - Returns simple text content |
| 11 | +- `test_image_content` - Returns image content (base64 PNG) |
| 12 | +- `test_audio_content` - Returns audio content (base64 WAV) |
| 13 | +- `test_embedded_resource` - Returns embedded resource |
| 14 | +- `test_multiple_content_types` - Returns mixed content types |
| 15 | +- `test_tool_with_logging` - Emits log messages during execution |
| 16 | +- `test_tool_with_progress` - Reports progress notifications |
| 17 | +- `test_error_handling` - Returns error response |
| 18 | +- `test_sampling` - Requests LLM completion from client |
| 19 | +- `test_elicitation` - Requests user input from client |
| 20 | +- `test_dynamic_tool` - Dynamically added/removed tool |
| 21 | + |
| 22 | +### Resources |
| 23 | +- `test://static-text` - Static text resource |
| 24 | +- `test://static-binary` - Static binary resource (image) |
| 25 | +- `test://template/{id}/data` - Resource template with parameter |
| 26 | +- `test://watched-resource` - Subscribable resource with updates |
| 27 | + |
| 28 | +### Prompts |
| 29 | +- `test_simple_prompt` - Simple prompt without arguments |
| 30 | +- `test_prompt_with_arguments(arg1, arg2)` - Parameterized prompt |
| 31 | +- `test_prompt_with_embedded_resource(resourceUri)` - Prompt with embedded resource |
| 32 | +- `test_prompt_with_image` - Prompt with image content |
| 33 | + |
| 34 | +### Other Capabilities |
| 35 | +- Logging at all levels (debug, info, notice, warning, error, critical, alert, emergency) |
| 36 | +- Completion support for prompt and resource arguments |
| 37 | +- List changed notifications for tools, resources, and prompts |
| 38 | +- Resource subscription and update notifications |
| 39 | + |
| 40 | +## Installation |
| 41 | + |
| 42 | +```bash |
| 43 | +npm install |
| 44 | +``` |
| 45 | + |
| 46 | +## Running the Server |
| 47 | + |
| 48 | +```bash |
| 49 | +npm start |
| 50 | +``` |
| 51 | + |
| 52 | +The server will start on `http://localhost:3000` (or the port specified in `PORT` environment variable). |
| 53 | + |
| 54 | +## Endpoints |
| 55 | + |
| 56 | +### MCP Endpoint |
| 57 | +- `POST /mcp` - Main MCP protocol endpoint |
| 58 | + |
| 59 | +### Health Check |
| 60 | +- `GET /health` - Server health check |
| 61 | + |
| 62 | +## Automatic Behaviors |
| 63 | + |
| 64 | +The server automatically demonstrates dynamic capabilities: |
| 65 | + |
| 66 | +- **Dynamic Tool** - `test_dynamic_tool` is automatically added 2 seconds after server starts |
| 67 | +- **Dynamic Resource** - `test://dynamic-resource` is automatically added 2 seconds after server starts |
| 68 | +- **Dynamic Prompt** - `test_dynamic_prompt` is automatically added 2 seconds after server starts |
| 69 | +- **Resource Updates** - `test://watched-resource` automatically updates every 3 seconds with new content |
| 70 | + |
| 71 | +These behaviors allow testing of MCP notifications without requiring manual triggers. |
| 72 | + |
| 73 | +## Example Usage |
| 74 | + |
| 75 | +### Starting the Server |
| 76 | +```bash |
| 77 | +npm start |
| 78 | +``` |
| 79 | + |
| 80 | +### Testing with MCP Inspector |
| 81 | +```bash |
| 82 | +npx @modelcontextprotocol/inspector http://localhost:3000/mcp |
| 83 | +``` |
| 84 | + |
| 85 | +### Testing with curl |
| 86 | + |
| 87 | +#### Initialize |
| 88 | +```bash |
| 89 | +curl -X POST http://localhost:3000/mcp \ |
| 90 | + -H "Content-Type: application/json" \ |
| 91 | + -d '{ |
| 92 | + "jsonrpc": "2.0", |
| 93 | + "id": 1, |
| 94 | + "method": "initialize", |
| 95 | + "params": { |
| 96 | + "protocolVersion": "2025-06-18", |
| 97 | + "capabilities": {}, |
| 98 | + "clientInfo": { |
| 99 | + "name": "test-client", |
| 100 | + "version": "1.0.0" |
| 101 | + } |
| 102 | + } |
| 103 | + }' |
| 104 | +``` |
| 105 | + |
| 106 | +#### List Tools |
| 107 | +```bash |
| 108 | +curl -X POST http://localhost:3000/mcp \ |
| 109 | + -H "Content-Type: application/json" \ |
| 110 | + -d '{ |
| 111 | + "jsonrpc": "2.0", |
| 112 | + "id": 2, |
| 113 | + "method": "tools/list" |
| 114 | + }' |
| 115 | +``` |
| 116 | + |
| 117 | +#### Call Tool |
| 118 | +```bash |
| 119 | +curl -X POST http://localhost:3000/mcp \ |
| 120 | + -H "Content-Type: application/json" \ |
| 121 | + -d '{ |
| 122 | + "jsonrpc": "2.0", |
| 123 | + "id": 3, |
| 124 | + "method": "tools/call", |
| 125 | + "params": { |
| 126 | + "name": "test_simple_text", |
| 127 | + "arguments": {} |
| 128 | + } |
| 129 | + }' |
| 130 | +``` |
| 131 | + |
| 132 | +## Conformance Testing |
| 133 | + |
| 134 | +This server implements the MCP Server Conformance Requirements specified in `../../../SERVER_REQUIREMENTS.md`. All tools, resources, and prompts use standardized naming conventions for consistent testing across SDK implementations. |
| 135 | + |
| 136 | +To run conformance tests against this server: |
| 137 | + |
| 138 | +```bash |
| 139 | +cd ../../../ |
| 140 | +npm run test:server -- --server-url http://localhost:3000/mcp --all |
| 141 | +``` |
| 142 | + |
| 143 | +## Implementation Notes |
| 144 | + |
| 145 | +- All tool, resource, and prompt names follow the standardized naming conventions (`test_*` for tools/prompts, `test://` for resources) |
| 146 | +- Names are descriptive of the feature being tested (e.g., `test_image_content`, `test_tool_with_progress`) |
| 147 | +- The server uses the TypeScript MCP SDK (`@modelcontextprotocol/sdk`) high-level API |
| 148 | +- Uses `registerTool()`, `registerResource()`, and `registerPrompt()` methods |
| 149 | +- Transport is Streamable HTTP (Express) for web-based testing compatibility |
| 150 | +- Promise rejections from notifications are caught and handled gracefully |
| 151 | + |
| 152 | +## For SDK Implementers |
| 153 | + |
| 154 | +If you're implementing MCP in another language/SDK: |
| 155 | + |
| 156 | +1. **Read the Requirements**: See `../../../SERVER_REQUIREMENTS.md` for complete specifications |
| 157 | +2. **Use This as Reference**: This TypeScript implementation demonstrates all required features |
| 158 | +3. **Follow Naming Conventions**: Use exact tool/resource/prompt names specified in requirements |
| 159 | +4. **Implement Automatic Behaviors**: Dynamic registration after 2s, resource updates every 3s |
| 160 | +5. **Handle Notifications Carefully**: Catch/ignore errors when no client is connected |
| 161 | + |
| 162 | +**Goal**: All SDK example servers provide the same interface, enabling a single test suite to verify conformance across all implementations. |
0 commit comments