How rawveg/ollama-mcp works
Project Type and Purpose
• This is a Node.js–based MCP (Model Context Protocol) server, written in TypeScript and packaged as a CLI tool (src/cli.ts → ollama-mcp command).
• It sits between MCP‐compatible client applications (e.g., Claude Desktop, Cline) and Ollama’s local LLM API, translating MCP requests into Ollama API calls and returning results over HTTP.
• Its responsibilities: list models, pull models, chat, fetch model details, and manage ports/configuration.
File Structure
• Top‐level:
• package.json, tsconfig.json – Node/TypeScript build and run configuration
• mcp.json – MCP meta/config descriptor
• README.md, LICENSE – project documentation and license
• src/ directory:
• cli.ts – CLI entrypoint that parses args/env and launches the server
• index.ts – core HTTP server implementation, handlers for /models, /chat, etc.
Main Components
A. Client Layer
• MCP‐compatible applications (e.g., Claude Desktop, Cline)
• They issue HTTP requests to the MCP server on the configured port.
B. Server Layer (Node.js Process)
• CLI Launcher
• Reads PORT, OLLAMA_API, other env vars
• Loads mcp.json configuration
• Instantiates HTTP server
• HTTP Server
• Route handlers for GET /models, POST /models/pull, POST /chat, GET /models/:name
• Implements MCP request/response schema
• MCP Adapter
• Translates incoming HTTP requests to Ollama API calls
• Marshals responses back into MCP‐compatible JSON
C. External Service
• Ollama Local API (http://localhost:11434 by default)
• Endpoints for listing, pulling, chatting, model info
• Environment Variables & Config
• PORT, OLLAMA_API override defaults
• mcp.json describes how the server integrates with host MCP apps
Architectural Patterns and Design Principles
• Layered architecture: CLI bootstrapper → HTTP server → protocol adapter → external API
• Adapter pattern: abstracts Ollama API behind MCP protocol
• Twelve‐factor app: config via environment, no persistent storage
Technologies, Frameworks, and Libraries
• Node.js (v16+), TypeScript
• HTTP library (e.g., built‐in http or Express)
• mcp.json format for MCP metadata
• NPM packaging for global install and npx invocation
Essential Details to Capture
• CLI startup sequence feeding env vars and mcp.json into the server
• Port management (default 3456, overridable via PORT)
• All four HTTP endpoints and their purpose
• The stateless, on‐the‐fly translation to Ollama API calls
• Integration points at both ends: MCP client on one side, Ollama on the other