Back to catalog / MCP servers
Build a read-only MCP tool server for agent queries
Expose a narrowly scoped query tool so MCP clients can read application data but cannot change it.
Goal
Provide discoverable, constrained MCP queries with no write side effects.
Steps
- Choose one read-only business query and grant minimum read privileges at the data layer. [mcp-tools] [mcp-errors]
- Register with
@mcp.tool()and type hints; constrain pagination withAnnotated[int, Field(ge=1, le=50)]. [mcp-tools] [mcp-errors] - If you set
read_only_hint=True, treat it only as a client hint; enforce read-only access in database/service permissions. [mcp-tools] [mcp-errors] - Convert exceptions to controlled MCP errors; never return stack traces, connection strings, or secrets. [mcp-tools] [mcp-errors]
- Test valid, unauthorized, invalid, and oversized-page requests; verify the data layer rejects writes. [mcp-tools] [mcp-errors]
How to verify
Tests should prove the tool reads only authorized scope and errors reveal no internal details.
Troubleshooting
If a test can mutate data, enforce read-only permissions in the data layer rather than relying on the tool description.
Permissions
Prerequisites
- Python 3.10+ and the MCP Python SDK compatible with the pinned revision
Permissions
- Use a local or isolated test environment; use least privilege and approval for external data or side effects
Limitations
SDK behavior varies by version. Check the pinned revision against your agent or client, then review data retention, authorization, and side effects before production use.
Pinned upstream source
- Repository
- modelcontextprotocol/python-sdk
- File path
- docs/servers/tools.md
- Pinned commit
754254c08fe1c3eda18b69da3d336106fe8d72d6- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT