|
| 1 | +# Testing MCP Server using stdio Transport |
| 2 | + |
| 3 | +This guide explains how to test the MCP server locally using stdio transport format. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Go (for building the server) |
| 8 | +- Python 3.x (for running test client) |
| 9 | +- NATS credentials |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +1. Clone the repository: |
| 14 | +```bash |
| 15 | +git clone https://github.com/sinadarbouy/mcp-nats.git |
| 16 | +cd mcp-nats |
| 17 | +``` |
| 18 | + |
| 19 | +2. Build the server: |
| 20 | +```bash |
| 21 | +go build -o mcp-nats ./cmd/mcp-nats |
| 22 | +chmod +x mcp-nats |
| 23 | +``` |
| 24 | + |
| 25 | +## Testing Methods |
| 26 | + |
| 27 | +### Using Cursor IDE |
| 28 | + |
| 29 | +If you're using Cursor IDE, you can configure the MCP server in your settings: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "mcpServers": { |
| 34 | + "MCP_NATS_STDIO": { |
| 35 | + "command": "./mcp-nats", |
| 36 | + "args": ["--transport", "stdio"], |
| 37 | + "env": { |
| 38 | + "NATS_URL": "Your NATS server URL", |
| 39 | + "NATS_A_CREDS": "<base64 of A account creds>" |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +After configuration, you can interact with the server directly through Cursor using natural language commands. For example: |
| 47 | + |
| 48 | +1. You can tell Cursor: |
| 49 | +``` |
| 50 | +"publish dummy message to A account" |
| 51 | +``` |
| 52 | + |
| 53 | +2. Cursor will automatically translate this to an MCP tool call: |
| 54 | +```json |
| 55 | +{ |
| 56 | + "account_name": "A", |
| 57 | + "subject": "test.message", |
| 58 | + "body": "Hello from test message!" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +3. The result will be displayed: |
| 63 | +``` |
| 64 | +"Published 1 message(s) to test.message" |
| 65 | +``` |
| 66 | + |
| 67 | +This natural language interface makes it easy to interact with the MCP server without needing to remember specific command formats or tool names. |
| 68 | + |
| 69 | +### Using Python Test Client |
| 70 | + |
| 71 | +If you're not using Cursor, you can test the server using the provided Python client: |
| 72 | + |
| 73 | +1. Set up Python environment: |
| 74 | +```bash |
| 75 | +python -m venv venv |
| 76 | +source venv/bin/activate |
| 77 | +pip install --upgrade pip |
| 78 | +pip install -r docs/stdio/requirements.txt |
| 79 | +``` |
| 80 | + |
| 81 | +2. Run the example client (publish_example.py): |
| 82 | +```python |
| 83 | +from mcp_client import StdioServerParameters, stdio_client, ClientSession |
| 84 | + |
| 85 | +async def main(): |
| 86 | + server_params = StdioServerParameters( |
| 87 | + command="./mcp-nats", |
| 88 | + args=["--transport", "stdio"], |
| 89 | + env={ |
| 90 | + "NATS_URL": "Your NATS server URL", |
| 91 | + "NATS_A_CREDS": "Your base64 encoded credentials", |
| 92 | + } |
| 93 | + ) |
| 94 | + |
| 95 | + async with stdio_client(server_params) as streams: |
| 96 | + async with ClientSession(*streams) as session: |
| 97 | + await session.initialize() |
| 98 | + |
| 99 | + # List available tools |
| 100 | + response = await session.list_tools() |
| 101 | + print("Available tools:", [tool.name for tool in response.tools]) |
| 102 | + |
| 103 | + # Example: Publish a message |
| 104 | + result = await session.call_tool("publish", { |
| 105 | + "account_name": "A", |
| 106 | + "subject": "test.message", |
| 107 | + "body": "Hello from test message!" |
| 108 | + }) |
| 109 | + print("Publish result:", result.content) |
| 110 | + |
| 111 | +if __name__ == "__main__": |
| 112 | + asyncio.run(main()) |
| 113 | +``` |
| 114 | + |
| 115 | +3. Execute the example: |
| 116 | +```bash |
| 117 | +python docs/stdio/publish_example.py |
| 118 | +``` |
| 119 | + |
| 120 | +## Expected Output |
| 121 | + |
| 122 | +When running the example client, you should see output similar to: |
| 123 | + |
| 124 | +``` |
| 125 | +Available tools: ['account_backup', 'account_info', 'account_report_connections', ...] |
| 126 | +Publish result: [TextContent(type='text', text='Published 1 message(s) to test.message')] |
| 127 | +``` |
| 128 | + |
| 129 | +## Environment Variables |
| 130 | + |
| 131 | +- `NATS_URL`: The URL of your NATS server |
| 132 | +- `NATS_A_CREDS`: Base64 encoded credentials for the A account |
| 133 | + |
| 134 | +## Notes |
| 135 | + |
| 136 | +- Make sure to replace placeholder values (NATS_URL, NATS_A_CREDS) with your actual configuration |
| 137 | +- The server must be built and executable before running any tests |
| 138 | +- All credentials should be properly base64 encoded |
0 commit comments