43.1 Pattern 1 — Database Integration Server
@server.tool()
async def query_database(query: str, database: str = "analytics") -> str:
"""Execute a read-only SQL query."""
if not query.strip().upper().startswith("SELECT"):
raise ValueError("Only SELECT queries allowed")
result = await db.execute(query)
return format_as_table(result)
@server.resource("schema://tables")
async def list_tables() -> str:
"""List all available tables and their schemas."""
schemas = await db.get_schemas()
return json.dumps(schemas)
43.2 Pattern 2 — API Integration Server
@server.tool()
async def search_contacts(name: str, company: str | None = None) -> str:
"""Search CRM contacts by name and optional company."""
params = {"name": name}
if company:
params["company"] = company
return await crm_client.search_contacts(**params)
@server.tool()
async def create_opportunity(
account_id: str, name: str, amount: float, stage: str
) -> str:
"""Create a new sales opportunity in the CRM."""
return await crm_client.create_opportunity(
account_id=account_id, name=name, amount=amount, stage=stage
)
43.3 Pattern 3 — File System Server
@server.resource("file://{path}")
async def read_file(path: str) -> str:
"""Read a file from the allowed directory."""
safe_path = validate_path(path, allowed_root="/data")
return Path(safe_path).read_text()
@server.tool()
async def search_files(query: str, file_type: str = "*") -> list:
"""Search files by content using full-text search."""
results = await file_index.search(query, file_type=file_type)
return [{"path": r.path, "snippet": r.snippet} for r in results]
43.4 Pattern 4 — Governed Enterprise SaaS Connectors (Slack, Jira, Salesforce, ERP/CRM)
Enterprise connectors are the highest-blast-radius MCP servers in practice — they hold real business-system credentials (a Slack bot token, a Jira service account, a Salesforce API user) and every tool call is a real side effect in a system other teams depend on. The pattern that keeps this safe layers four things on top of the basic API-integration pattern from 62.2:
# One MCP server per SaaS system, never one server proxying many systems —
# this keeps credential scope, rate limits, and audit logs cleanly isolated.
@server.tool()
async def post_slack_message(channel: str, text: str) -> str:
"""Post a message to a Slack channel. Requires explicit user approval."""
if channel not in ALLOWED_CHANNELS: # allow-list, not deny-list
raise PermissionError(f"Channel {channel} not in governed allow-list")
await audit_log.record(action="slack.post", channel=channel, actor=current_user())
return await slack_client.chat_postMessage(channel=channel, text=text)
@server.tool()
async def create_jira_ticket(project: str, summary: str, issue_type: str = "Task") -> str:
"""Create a Jira ticket. Write action — requires per-call approval."""
if project not in GOVERNED_PROJECTS:
raise PermissionError(f"Project {project} not governed for AI ticket creation")
ticket = await jira_client.create_issue(project=project, summary=summary, issuetype=issue_type)
await audit_log.record(action="jira.create", project=project, ticket_id=ticket.key)
return ticket.key
@server.tool()
async def update_salesforce_opportunity(opp_id: str, stage: str) -> str:
"""Update a Salesforce opportunity stage. High-risk write — always HITL-gated."""
require_human_approval(action="update_opportunity", opp_id=opp_id, new_stage=stage)
await audit_log.record(action="sfdc.update", opp_id=opp_id, new_stage=stage)
return await sfdc_client.update_opportunity(opp_id, stage=stage)
Governance layers every enterprise connector needs:
- Scoped, per-connector credentials — a Slack connector’s bot token should only have the scopes for the specific channels/actions it needs, never a workspace-admin token; same principle for Jira/Salesforce API users. This bounds the blast radius of a compromised or misbehaving agent to that one system.
- Allow-lists over deny-lists for destinations (channels, projects, object types) — an agent should only be able to post to/modify resources explicitly governed for AI access, not “anything except this excluded list.”
- Action-tier-based approval (ties to Section 31’s action classification): reads and low-risk writes (posting a status update to a pre-approved channel) can be autonomous; anything touching financial data, customer-facing records, or ticket/pipeline state that other humans act on (Salesforce opportunity stage, a customer-facing Jira ticket) is HITL-gated by default.
- Full audit trail — every connector call logged with actor (which agent/session/user triggered it), action, target, and outcome, independent of the underlying SaaS system’s own audit log, so an incident review doesn’t depend on the third-party system’s logging retention policy.
- ERP/CRM-specific caution: these systems are frequently the system of record for revenue, inventory, or compliance data — an incorrect AI-driven update doesn’t just look bad, it can cascade into financial reporting or downstream automation (e.g., a wrong Salesforce stage change firing a customer-facing automated email). Treat any ERP/CRM write connector as regulated-system-adjacent even if the data itself isn’t classified as sensitive.
Section 43 — Interview Q&A
Q1: How do you design an MCP server that wraps a database safely, given that the AI will decide when to call it?
Restrict the tool surface to the minimum needed — typically a single query tool that only accepts SELECT statements (reject anything else at the server, not just via prompt instruction), expose a separate read-only schema resource so the model can discover available tables/columns without querying blindly, enforce a query timeout and row-limit server-side, and never let the tool’s connection have write/DDL privileges at the database-credential level — defense in depth, not just prompt-level restriction.
Q2: What’s different about designing a file-system MCP server vs. a database or API server?
Path traversal is the primary new risk — every path must be validated and normalized against an explicit allowed root before any file operation, rejecting ../ traversal attempts and symlinks that could escape the sandbox. Unlike a database server (where the query language itself can be restricted, e.g., SELECT-only) or an API server (where the wrapped API defines its own permission boundary), a file-system server must implement its own access-control boundary from scratch, since the underlying filesystem has no inherent concept of “allowed directory.”
Q3: How do you govern a set of enterprise connectors (Slack, Jira, Salesforce, ERP/CRM) so that giving an agent broad enterprise reach doesn’t become a broad enterprise risk? One server per system with scoped, least-privilege credentials rather than one server proxying many systems — this bounds blast radius and keeps rate limits/audit logs cleanly separated per system. Every write-capable tool is allow-listed at the destination level (specific channels, specific Jira projects, specific Salesforce object types) rather than open by default. Actions are tiered the same way as Section 31’s general action classification — low-risk reads and pre-approved status posts run autonomously, anything touching a system-of-record field that other humans or downstream automations act on (a Salesforce stage, a customer-facing ticket) is human-approval-gated regardless of how confident the agent is. And every connector call gets its own audit entry independent of the underlying SaaS system’s logs, because a security or compliance review needs a single place to reconstruct “what did the AI actually do across all these systems,” not five different vendor audit logs to cross-reference.