Production-ready Model Context Protocol server with file, shell, and search tools
Read file contents with path restrictions and size limits
Write or append content to files with directory creation
Execute shell commands with timeout and security controls
Search for patterns in files using regex (grep-like)
Find files matching a glob pattern
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())
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "file_read",
"arguments": {
"path": "/etc/hostname"
}
}
}
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"content": [
{
"type": "text",
"text": "myhost\n"
}
]
}
}
Limit file operations to specific directories only
Block dangerous commands, whitelist allowed ones
Prevent runaway commands with configurable limits
Prevent memory exhaustion from large files
Control max parallel request processing
Limit search results to prevent overflow