Skip to main content
Glama
TushGoel

production-mcp-server

by TushGoel

production-mcp-server

CI Python License Tests

A production-grade MCP (Model Context Protocol) server demonstrating how to safely expose tools to AI agents in enterprise environments.

Most MCP examples show how to connect tools to agents. This repo shows how to do it safely at scale โ€” with permission enforcement, behavioral guardrails, blast-radius controls, and structured audit trails on every invocation.


The Problem โ†’ Solution โ†’ Impact

Problem

AI agents need tool access to be useful โ€” but unconstrained tool access causes production incidents. Teams either lock agents down (useless) or give full access (dangerous).

Solution

A governed MCP gateway layer that sits between every agent and every tool: permission-checked, blast-radius controlled, and fully audited on every call.

Impact

Agents operate safely in production with enterprise-grade authorization. Security teams can audit every action. Developers ship agent features without fear of side effects.


Related MCP server: nice

System Design

graph TD
    A[๐Ÿค– AI Agent<br/>Claude / Any LLM] -->|MCP Protocol| B

    subgraph MCP Gateway โ€” Governed Tool Access
        B[Request Received] --> C{Layer 1<br/>Permission Check}
        C -->|Missing permissions| D[โŒ Denied<br/>Audit logged]
        C -->|Permitted| E{Layer 2<br/>Blast-Radius Guard}
        E -->|HIGH risk, no confirmation| F[โŒ Blocked<br/>Audit logged]
        E -->|Confirmed or LOW/MED| G{Layer 3<br/>Input Validation}
        G -->|Path traversal / SQL injection| H[โŒ Blocked<br/>Audit logged]
        G -->|Clean inputs| I[โœ… Tool Handler Executes]
    end

    I --> J[(Tool Registry<br/>name ยท permissions ยท risk_level)]
    I --> K[๐Ÿ“‹ Audit Trail<br/>every call ยท permitted or denied]

    subgraph Tools
        I --> L[๐Ÿ“Š Read Metrics]
        I --> M[๐Ÿ” Query Database]
        I --> N[๐Ÿš€ Trigger Rollback<br/>HIGH RISK โ€” requires confirmed=True]
    end

Layer Breakdown

Layer

What It Does

Why It Matters

Tool Registry

Stores name, description, required permissions, and risk level for every tool

Single source of truth โ€” no tool runs without being registered

Permission Enforcement

Checks caller permissions against tool requirements before execution

Agents can only call tools they are explicitly authorized for

Blast-Radius Guard

Requires confirmed=True for HIGH risk operations

Agents cannot accidentally trigger destructive operations

Input Validation

Blocks path traversal, destructive SQL, and other attack patterns

Defense-in-depth โ€” validates before any handler runs

Audit Trail

Immutable append-only log of every invocation

Complete auditability for compliance and debugging

The Problem

When AI agents gain tool access, three failure modes emerge immediately:

  1. Unconstrained access โ€” agents call tools they shouldn't, causing unintended side effects

  2. No audit trail โ€” when something goes wrong, you can't reconstruct what the agent did

  3. Silent failures โ€” permission errors are swallowed, making debugging impossible

This server addresses all three.

Architecture

Agent (Claude / any LLM)
        โ”‚
        โ–ผ MCP Protocol
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        MCP Server           โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚    Guardrail Layer   โ”‚   โ”‚  โ† permission check โ†’ blast-radius guard โ†’ arg validation
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚             โ”‚               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚    Tool Registry     โ”‚   โ”‚  โ† name, description, required_permissions, risk_level
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚             โ”‚               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚    Tool Handlers     โ”‚   โ”‚  โ† plain Python functions, no security logic here
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚             โ”‚               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚     Audit Trail      โ”‚   โ”‚  โ† every invocation logged, permitted or denied
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Patterns

1. Governed Tool Access

Every tool is registered with explicit permission requirements:

registry.register(ToolDefinition(
    name="trigger_rollback",
    description="Initiate a deployment rollback.",
    handler=trigger_rollback,
    required_permissions={"deployments:write", "deployments:rollback"},
    risk_level=RiskLevel.HIGH,
    requires_confirmation=True,  # blast-radius guard
))

2. Permission Enforcement

The guardrail layer checks permissions before any handler runs:

# Agent tries to trigger rollback but lacks deployments:write
guardrails.invoke(
    tool_name="trigger_rollback",
    arguments={"deployment_id": "d-123", "reason": "high error rate"},
    caller_id="monitoring-agent",
    caller_permissions={"deployments:read"},  # missing write permission
)
# โ†’ PermissionDeniedError: Caller 'monitoring-agent' lacks permissions
#   {'deployments:write', 'deployments:rollback'} for tool 'trigger_rollback'

3. Blast-Radius Controls

HIGH risk tools require an explicit confirmation flag โ€” agents cannot accidentally trigger destructive operations:

# Without confirmation โ€” blocked
guardrails.invoke("trigger_rollback", {...}, confirmed=False)
# โ†’ GuardrailViolationError: HIGH risk tool requires confirmed=True

# With confirmation โ€” permitted
guardrails.invoke("trigger_rollback", {...}, confirmed=True)

4. Input Validation

Argument-level checks run before any tool handler:

# Path traversal โ€” blocked automatically
guardrails.invoke("read_file", {"path": "../../etc/passwd"}, ...)
# โ†’ GuardrailViolationError: Path traversal detected

# Destructive SQL โ€” blocked automatically
guardrails.invoke("query", {"query": "DROP TABLE users"}, ...)
# โ†’ GuardrailViolationError: Destructive SQL pattern detected

5. Structured Audit Trail

Every invocation โ€” permitted or denied โ€” is recorded:

# After some invocations
events = audit.get_events()
print(events[0].to_json())
# {
#   "tool_name": "read_deployment_status",
#   "caller_id": "oncall-agent-v1",
#   "arguments": {"deployment_id": "d-abc"},
#   "result": "{'status': 'healthy', ...}",
#   "permitted": true,
#   "timestamp": "2026-08-26T14:30:00+00:00",
#   "duration_ms": 12.4
# }

print(f"Denied requests: {audit.denied_count()}")

Project Structure

production-mcp-server/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ server.py          # MCP server entry point โ€” tool registration + FastMCP wiring
โ”‚   โ”œโ”€โ”€ registry.py        # Tool registry โ€” metadata, permissions, risk classification
โ”‚   โ”œโ”€โ”€ guardrails.py      # Guardrail layer โ€” 3-layer enforcement on every invocation
โ”‚   โ”œโ”€โ”€ audit.py           # Structured audit trail โ€” append-only event log
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ””โ”€โ”€ example_tools.py  # Example handlers โ€” swap with your real data sources
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_guardrails.py    # Permission enforcement, blast-radius, input validation
โ”‚   โ””โ”€โ”€ test_registry.py      # Tool registration and lookup
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ basic_usage.py        # Standalone usage without the MCP server
โ””โ”€โ”€ pyproject.toml

Installation

pip install -e ".[dev]"

Running the Server

python -m src.server

Connect any MCP-compatible client (Claude Desktop, Claude Code, etc.) to the server.

Running Tests

pytest tests/ -v

Extending

Adding a New Tool

  1. Write the handler function in src/tools/:

def read_config(config_key: str) -> str:
    return os.environ.get(config_key, "not_found")
  1. Register it with permissions and risk level:

registry.register(ToolDefinition(
    name="read_config",
    description="Read a configuration value by key.",
    handler=read_config,
    required_permissions={"config:read"},
    risk_level=RiskLevel.LOW,
))
  1. Expose via FastMCP:

@mcp.tool()
def config(config_key: str) -> str:
    return guardrails.invoke("read_config", {"config_key": config_key}, ...)

The guardrail and audit layers apply automatically โ€” no changes needed there.

Integrating Your Auth Layer

Replace the static CALLER_ID / CALLER_PERMISSIONS in server.py with your real identity provider:

# Example: derive permissions from an OAuth token in the MCP session context
def get_caller_context(session) -> tuple[str, set[str]]:
    token = session.headers.get("Authorization")
    claims = verify_jwt(token)
    return claims["sub"], set(claims["permissions"])

Why This Matters

AI agents operating with tool access in production need the same controls as any privileged service: least-privilege authorization, input validation, blast-radius limits, and a complete audit trail. This repo is a reference implementation of those patterns using the MCP protocol.

License

MIT


Part of the Agentic Infrastructure Stack

This repo is one piece of a production AI agent infrastructure portfolio:

Repo

What It Is

agentic-ops

Full system design: how these pieces fit together in a production deployment that eliminated 95% of manual oncall triage

production-mcp-server

โ† You are here: the MCP governance layer

agent-eval-framework

How agent quality is measured and regressions caught before they ship

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    A secure MCP gateway for enterprise AI tool execution, enabling governed invocation of business tools with authentication, RBAC, audit logging, PII redaction, and async processing.
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Provides a secure MCP gateway for AI agents to access APIs without exposing raw credentials, with scoped access, audit logging, and OAuth support.
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to securely call MCP tools with risk scoring, checkpoints, rollback, and approval workflows.
    134
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Governed MCP gateway that lets AI agents call tools with policy enforcement, prompt-injection screening, a kill-switch, and tamper-evident signed audit logs.
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • See, price, and control every tool call your AI agents make: policy checks, cost, and audit tools.

  • Security firewall for AI agents โ€” scans MCP calls for injection, secrets, and risks.

  • Runtime permission, approval, and audit layer for AI agent tool execution.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TushGoel/production-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server