MCP Server
A reusable, installable Python package implementing the Model Context Protocol over stdio — with dynamic tool auto-discovery, centralized logging, and Pydantic validation.
Overview
MCP Server is a production-ready Python package (mcp_server-1.0.0) that implements the Model Context Protocol over a JSON stdio interface. It provides the foundation used by KnowledgeBot, SysBot, and Financial Insight: a BaseTool abstraction, a ToolLoader that auto-discovers any *_tool.py file at startup, a Dispatcher that routes natural language queries to the right tool, and a layered infrastructure of config, logger, and validation modules — all packaged as an installable .whl.
Key Features
- JSON stdio protocol: send a request object in, receive a structured
ResponseMessagewithtool_resultsout ToolLoaderauto-discovery — place a*_tool.pyfile undertools/<category>/and it loads without any registration code- Three separate log files:
mcp_server.log,mcp_errors.log,mcp_tools.logwith 10 MB rotation and 5 backups - Singleton
ConfigManagerloading from.envwith type-safe getters (get_int,get_bool,get_list) - In-memory session management with configurable timeout and concurrent session limits
- Control messages:
ping→pong,status, gracefulshutdown
Technical Decisions
The dispatcher is the single logging point for all requests and tool executions — the server itself logs nothing — to keep responsibilities clearly separated and make the log files directly useful for debugging tool behaviour without noise from the transport layer. The package is distributed as a .whl so downstream apps pin an exact version rather than copying source, making core improvements propagate via dependency updates rather than copy-paste.