MCP Tool Server

Production-ready Model Context Protocol server with file, shell, and search tools

112 Tests Passing MCP Protocol Pure Python

Architecture

AI Client
Claude, etc.
->
Transport
Stdio / WebSocket
->
MCP Server
Request Handler
->
Tools
File, Shell, Search

Built-in Tools

file_read

Read file contents with path restrictions and size limits

path: string encoding: string

file_write

Write or append content to files with directory creation

path: string content: string mode: write|append

shell

Execute shell commands with timeout and security controls

command: string timeout: integer

search

Search for patterns in files using regex (grep-like)

pattern: string path: string include: string ignore_case: bool

glob

Find files matching a glob pattern

pattern: string path: string

Quick Start

import asyncio from mcp_server import MCPServer, ServerConfig, create_server # Create server with default tools config = ServerConfig( name="my-mcp-server", allowed_paths=["/home/user/projects"], ) server = create_server(config=config) # Run via stdio asyncio.run(server.run())

Protocol Example

Request

{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "tools/call",
  "params": {
    "name": "file_read",
    "arguments": {
      "path": "/etc/hostname"
    }
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "content": [
      {
        "type": "text",
        "text": "myhost\n"
      }
    ]
  }
}

Security Features

Path Restrictions

Limit file operations to specific directories only

Command Filtering

Block dangerous commands, whitelist allowed ones

Timeouts

Prevent runaway commands with configurable limits

File Size Limits

Prevent memory exhaustion from large files

Concurrent Limits

Control max parallel request processing

Result Truncation

Limit search results to prevent overflow

112
Tests Passing
5
Built-in Tools
2
Transport Types