readonly-mcp-server
A read-only MCP server with configurable transport (stdio or HTTP+SSE), API key authentication, and scope-based authorization for read and search operations on documents.
README
readonly-mcp-server
An MCP (Model Context Protocol) server with:
- Transport layer configuration —
stdiofor local process spawning, or HTTP+SSE for a networked/shared deployment. Selection follows "ifstdioelsehttp+sse": anyMCP_TRANSPORTvalue other than the literalstdiofalls back to HTTP+SSE. - Connection configuration (authentication) — bearer API keys on
HTTP+SSE (
Authorization: Bearer <key>, required on the SSE connection and every message POST), and a pre-shared key on stdio so the same auth model applies to local connections too. - Authorization limits (read / search only) — the server exposes
exactly two tool categories,
readandsearch. There are no write/update/delete tools at all, and each API key is independently granted a subset of{read, search}, enforced on every tool call.
Project layout
mcp-server-py/
├── config/
│ ├── api_keys.json # key -> client_id + scopes (read/search)
│ └── documents.json # sample read-only data backing the tools
├── src/
│ ├── config.py # env-driven transport/auth/data settings
│ ├── auth.py # API key store, TokenVerifier, scope checks
│ ├── data_store.py # read-only document backend
│ ├── tools.py # list_documents / read_document / search_documents
│ └── server.py # wires transport + auth + tools, entry point
├── requirements.txt
├── .env.example
└── test_stdio_client.py / test_http_client.py # example clients
Install
pip install -r requirements.txt
cp .env.example .env # then edit as needed
Configuration (environment variables)
| Variable | Purpose | Default |
|---|---|---|
MCP_TRANSPORT |
stdio or anything else → HTTP+SSE |
stdio |
MCP_HTTP_HOST / MCP_HTTP_PORT |
HTTP+SSE bind address | 0.0.0.0 / 8000 |
MCP_SSE_PATH / MCP_MESSAGE_PATH |
HTTP+SSE endpoint paths | /sse / /messages/ |
MCP_API_KEYS_FILE |
Path to key→scope config | config/api_keys.json |
MCP_STDIO_API_KEY |
Pre-shared key required for stdio clients | (unset — required) |
MCP_REQUIRE_AUTH |
Disable HTTP auth (local dev only) | true |
MCP_ISSUER_URL / MCP_RESOURCE_SERVER_URL |
Metadata URLs for the HTTP auth middleware | http://localhost:8000 |
MCP_DOCUMENTS_FILE |
Path to the document data file | config/documents.json |
Edit config/api_keys.json to add/remove keys. Each key lists scopes,
which may only contain read and/or search — anything else is rejected
at startup.
Run — stdio transport
MCP_TRANSPORT=stdio MCP_STDIO_API_KEY=demo-read-search-key-change-me \
python3 src/server.py
Point an MCP client (Claude Desktop, Claude Code, etc.) at this command,
passing MCP_STDIO_API_KEY in the client's configured environment for the
server process, e.g. in claude_desktop_config.json:
{
"mcpServers": {
"readonly-docs": {
"command": "python3",
"args": ["/absolute/path/to/mcp-server-py/src/server.py"],
"env": {
"MCP_TRANSPORT": "stdio",
"MCP_STDIO_API_KEY": "demo-read-search-key-change-me"
}
}
}
}
Run — HTTP+SSE transport
MCP_TRANSPORT=http MCP_HTTP_PORT=8000 python3 src/server.py
Clients connect to GET http://host:8000/sse and POST /messages/, both
requiring Authorization: Bearer <api-key>. See test_http_client.py for
a minimal client example using the official mcp Python SDK.
Tools exposed
| Tool | Required scope | Description |
|---|---|---|
list_documents |
read |
List all document ids + titles |
read_document |
read |
Fetch full content of one document by id |
search_documents |
search |
Keyword search returning matches + snippets |
A key missing the required scope gets a clear isError=true tool result
(Access denied: this operation requires the 'X' scope...) rather than a
crash or silent failure.
Design notes / how the auth is wired
- HTTP+SSE: uses the MCP Python SDK's built-in
TokenVerifier+AuthSettingssupport.ApiKeyTokenVerifier(inauth.py) adapts our flat API-key file to that protocol; the SDK then wraps both the/sseand/messagesendpoints withAuthenticationMiddleware+RequireAuthMiddlewareautomatically, and binds each SSE session to the credential that opened it (a POST with a different/no credential for an existing session is rejected). - stdio: authenticated once at process startup via
MCP_STDIO_API_KEY; scopes are held for the lifetime of the process. All logging goes to stderr — the stdio transport reserves stdout for JSON-RPC protocol frames. - Scope enforcement:
auth.require_scope()is called at the top of every tool function and reads the caller's granted scopes viaget_access_token()(HTTP) or the stdio session's validated key (stdio), raising if the scope isn't present.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。