|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is an MCP (Model Context Protocol) Hub server that acts as a proxy/aggregator for multiple MCP servers. It bypasses tool limitations in AI assistants (especially Cursor's 40-tool limit) and provides a unified interface to multiple MCP servers. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Build and Run |
| 12 | +```bash |
| 13 | +# Install dependencies |
| 14 | +pnpm install |
| 15 | + |
| 16 | +# Build TypeScript to JavaScript |
| 17 | +pnpm build |
| 18 | + |
| 19 | +# Run the server (after building) |
| 20 | +pnpm start |
| 21 | + |
| 22 | +# Build and run in one command |
| 23 | +pnpm dev |
| 24 | +``` |
| 25 | + |
| 26 | +### Development Workflow |
| 27 | +```bash |
| 28 | +# For testing changes locally with npx |
| 29 | +npm link # Creates a global link to the local package |
| 30 | +npx mcp-hub-mcp # Test the linked version |
| 31 | + |
| 32 | +# To unlink after testing |
| 33 | +npm unlink -g mcp-hub-mcp |
| 34 | +``` |
| 35 | + |
| 36 | +### Release Process |
| 37 | +- Uses semantic-release with Conventional Commits |
| 38 | +- Commits should follow: `type(scope): description` |
| 39 | +- Types: feat, fix, docs, style, refactor, perf, test, chore |
| 40 | +- Breaking changes: add `!` after type or `BREAKING CHANGE:` in body |
| 41 | +- Releases are automated via GitHub Actions on the main branch |
| 42 | + |
| 43 | +## Architecture |
| 44 | + |
| 45 | +### Core Components |
| 46 | + |
| 47 | +1. **src/index.ts** - Entry point that creates the MCP server with three tools: |
| 48 | + - `list-all-tools`: Lists all available tools from connected servers |
| 49 | + - `call-tool`: Executes a tool on a specific server |
| 50 | + - `find-tools`: Grep-like search for tools matching regex patterns |
| 51 | + |
| 52 | +2. **src/server-manager.ts** - `McpServerManager` class that: |
| 53 | + - Loads server configurations from JSON file |
| 54 | + - Manages connections to multiple MCP servers |
| 55 | + - Proxies tool calls to appropriate servers |
| 56 | + - Handles server lifecycle and error recovery |
| 57 | + - Implements `findTools` method for regex-based tool search |
| 58 | + |
| 59 | +3. **src/types.ts** - Type definitions and Zod schemas for: |
| 60 | + - Server configuration validation |
| 61 | + - MCP SDK type exports |
| 62 | + - Configuration file structure |
| 63 | + - Parameter schemas for all tools |
| 64 | + |
| 65 | +### Configuration |
| 66 | + |
| 67 | +The server configuration is loaded from (in order of precedence): |
| 68 | +1. Environment variable: `MCP_CONFIG_PATH` |
| 69 | +2. Command-line argument: `--config-path` |
| 70 | +3. Default location: `./mcp-config.json` or `{cwd}/mcp-config.json` |
| 71 | + |
| 72 | +Configuration format (Claude Desktop compatible): |
| 73 | +```json |
| 74 | +{ |
| 75 | + "mcpServers": { |
| 76 | + "server-name": { |
| 77 | + "command": "command-to-run", |
| 78 | + "args": ["arg1", "arg2"], |
| 79 | + "env": { "KEY": "value" } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Tool Naming Convention |
| 86 | + |
| 87 | +Tools from connected servers are prefixed with the server name: |
| 88 | +- Original tool: `list-files` |
| 89 | +- Through hub: `server-name__list-files` |
| 90 | + |
| 91 | +## Important Considerations |
| 92 | + |
| 93 | +1. **Error Handling**: The hub gracefully handles server connection failures and continues operating with available servers. |
| 94 | + |
| 95 | +2. **Environment Variables**: Server configurations can include environment variables that are passed to child processes. |
| 96 | + |
| 97 | +3. **Logging**: Uses console.error for error messages since stdout is reserved for MCP protocol communication. |
| 98 | + |
| 99 | +4. **No Tests**: Currently no test framework is set up. When implementing tests, consider: |
| 100 | + - Unit tests for server-manager.ts logic |
| 101 | + - Integration tests for MCP protocol handling |
| 102 | + - Mock MCP server responses for testing |
| 103 | + |
| 104 | +5. **TypeScript Configuration**: |
| 105 | + - Target: ES2020 |
| 106 | + - Module: NodeNext with NodeNext resolution |
| 107 | + - Strict mode enabled |
| 108 | + - Outputs to `dist/` directory |
| 109 | + - Declaration files generated |
| 110 | + |
| 111 | +6. **Dependencies**: |
| 112 | + - Keep dependencies minimal (currently only @modelcontextprotocol/sdk and zod) |
| 113 | + - All types are exported from types.ts for consistency |
| 114 | + |
| 115 | +7. **Binary Execution**: Configured as npm binary `mcp-hub-mcp` with shebang in index.ts |
0 commit comments