Enterprise Connectors
README.md
# mcp-enterprise-connectors
**An MCP server that lets AI agents work safely with a customer's CRM, ticketing and chat systems.** Under the tools sits the unglamorous integration work that decides whether an agent can be trusted in production: OAuth2, retries with backoff, circuit breaking, pagination, idempotent writes, signed webhooks, role-based access, human approval and audit logs.



> The CRM, ITSM and chat systems here are **local mocks** that follow the shapes of the Salesforce REST, ServiceNow Table and Slack Web APIs. The connectors switch to real endpoints through environment variables (`Backends.from_env`).
## The problem
Giving an agent a `create_ticket` tool is easy. Making it safe in a customer's environment is the actual job:
- Enterprise APIs **rate-limit, time out and return 5xx errors**. An agent that gives up on the first error is useless.
- The worst failure is the **lost response**: the server creates the record, then the response times out. Retry blindly and you create duplicates. Don't retry and you report a failure for something that actually happened.
- An agent shouldn't be able to post to a customer-facing channel, or act outside its user's role, without guardrails and a record of what it did.
## Results
`entconnect-bench` sends 500 incident creates through a deliberately faulty network: 10% HTTP 503, 5% HTTP 429, and 10% lost responses after the server committed the write. All backoff waits run in virtual time, so the benchmark takes seconds. Full output: [`reports/resilience.md`](reports/resilience.md).
| Client strategy | Success | Records written | Duplicates | Written but reported as failed | HTTP calls / create |
|---|---|---|---|---|---|
| No retries | 74.4% | 427 | 0 | 55 | 1.00 |
| Retries, blind POST | 100% | 569 | **69** | 0 | 1.34 |
| **Retries + correlation-id idempotency** | **100%** | **500** | **0** | **0** | 2.95 |
- **Pagination under rate limiting:** read 1,000 of 1,000 incidents, each exactly once, with 1 OAuth token fetch for the whole run.
- **ITSM → CRM sync:** re-run like a scheduler would, under the same faults (including two runs cut short by the circuit breaker). It converged to 187 cases for 187 incidents, with 0 duplicates.
- CI runs this benchmark on every push and **fails the build** if the idempotent path loses or duplicates a single record.
The trade-off is in the last column: idempotency costs an extra lookup per write (2.95 calls instead of 1.34). For ticket creation that is an easy decision. For a high-volume write path I'd ask the vendor for a native idempotency key or a bulk API.
## Architecture
```mermaid
flowchart LR
subgraph Client[MCP client: Claude, IDE or agent]
end
Client -->|stdio / MCP| S[MCP server<br/>5 typed tools]
S --> P{Policy<br/>RBAC · approvals}
P -->|denied| X[ToolError]
P -->|customer channel| AP[pending approval<br/>two-person rule]
P --> C[Connectors]
C --> R[ResilientClient<br/>OAuth2 · retries · Retry-After<br/>full-jitter backoff · circuit breaker]
R --> CRM[(CRM<br/>Salesforce-style)]
R --> ITSM[(ITSM<br/>ServiceNow-style)]
R --> CHAT[(Chat<br/>Slack-style)]
S --> AU[[Audit log<br/>JSONL, PII redacted]]
WH[Webhook receiver<br/>HMAC · replay window · dedupe] --> SY[ITSM → CRM sync<br/>idempotent upserts]
SY --> C
```
### MCP tools
| Tool | Annotation | What it does | Who can call it |
|---|---|---|---|
| `search_accounts` | read-only | Fuzzy account search (SOQL with escaping) | viewer, support_agent, manager |
| `get_account_360` | read-only | Account plus open incidents across systems | viewer, support_agent, manager |
| `create_incident` | idempotent | Opens an incident; the same `idempotency_key` never creates twice | support_agent, manager |
| `post_status_update` | write | Posts to chat; `#customer-*` channels wait for approval | support_agent, manager |
| `approve_action` | write | Approves someone else's pending action (never your own) | manager |
Tools return Pydantic models, so clients get an `outputSchema` and `structuredContent`, not just text.
## Security model
| Risk | Control | Where |
|---|---|---|
| Agent acts beyond its user's role | Role → tool allowlist, checked on every call | `policy.py` |
| Agent messages a customer by mistake | Approval queue with a two-person rule; each approval works once | `policy.py`, `server.py` |
| No record of what the agent did | Append-only audit log: user, role, tool, args hash, outcome, latency | `policy.py` |
| PII ends up in logs | Emails and phone numbers redacted before anything is written | `policy.redact` |
| Query injection through tool arguments | SOQL literal escaping, with a test that tries `' OR Name LIKE '%` | `connectors.soql_escape` |
| Forged or replayed webhooks | HMAC-SHA256 signatures, constant-time comparison, 5-minute timestamp window | `webhooks.py` |
| Duplicate webhook deliveries | Delivery-id dedupe (swap in Redis when running several replicas) | `webhooks.SeenIds` |
| Leaked or expired credentials | OAuth2 client credentials, cached with an expiry skew, refreshed once on 401 | `http.OAuthClientCredentials` |
## Quickstart
```bash
git clone https://github.com/rakeshsaineni/mcp-enterprise-connectors && cd mcp-enterprise-connectors
python -m venv .venv && source .venv/bin/activate
make install
make test # 20 tests: retries, breaker, pagination, idempotency, webhooks, MCP tools, RBAC
make bench # regenerates reports/resilience.md and enforces the resilience gate
```
**Use it from Claude Desktop** (runs against the mocks by default). Add this to `claude_desktop_config.json` ([example](examples/claude_desktop_config.json)):
```json
{ "mcpServers": { "enterprise-connectors": {
"command": "entconnect-mcp",
"env": { "ENTCONNECT_USER": "ana@yourco.com", "ENTCONNECT_ROLE": "support_agent" } } } }
```
Then ask: *"Find the Acme Logistics account, show its open incidents, and open a P2 for failing SSO logins."*
**Point it at real systems:** set `CRM_BASE_URL`, `CRM_CLIENT_ID`, `CRM_CLIENT_SECRET`, `ITSM_BASE_URL`, `ITSM_CLIENT_ID`, `ITSM_CLIENT_SECRET` and `CHAT_BOT_TOKEN`.
## Design decisions
- **Idempotency through `correlation_id`, not an HTTP header.** ServiceNow has no `Idempotency-Key` header, so the connector uses the integration pattern the platform supports: stamp the key on the record and look it up before every attempt. That also covers the case a header can't: a timeout *after* the commit.
- **Reads retry automatically; writes have to opt in.** `request(..., retry=False)` is the default for POSTs. Blind POST retries produced 69 duplicates in the benchmark above.
- **Full-jitter backoff that honors `Retry-After`.** Jitter keeps many agents from retrying in lockstep, and when the server says how long to wait, the client waits that long.
- **The circuit breaker fails fast for interactive tools, but background jobs wait it out.** An agent shouldn't hang for 30 seconds inside a chat turn, but the sync job can wait and resume. The benchmark shows both behaviors.
- **Virtual time for tests.** `sleep` and `clock` are injected, so the fault-injection suite exercises real backoff logic without real waiting.
## Limitations and next steps
- MCP over stdio trusts the local user's role from configuration. For a hosted server, use the streamable-HTTP transport with OAuth and take the role from the token.
- Dedupe state lives in memory. Use Redis or a database table when running more than one replica.
- Add contract tests against real Salesforce and ServiceNow developer sandboxes, plus Microsoft Teams alongside Slack.
- Add an LLM tool-selection eval: natural-language requests, expected tool and arguments, scored per model.
## Project layout
```
src/entconnect/ http (resilient client) · connectors · server (MCP) · policy · webhooks · sync · mocks · faults · bench
tests/ 20 tests, no network needed
reports/ latest resilience benchmark
examples/ Claude Desktop config
```
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues