mcpserve-py
Exposes SQLite database query tools and markdown document resources over JSON-RPC 2.0 stdio transport, enabling AI assistants to read and search documents and execute read-only SQL queries.
README
mcpserve-py
A Model Context Protocol (MCP) server built in Python — exposes database query tools and document resources over JSON-RPC 2.0 stdio transport, enabling AI assistants to interact with SQLite databases and markdown documents.
What is MCP?
The Model Context Protocol is an open standard for connecting AI assistants to external tools and data sources. MCP servers expose tools (functions the AI can call) and resources (data the AI can read) over a JSON-RPC 2.0 transport.
This server implements the MCP protocol from scratch using raw JSON-RPC 2.0 over stdio — no SDK dependency required.
Features
- 🔧 8 tools — database queries, document CRUD, search, date/time
- 📄 Resource providers — documents and database schemas as readable resources
- 🛡️ SQL injection protection — only SELECT queries allowed, with regex validation
- 📝 YAML frontmatter — documents stored as markdown with structured metadata
- 🔌 Stdio transport — line-delimited JSON-RPC 2.0 over stdin/stdout
- ⚡ Zero SDK dependency — hand-rolled MCP protocol implementation
- ✅ Well-tested — 113 tests covering protocol, tools, resources, and integration
Quick Start
# Clone and install
git clone https://github.com/devaloi/mcpserve-py.git
cd mcpserve-py
pip install -e ".[dev]"
# Run the server
python -m mcpserve_py
# Run tests
python -m pytest -v
Environment Variables
| Variable | Default | Description |
|---|---|---|
MCPSERVE_DATA_DIR |
data |
Directory for documents and data |
MCPSERVE_DB_PATH |
data/mcpserve.db |
Path to SQLite database |
MCPSERVE_LOG_LEVEL |
INFO |
Log level (DEBUG, INFO, WARNING, ERROR) |
Claude Desktop Configuration
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"mcpserve-py": {
"command": "python",
"args": ["-m", "mcpserve_py"],
"env": {
"MCPSERVE_DATA_DIR": "./data",
"MCPSERVE_DB_PATH": "./data/mcpserve.db"
}
}
}
}
Tools
| Tool | Description | Parameters |
|---|---|---|
query_database |
Execute read-only SQL query | sql: str, params?: list |
list_tables |
List all tables in database | — |
describe_table |
Get table schema | table: str |
create_document |
Create a markdown document | title: str, content: str, tags?: list[str] |
read_document |
Read document by title | title: str |
list_documents |
List all documents | tag?: str |
search_documents |
Full-text search across documents | query: str |
get_datetime |
Current date/time | timezone?: str |
Resources
| URI Pattern | Description | MIME Type |
|---|---|---|
docs:///{title} |
Document content | text/markdown |
db:///schema |
Full database schema | text/plain |
db:///tables/{name} |
Single table schema | text/plain |
Architecture
src/mcpserve_py/
├── __main__.py # Entry point: python -m mcpserve_py
├── server.py # MCP server: receive → dispatch → respond
├── protocol.py # JSON-RPC 2.0 types and encoding
├── transport.py # Stdio transport (line-delimited JSON)
├── config.py # Pydantic settings
├── tools/
│ ├── registry.py # Tool registry
│ ├── database.py # SQLite tools (query, list_tables, describe)
│ ├── documents.py # Document tools (CRUD + search)
│ └── system.py # System tools (get_datetime)
└── resources/
├── provider.py # Resource provider interface + registry
├── documents.py # Document resource provider
└── database.py # Database schema resource provider
Design Decisions
- No MCP SDK — The protocol is implemented directly using JSON-RPC 2.0 dataclasses. This demonstrates deep understanding of the protocol rather than SDK usage.
- Synchronous — Stdio is inherently sequential; async adds complexity without benefit here.
- Pydantic Settings — Configuration via environment variables with type validation and
.envfile support. - Tool registry pattern — Tools register themselves with a central registry, keeping the server dispatch clean.
- Read-only SQL — Mutations are rejected via regex before reaching SQLite, preventing data corruption by AI assistants.
- YAML frontmatter — Documents use the same format as static site generators (Jekyll, Hugo), making them human-readable and tool-friendly.
Development
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
make test
# Lint
make lint
# Type check
make typecheck
# Format
make format
# All checks
make all
License
MIT
Contributing
See CONTRIBUTING.md. PRs welcome — run make all before submitting.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。