AI Engineering Projects › MCP · Lakehouse Ops Server

🔌 MCP · Lakehouse Ops Server — every aspect of MCP

One tiny FastMCP server that exposes all of MCP · your D4 exam rehearsal · mock-first, no Docker

THE PROJECT One small server, every MCP concept

Build one local MCP server (FastMCP) that deliberately exposes every MCP feature — the three primitives (tools · resources · prompts), both transports (stdio & streamable HTTP), and the advanced client-facing features (sampling · roots · elicitation) — then connect it to a host (Claude Code / Claude Desktop). It's themed on Ops, so it also becomes the real MCP layer for G4 and G5. All data is mock; it's a few dozen lines.

🎯 MCP is ~18% of the exam (D4). This one server touches every question they can ask: what are the primitives & who controls each, stdio vs HTTP, discovery/handshake, sampling/elicitation/roots, MCP security, and custom-tools-vs-MCP.

WHICH PORTFOLIO PROJECTS USE MCP

MCP fits wherever an agent must reach external systems through standardized, reusable tools/resources. Best-fit first:

ProjectMCP fitWhat becomes MCP
G4 · RCA Copilot★★★ (the showcase)A Databricks MCP server (read-only tools) + a ServiceNow MCP server (draft ticket) + runbooks as resources + /rca as a prompt — uses all three primitives across two servers
G5 · Runbook Agent★★★Runbooks & past incidents exposed as resources; search as a tool
P4 · Support Agent★★★CRM / ticketing / knowledge-base via MCP servers (tools)
P0 · Text-to-SQL★★A database MCP server: run_sql tool + schema as a resource
G6/G8/G9/G10★★Cost / DQ / Git-CI / Unity-Catalog MCP servers (read-only tools + resources)
G1 · Health Sentinel★ (optional)Could consume a Databricks read-only MCP server for signals — but G1 is a single call, so MCP is optional
Second-Brain★Memory exposed as an MCP server (tools to write, resources to read)
Best teacher = G4 (multiple servers, all primitives, read-only + a human-gated draft). This page builds the server side of exactly that, as a standalone toy.

MENTAL MODEL Host · Client · Server

MCP is an open protocol (JSON-RPC 2.0) with a strict topology: a host (the LLM app) runs one client per server. Servers expose capabilities; the host decides what reaches the model.

flowchart LR subgraph HOST["HOST — Claude Code / Desktop"] LLM["Claude"] C1["MCP client A"] C2["MCP client B"] end C1 <-->|"JSON-RPC"| S1["MCP server: lakehouse-ops
tools · resources · prompts"] C2 <-->|"JSON-RPC"| S2["MCP server: servicenow"] LLM -.->|"reverse: sampling / elicitation"| C1 classDef s fill:#f3f0ff,stroke:#764ba2,color:#4a3b7a; class S1,S2 s;

On connect there's an initialization handshake with capability negotiation, then the client discovers what the server offers (tools/list, resources/list, prompts/list) — dynamically, so a server can add a tool and emit a list_changed notification without a client redeploy.

THE THREE PRIMITIVES …and who controls each

The single most-tested MCP fact: each primitive is controlled by a different party.

PrimitiveControlled byWhat it isIn this Ops server
ToolsMODELActions the model chooses to call (like tool use). Can have side effects.get_job_runs(), get_run_logs() (read-only)
ResourcesAPP / HOSTRead-only context data addressed by URI; the host decides when to load it.runbook://schema-drift, incident://INC-1042
PromptsUSERReusable templates / workflows, usually surfaced as slash commands./rca <run_id>, /weekly-brief
Exam trap: "resources are things the model calls." No — tools are model-controlled; resources are application-controlled context; prompts are user-invoked. Mixing up who controls what is a classic D4 miss.

TRANSPORTS Local (stdio) vs remote (streamable HTTP)

stdioStreamable HTTP
Where the server runsLocal subprocess of the hostA remote service (its own URL)
TransportJSON-RPC over stdin/stdoutJSON-RPC over HTTP (SSE for streaming)
AuthOS process / local trustOAuth 2.1 (authorization)
Use whenPersonal/local tools, filesystem, devShared/hosted servers, multi-user, SaaS
Streamable HTTP is the current remote transport (it superseded the older HTTP+SSE transport). Same protocol & primitives on either — only the pipe changes.

ADVANCED — the reverse direction sampling · roots · elicitation

Beyond exposing capabilities, a server can call back into the client. These are the features people forget:

flowchart LR S["MCP server"] -->|"tools/resources/prompts"| C["Client / Host"] S -->|"sampling: ask the LLM"| C S -->|"elicitation: ask the user"| C C -->|"roots: here are your boundaries"| S classDef s fill:#f3f0ff,stroke:#764ba2,color:#4a3b7a; class S s;

SECURITY the part the exam loves

BUILD IT the whole server (FastMCP, mock-first)

🧩 SDK — the official mcp Python package (FastMCP).
🗄️ Data — mock JSON (job runs, runbooks, incidents).
🖥️ Host — Claude Code or Claude Desktop via a tiny .mcp.json.
🚫 No Docker — a local stdio subprocess.
# pip install mcp   ·   run: python server.py   ·   host connects via .mcp.json
from mcp.server.fastmcp import FastMCP, Context
import json

mcp = FastMCP("lakehouse-ops")

# 1) TOOL — MODEL-controlled action. The DESCRIPTION drives selection (D4). Read-only.
@mcp.tool()
def get_job_runs(window_min: int = 60) -> list[dict]:
    """Recent Databricks job runs (read-only). Use to check pipeline health."""
    return json.load(open("mock/runs.json"))

# 2) RESOURCE — APP/HOST-controlled context, addressed by URI. Read-only.
@mcp.resource("runbook://{name}")
def runbook(name: str) -> str:
    """A runbook the host can pull into context on demand."""
    return open(f"mock/runbooks/{name}.md").read()

# 3) PROMPT — USER-controlled template, surfaced as a slash command.
@mcp.prompt()
def rca(run_id: str) -> str:
    """/rca — investigate a failed run using the tools and runbook resources."""
    return f"Investigate run {run_id}. Call get_job_runs, read the relevant runbook, cite evidence."

# 4) SAMPLING — the server asks the CLIENT'S LLM (no server API key needed).
@mcp.tool()
async def summarize_health(ctx: Context) -> str:
    """One-line health summary — generated by the host's model via sampling."""
    runs = json.load(open("mock/runs.json"))
    reply = await ctx.sample(f"Summarize pipeline health in one line:\n{runs}")
    return reply.text

# 5) ELICITATION — the server asks the USER for structured input mid-call.
@mcp.tool()
async def health_check(ctx: Context) -> str:
    """Ask which environment, then report (human stays in the loop)."""
    answer = await ctx.elicit("Which environment?", schema={"type":"string", "enum":["dev","prod"]})
    return f"Checked {answer} — all green (mock)."

if __name__ == "__main__":
    mcp.run()                                # stdio (local). Remote: mcp.run(transport="streamable-http")

Connecting the host (.mcp.json)

# .mcp.json (Claude Code) — how a host discovers & launches the server
{
  "mcpServers": {
    "lakehouse-ops": { "command": "python", "args": ["server.py"] }
    // remote instead:  "lakehouse-ops": { "url": "https://ops.internal/mcp" }
  }
}
🟣 Cert tie-in: the model consumes an MCP tool exactly like a native tool — a typed tool_use block, a tool_result back. MCP is the standard packaging & discovery layer around tools/resources/prompts, so many hosts can reuse one server. Everything you learned in the Claude API tool loop (D4) still applies.

CUSTOM TOOLS vs MCP when to use which

🔌 Reach for MCP when…

  • The integration should be reusable across hosts (Claude Code, Desktop, your app)
  • You want standard discovery, resources & prompts, not just functions
  • It's a shared/hosted capability (a team Databricks or ServiceNow server)
  • A vendor already ships an MCP server you can plug in

🛠️ Just define API tools when…

  • The tools are internal to one app and won't be reused elsewhere
  • You want the simplest path — the Messages API tool loop / Tool Runner
  • No need for resources/prompts or cross-host sharing
Both end up as tool_use/tool_result to the model. MCP adds a protocol & ecosystem; custom tools add nothing to learn. The exam wants you to justify the choice.

FAILURE POINTS

Injection via an MCP tool/resource → server output says "ignore instructions…". Mitigation: treat as untrusted data, least-privilege tools, human approval on actions.
Malicious / spoofed server → you connect to an untrusted server. Mitigation: allow-list servers; review before adding to .mcp.json.
Token pass-through → the server forwards your token downstream (confused deputy). Mitigation: scope credentials per server; never blind-forward tokens.
Tool-name collisions across two servers → misrouting. Mitigation: distinct, descriptive names; namespacing.
Over-broad tool scope → a write tool where read-only would do. Mitigation: read-only by default; separate, gated write tools.

CONCEPTS → CCA MAP

You practised…CCA domain
MCP primitives (tools/resources/prompts) & who controls eachD4 · Tool Design & MCP
Transports (stdio / streamable HTTP), discovery, capability negotiationD4
Sampling, elicitation, rootsD4
MCP security (untrusted output, OAuth, approval, token pass-through)D4 · D5 (guardrails)
MCP vs custom tools; tool descriptions drive selectionD4 · D2 (Claude Code config)

LEVEL IT UP