mcp-tools-server
A portfolio MCP server demonstrating four tools (web search, database query, file reading, directory listing) with read-only SQL, filesystem sandbox, and both stdio and HTTP transports.
README
mcp-tools-server
MCP server on the official Python SDK (FastMCP): four tools, stdio and streamable HTTP transports from one codebase, read-only SQL, a filesystem sandbox, offline test suite.
What this demonstrates
- MCP servers with the official SDK: tools, resources, schemas, lifecycle, both transports.
- Tool design for LLMs: names, argument schemas and docstrings are the interface the model reasons over, so descriptions carry the DB schema, examples and constraints on purpose.
- Least-privilege security controls: SQL locked to read-only via a SQLite authorizer rather than regex filtering (plus multi-statement injection rejection), and a filesystem sandbox built on
resolve()+is_relative_to, with size caps and binary detection. - Structured JSON logging to stderr: every tool call, rejection and startup is one machine-parseable line, shapes and sizes only — never SQL text, rows or file contents.
- Layering: tool logic is pure typed functions in
app/tools/with zero MCP imports;app/server.pyregisters thin wrappers.
Architecture
flowchart LR
CD["Claude Desktop / Inspector"] -- stdio --> S["FastMCP<br/>portfolio-tools"]
ANY["any MCP client"] -- "streamable HTTP :8082/mcp" --> S
S --> SW["search_web"] --> IDX[("search_index.json")]
S --> QD["query_database"] --> DB[("demo.db<br/>SQLite, read-only")]
S --> FS["read_file / list_dir"] --> DOCS[("data/docs<br/>sandbox")]
Tools
| Tool | Arguments | Returns |
|---|---|---|
search_web |
query, max_results=5 |
ranked {title, url, snippet, score} from an offline curated index |
query_database |
sql, max_rows=50 |
{columns, rows, row_count, truncated} — single SELECT over the demo DB |
read_file |
path |
UTF-8 file content inside the sandbox, 100 KB cap |
list_dir |
path="." |
sorted entries with type and size |
All four tools declare TypedDict results, so responses ship as machine-readable structuredContent (with an output schema) alongside the usual JSON text.
The files in data/docs/ are also published as MCP resources — concrete docs://<file> entries plus a docs://{name} template; resource reads go through read_file's sandbox and size cap.
Demo DB (seeded on first query, ~25 rows of job-market data): companies(id, name, industry, city), vacancies(id, company_id, title, grade, salary_rub, stack), applications(id, vacancy_id, applied_at, status).
Quickstart
make install
make run-stdio # stdio (default), for clients that spawn the server
make run-http # streamable HTTP on :8082/mcp
# or: docker compose up --build
Debugging: npx @modelcontextprotocol/inspector python -m app.server.
Claude Desktop
Add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/, Windows: %APPDATA%\Claude\), restart, and the four tools appear in a new chat:
{
"mcpServers": {
"portfolio-tools": {
"command": "python",
"args": ["-m", "app.server", "--transport", "stdio"],
"env": {
"PYTHONPATH": "/absolute/path/to/mcp-tools-server",
"DATA_DIR": "/absolute/path/to/mcp-tools-server/data"
}
}
}
}
Claude Desktop sets no working directory for servers, so both paths must be absolute; if deps live in a venv, use its interpreter as command.
Configuration
Read from the process environment, no dotenv (see .env.example): DATA_DIR — sandbox root holding search_index.json, demo.db and docs/ (default ./data); MCP_HOST / MCP_PORT — HTTP transport bind (default 0.0.0.0:8082).
Notes
search_webis an offline stub: keyword ranking over 14 curated entries, so demos and tests are deterministic. A real search API drops in behind the same contract.query_databaselayers, least-privilege: read-only URI (mode=ro), asqlite3authorizer that allowlists SELECT/READ/FUNCTION and denies writes, DDL, PRAGMA, ATTACH and transactions,complete_statementrejection ofSELECT 1; DROP ...payloads, and row/cell/result-size caps.read_file/list_dirare sandboxed toDATA_DIR: absolute paths are accepted only when they resolve inside the root; any escape (.., outside path, or symlink target) is denied.- Structured JSON logging (
app/core/logging.py) writes one JSON object per line to stderr (stdout carries the stdio JSON-RPC frames), logging only call shapes/sizes/paths — never data. - All failures raise
ToolErrorwith a single-line message — clients see actionable errors, never tracebacks.
Testing
97 tests, offline: units hit the pure functions directly; integration runs a real MCP client against the server in memory via the SDK's create_connected_server_and_client_session — tools, structured output, resources and error mapping included.
make install-dev && make test; make lint for ruff, make typecheck for strict mypy. CI runs lint + strict mypy + tests, a security job (pip-audit + bandit), and CodeQL; Dependabot keeps deps current. The seeded data/ (demo.db, docs/, search_index.json) is resolved from the repo root by default; set DATA_DIR to relocate the sandbox.
MIT. Portfolio demo — siblings: llm-gateway · rag-pgvector · agent-orchestrator, which calls this server's search_web over HTTP.
Releases
Version history is in CHANGELOG.md.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。