← Back to Projects
Library

MCP Server

A reusable, installable Python package implementing the Model Context Protocol over stdio — with dynamic tool auto-discovery, centralized logging, and Pydantic validation.

PythonMCPPydanticCLI

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 ResponseMessage with tool_results out
  • ToolLoader auto-discovery — place a *_tool.py file under tools/<category>/ and it loads without any registration code
  • Three separate log files: mcp_server.log, mcp_errors.log, mcp_tools.log with 10 MB rotation and 5 backups
  • Singleton ConfigManager loading from .env with type-safe getters (get_int, get_bool, get_list)
  • In-memory session management with configurable timeout and concurrent session limits
  • Control messages: pingpong, status, graceful shutdown

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.