How patruff/ollama-mcp-bridge works
Main Components
• Bridge (Core): This is the central controller that handles tool registration, command routing, and communication between the LLM and various MCP servers.
• LLM Client: A component that manages interactions with Ollama (as seen in files like llm-client.ts) including sending prompts and receiving structured tool-call outputs.
• MCP Client (including specialized clients): Responsible for managing the connections with various MCP servers, handling JSON-RPC communications. Look at components such as mcp-client.ts and mcp-registry.ts.
• Tool Router/Registry: This component detects which tool to call based on user input and routes the operation to the correct MCP (tool-registry.ts and possibly the constant definitions in types).
• Logger and Configuration Management: Files like logger.ts and config.ts indicate configurable options and detailed logging, which are crucial for debugging and monitoring.
• Test Components: To ensure reliability and proper routing among components, a suite of tests exists in both the “src/tests” and “tests” directories.
Relationships and Interactions
• The LLM Client (for sending and receiving messages).
• The MCP Client/Registry (which further connects to individual MCP servers for filesystem, search, GitHub, memory, image generation, etc.).
• The Tool Router that parses the user prompt, identifies the required tool, and forwards it to the corresponding MCP server.
• The LLM Client interacts bidirectionally with the Bridge: it receives prompts from the user, then sends structured commands to the Bridge for further handling.
• Configuration management (bridge_config.json), which influences how the Bridge initializes connections to each MCP.
Architectural Patterns & Technologies
• The system follows a modular architecture with clearly separated concerns:
• Command Routing (Tool Router and MCP Clients),
• Communication Handling (LLM interaction and JSON-RPC protocol),
• Configuration and Logging.
• The code structure suggests a “plug-and-play” design for MCP servers (dynamic tool registration) – an important design principle to highlight.
• Multiple directories (src vs. tests) suggest strong unit and integration testing practices.
• Use of TypeScript for type safety, which is critical in a system relying on structured message passing and multiple client interactions.
Additional Details
• Optionally, highlight the startup sequence, which begins by reading the configuration, initializing the Bridge, setting up LLM and MCP clients, and then waiting for user, command, and tool calls.