mcp
⌘ P

Model Context Protocol Server

A lightweight Python implementation of an MCP server designed to securely expose local file system tools to an LLM running within an orchestration framework.

The Problem

Large Language Models lack direct access to local development environments. Copy-pasting context is inefficient. We need a standardized, minimal-overhead protocol to safely execute structured tool calls locally without exposing a massive attack surface.

python
import json
import logging
from typing import Any, Dict

class FastMCPServer:
    def __init__(self, tools: Dict[str, Any]):
        self.tools = tools
        self.logger = logging.getLogger("mcp")

    def handle_request(self, payload: Dict[str, Any]) -> Dict[str, Any]:
        """Process incoming MCP JSON-RPC requests."""
        if "method" not in payload:
            return {"error": "Invalid request: missing method"}
            
        tool_name = payload["method"]
        if tool_name not in self.tools:
            return {"error": f"Tool '{tool_name}' not found"}
            
        try:
            self.logger.info(f"Executing tool: {tool_name}")
            result = self.tools[tool_name](**payload.get("params", {}))
            return {"result": result}
        except Exception as e:
            self.logger.error(f"Execution failed: {e}")
            return {"error": str(e)}

# Basic tool definition
def fetch_local_context(file_path: str) -> str:
    with open(file_path, "r") as f:
        return f.read()

server = FastMCPServer({
    "fetch_context": fetch_local_context
})
/systems/mcp
system_status:active