How fareedkhan-dev/production-grade-mcp-agentic-system works
1. System shape
This repo is a Python 3.11+ production-oriented MCP server plus a separate four-agent “support copilot.” The server is the runtime boundary exposed to MCP clients; the agent system is an internal consumer that calls the server through an MCP client. The code is organized so transport/auth/governance are cross-cutting around tool execution, while observability and reliability wrap almost every path.
2. Primary request path
External MCP clients connect to src/atlas_mcp/server.py over stdio or Streamable HTTP. Requests pass through authentication middleware, tenant enforcement, authorization policy checks, rate limiting, caching, and reliability controls before reaching tool handlers. The server then dispatches to a registered tool and returns structured results or structured errors.
3. Identity, access, and tenant isolation
Authentication is handled in src/atlas_mcp/auth/oauth.py and auth/middleware.py, using OAuth 2.1 / JWT / JWKS validation. Authorization lives in auth/policy.py and is driven by YAML config in config/policy.yaml; outbound HTTP restrictions are also governed by config/http_allowlist.yaml. Tenant scoping is a first-class boundary in src/atlas_mcp/governance/tenant.py, so the same server instance can serve multiple tenants with different permissions and data access constraints.
4. Tool surface and execution model
Tools are registered in src/atlas_mcp/tools/registry.py and built on tools/base.py. The tool layer is split into three levels: atomic tools for single backends, composed tools for deterministic chains, and workflow tools for multi-step business procedures. The repository includes atomic integrations for Postgres, Elasticsearch, S3/MinIO, embeddings, HTTP client calls, and vector search; composed tools include semantic and hybrid search; workflow tools include customer-context assembly.
5. Data plane
The data layer is heterogeneous by design: PostgreSQL, Elasticsearch, S3-compatible storage, Redis, and a vector database are all represented in the tool modules. deploy/sql/init.sql suggests the database side includes schema setup plus row-level security policies for tenant isolation. The server does not hide these systems behind a single ORM abstraction; instead it exposes them as controlled tool capabilities.
6. Reliability controls
src/atlas_mcp/reliability/ contains per-tool circuit breaking, retry with jitter, and adaptive timeout budget allocation. This means backend failures are handled at the integration boundary rather than leaking directly into the MCP layer. tests/test_circuit_breaker.py indicates the breaker state machine is load-bearing and explicitly tested.
7. Caching and rate limiting
src/atlas_mcp/cache/manager.py implements a two-tier cache: an in-process L1 and Redis-backed L2, with stampede protection. src/atlas_mcp/ratelimit/limiter.py provides Redis token-bucket rate limiting, likely applied per tenant and per tool. These two subsystems sit in front of backend calls to protect expensive resources and enforce quotas.
8. Validation and error contract
src/atlas_mcp/validation/schemas.py defines the request/tool-call schemas, which is important because the system assumes adversarial or malformed agent input. Errors are standardized in src/atlas_mcp/errors/framework.py, with machine-readable metadata such as retryability and hints. The test suite focuses on these semantics, which suggests error shape is part of the external contract.
9. Observability
src/atlas_mcp/observability/ provides three distinct signals: OpenTelemetry tracing, Prometheus metrics, and structured audit logs. The runtime is wired for end-to-end traceability, and the README shows a single run ID tying MCP tool calls back to Jaeger. This makes observability a first-class architectural layer rather than an add-on.
10. Agentic copilot subsystem
src/atlas_mcp/agents/ is a separate orchestration layer that consumes the MCP server. planner.py creates a retrieval plan, retriever.py performs bounded tool calls through mcp_client.py, synthesizer.py drafts the answer with citations, and critic.py performs one revise/approve pass. orchestrator.py ties the four agents together, and memory.py adds short-term and long-term memory backed by Redis and vector search.
11. Governance and human control
src/atlas_mcp/governance/approval.py introduces an approval gate, which implies some tool or workflow actions can be paused for human review. This is a distinct control plane from authentication and authorization: auth decides who may act, governance decides whether an action should proceed given tenant or risk context. That separation matters when drawing the architecture because approvals are not just another auth check.
12. Deployment and local stack
docker-compose.yml brings up the app plus supporting infrastructure for local development, including observability endpoints and likely database/cache/search/vector dependencies. deploy/otel/config.yaml, deploy/prometheus/prometheus.yml, and deploy/sql/init.sql show that the repo includes sidecar/configuration artifacts for telemetry and database bootstrap. Dockerfile and docs/DEPLOYMENT.md indicate the project is meant to run both locally and in production with swapped managed services.
13. What to show in an architecture diagram
The clearest diagram would have three major planes: the MCP server control plane, the tool/data plane, and the agentic copilot consuming that server. Cross-cutting overlays should show auth/policy, tenant isolation, rate limiting, caching, reliability, and observability around every server request. External dependencies to place outside the boundary are OAuth/JWKS provider, Redis, PostgreSQL, Elasticsearch, S3/MinIO, vector DB, OpenTelemetry/Prometheus stack, and the Anthropic API used by the agents.
Main entry points: atomic Atomic Tools · middleware.py Auth MW · orchestrator.py Orchestrator · registry.py Tool Registry
Components 34
MCP Control Plane
Runtime boundary for MCP requests, cross-cutting governance, and request validation.
- MCP Server · Entry point for MCP clients over stdio or Streamable HTTP.
src/atlas_mcp/server.py - Auth MW · Authentication and request-time identity enforcement.
src/atlas_mcp/auth/middleware.py - OAuth · OAuth 2.1, JWT, and JWKS validation logic.
src/atlas_mcp/auth/oauth.py - Policy · Authorization rules driven by YAML policy config.
src/atlas_mcp/auth/policy.py - Tenant Gate · Tenant scoping and isolation boundary.
src/atlas_mcp/governance/tenant.py - Approval Gate · Human-review control for risky or blocked actions.
src/atlas_mcp/governance/approval.py - Schemas · Request and tool-call schema definitions.
src/atlas_mcp/validation/schemas.py - Error Contract · Standardized structured errors and retry metadata.
src/atlas_mcp/errors/framework.py - Cache · L1 in-process cache plus Redis-backed L2 with stampede protection.
src/atlas_mcp/cache/manager.py - Rate Limit · Redis token-bucket throttling per tenant or tool.
src/atlas_mcp/ratelimit/limiter.py - Retries · Retry logic with jitter around backend calls.
src/atlas_mcp/reliability/retry.py - Circuit Breaker · Per-tool circuit breaking state machine.
src/atlas_mcp/reliability/circuit_breaker.py - Budgeting · Adaptive timeout budget allocation.
src/atlas_mcp/reliability/atba.py - Observability · Tracing, metrics, and audit logging.
src/atlas_mcp/observability/tracing.py
Tool/Data Plane
Registered tools and the heterogeneous backend systems they mediate.
- Tool Registry · Registers and dispatches tool implementations.
src/atlas_mcp/tools/registry.py - Tool Base · Shared tool interface and execution model.
src/atlas_mcp/tools/base.py - Atomic Tools · Single-backend tools for core storage and retrieval systems.
src/atlas_mcp/tools/atomic - Composed Tools · Deterministic multi-step tool chains.
src/atlas_mcp/tools/composed - Workflow Tools · Business-process tools with multi-step orchestration.
src/atlas_mcp/tools/workflow - Postgres · Transactional data store and schema bootstrap.
src/atlas_mcp/tools/atomic/postgres.py - Search · Elasticsearch-backed retrieval and indexing.
src/atlas_mcp/tools/atomic/elasticsearch.py - Object Store · S3-compatible blob storage.
src/atlas_mcp/tools/atomic/s3_storage.py - Vector Search · Embedding and vector retrieval capability.
src/atlas_mcp/tools/atomic/vector_search.py
Copilot Agents
Internal multi-agent consumer that calls the MCP server through an MCP client.
- Planner · Creates retrieval plans for the copilot.
src/atlas_mcp/agents/planner.py - Retriever · Performs bounded tool calls through the MCP client.
src/atlas_mcp/agents/retriever.py - Synthesizer · Drafts answers with citations and evidence.
src/atlas_mcp/agents/synthesizer.py - Critic · Runs a revise-or-approve review pass.
src/atlas_mcp/agents/critic.py - Orchestrator · Ties the four-agent copilot together.
src/atlas_mcp/agents/orchestrator.py - MCP Client · Internal client used by agents to call the MCP server.
src/atlas_mcp/agents/mcp_client.py - Agent Memory · Short-term and long-term memory backed by Redis and vectors.
src/atlas_mcp/agents/memory.py
Ops & Config
Deployment artifacts and runtime policy/configuration inputs.
- Runtime Config · Shared application configuration loader.
src/atlas_mcp/config.py - Policy YAML · Authorization policy definition.
config/policy.yaml - HTTP Allowlist · Outbound HTTP destination restrictions.
config/http_allowlist.yaml - DB Init · Database schema and row-level security bootstrap.
deploy/sql/init.sql
Connections 39
- MCP Server → Auth MW: incoming request · All MCP traffic first passes through authentication middleware.
- Auth MW → OAuth: verify identity · Validate OAuth/JWT/JWKS credentials.
- Auth MW → Policy: authorize · Apply request and tool access policy.
- Auth MW → Tenant Gate: scope tenant · Bind request to tenant context.
- Auth MW → Schemas: validate schema · Reject malformed or adversarial payloads early.
- Tenant Gate → Approval Gate: risk gate · Tenant and risk context can trigger human approval.
- Auth MW → Rate Limit: throttle · Enforce tenant/tool quotas before execution.
- Auth MW → Cache: lookup · Consult cache for repeatable or expensive results.
- Auth MW → Observability: trace · Emit traces, metrics, and audit events around request handling.
- Auth MW → Tool Registry: dispatch · Route approved requests to registered tools.
- Tool Registry → Tool Base: implements · Tools conform to a shared execution abstraction.
- Tool Registry → Atomic Tools: register · Atomic backend integrations are exposed as tools.
- Tool Registry → Composed Tools: register · Composed search tools are exposed as tools.
- Tool Registry → Workflow Tools: register · Workflow tools are exposed as tools.
- Composed Tools → Atomic Tools: chain · Composed tools build on atomic integrations.
- Workflow Tools → Atomic Tools: orchestrate · Workflow tools use atomic capabilities as steps.
- Atomic Tools → Postgres: query · PostgreSQL-backed tools.
- Atomic Tools → Search: search · Elasticsearch-backed tools.
- Atomic Tools → Object Store: store · S3-compatible object operations.
- Atomic Tools → Vector Search: embed · Embedding and vector search operations.
- Atomic Tools → Cache: cache results · Backend calls may be cached.
- Atomic Tools → Retries: retry · Backend failures are retried with jitter.
- Atomic Tools → Circuit Breaker: protect · Circuit breaking wraps backend integrations.
- Atomic Tools → Budgeting: budget · Adaptive timeout budgets constrain calls.
- Atomic Tools → Observability: observe · Instrument tool execution.
- Orchestrator → Planner: plan · Orchestrator starts with retrieval planning.
- Orchestrator → Retriever: retrieve · Planner-guided bounded tool use.
- Orchestrator → Synthesizer: synthesize · Assemble cited answers.
- Orchestrator → Critic: review · One revise-or-approve pass.
- Orchestrator → MCP Client: call server · Agents consume the MCP server through an internal client.
- MCP Client → MCP Server: mcp request · Internal agent calls target the same MCP runtime boundary.
- Orchestrator → Agent Memory: remember · Persist and retrieve short- and long-term context.
- Agent Memory → Vector Search: vector store · Long-term memory uses vector search.
- Agent Memory → Cache: short term · Near-term state can use cache-backed storage.
- Policy → Policy YAML: loads · Policy rules are configured from YAML.
- Auth MW → HTTP Allowlist: egress policy · Outbound HTTP is constrained by an allowlist.
- Runtime Config → Policy YAML: reads · Application config loads policy settings.
- Runtime Config → HTTP Allowlist: reads · Application config loads HTTP restrictions.
- DB Init → Postgres: bootstrap · Database initialization and RLS setup target PostgreSQL.