Skip to main content
Glama
mcp-crm-server

mcp-crm-server

README.md
# MCP server for a mock CRM (HubSpot-style), with permissions, audit log and tests

Python, MCP Python SDK 2.x, SQLite. The CRM data is synthetic; no HubSpot account or real customer data is used.

## What it does
- Exposes a CRM (20 contacts, 40 deals, call notes) to AI agents through 5 MCP tools: search_deals, get_contact, pipeline_summary (read) and update_deal_stage, log_call_note (write).
- Typed tool inputs (stage is an enum, so an invalid stage is rejected by the schema before the code runs), parameterised SQL, range checks.
- API key at start-up maps to a role: write tools refuse to run with a read key.
- Business rules: only allowed stage transitions (won and lost are final), a reason of at least 5 characters for every stage change.
- Call notes are length-limited and emails and phone numbers are redacted before saving.
- Every write is stored in an audit_log table in the same transaction as the change.
- Deliberate errors are returned to the agent with a clear message (MCP ToolError), so a model can correct its next call; unexpected crashes stay on the server.

## Run
pip install -r requirements.txt
python test_and_eval.py                              (tests, about 2 seconds)
CRM_API_KEY=demo-write-key python crm_mcp_server.py  (stdio server for Claude Desktop or Claude Code)

## Results (results/test_output.txt)
- 16/16 checks pass through the real MCP protocol: 15 calls from an in-memory MCP client plus 1 end-to-end call to the server running as a separate stdio process.
- Covered: tool listing, search filters, schema rejection of an invalid stage, limit check, SQL-injection text treated as data, unknown ids, write refused with a read key, allowed and forbidden stage transitions, short reason rejected, email and phone redaction, empty note rejected, audit log written for both writes.
- These are tests of the server's behaviour. They do not measure how well an LLM agent chooses tools.

## Limits
- Stdio transport with a key per server process; a hosted version would use OAuth or per-request tokens over HTTP.
- Demo keys are in the code; real keys belong in a secret manager.
- SQLite and a mock schema stand in for the HubSpot API; a real connector would call HubSpot's REST API with rate limiting and retries.