How josharsh/mcp-server-boilerplate works
Project type and purpose
• This is an open‑source Python framework (MCP Base) for building Model Context Protocol (MCP) servers. It provides core abstractions (tools, prompts, resources), pluggable transport layers (STDIO, SSE, HTTP), configuration management, and deployment artifacts (Docker).
File structure
• Top‑level:
• Dockerfile, docker‑compose.yml, dev‑setup.sh: containerization & dev environment
• main.py: entrypoint, selects transport, starts server
• app/: actual framework code
• Inside app/:
• base/: abstract base classes (BaseTool, BasePrompt, APIClient, result types)
• tools/: example tool implementations + global_context
• prompts/: example prompt definitions
• server.py: wiring (registries + transport)
• config.py: environment & settings
• docs/transports/: documentation for each transport plugin (stdio, sse, …)
README for additional insights
• Modular plugin system (tools, prompts, resources)
• Multi‑transport support via a common server abstraction
• Emphasis on security (sandboxing, validation)
• Deployment ready (Docker, logging, env management)
a. Main components
• Client (LLM or agentic client)
• Transport Layer(s)
• MCP Server Core
– Transport Dispatcher
– Tool Registry
– Prompt Registry
– Resource Registry
• Base Modules (base classes for prompt/tool/resource)
• Config & Environment
• Deployment Infrastructure (Docker, Compose)
• External Services (APIs, file system, environment variables)
b. Relationships & interactions
1. Client → Transport Layer (e.g., STDIO, SSE, HTTP)
2. Transport Layer parses message → passes to Server Core
3. Server Core uses Config to initialize Registries
4. Dispatcher inspects request type → routes to appropriate registry
5. Registry invokes tool/prompt implementation (via BaseTool/BasePrompt)
6. Implementation may call APIClient or filesystem (sandboxed)
7. Result flows back through Dispatcher → Transport → Client
8. Logs and metrics emitted at each step
c. Architectural patterns & design principles
• Plugin/Registry pattern for extensibility
• Layered architecture: Transport → Core → Plugins → Resources
• Dependency inversion: base abstractions define interfaces, concrete modules plug in
• Configuration-driven initialization
• Security via input validation and sandboxing
d. Key technologies
• Python & Pydantic (type‑safe schemas)
• Docker, docker‑compose
• Asyncio or threads in transports (depending on implementation)
• Server‑side event streams (SSE)
• STDIO for CLI integration