cs.oldnet

All sheets / Interview Core

MCP Servers

Model Context Protocol: architecture and a minimal server.

What it is

An open protocol that lets AI apps (hosts) connect to external tools and data through a standard interface. Like "USB-C for AI integrations".

  • Host: the AI app (Claude, IDE, agent).
  • Client: connection manager inside the host, one per server.
  • Server: exposes capabilities over JSON-RPC 2.0.

Primitives

PrimitiveControlled byExample
Toolsmodel (with user approval)query_deployments, create_ticket
Resourcesappfile contents, DB rows, docs (URI-addressed)
Promptsuserreusable prompt templates / slash commands

Clients can also offer sampling (server asks the model) and elicitation (ask the user).

Transports

  • stdio: local subprocess, simplest.
  • Streamable HTTP: remote servers; supports streaming responses; OAuth 2.1 for auth.

Minimal server (TypeScript)

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';

const server = new McpServer({ name: 'deploys', version: '1.0.0' });

server.tool('recent_deploys', 'List recent deployments for a service',
  { service: z.string(), limit: z.number().default(5) },
  async ({ service, limit }) => ({
    content: [{ type: 'text', text: JSON.stringify(await getDeploys(service, limit)) }],
  }));

await server.connect(new StdioServerTransport());

Minimal server (Python)

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("deploys")

@mcp.tool()
def recent_deploys(service: str, limit: int = 5) -> list[dict]:
    """List recent deployments for a service."""
    return get_deploys(service, limit)

if __name__ == "__main__":
    mcp.run()

Design tips

  • Clear tool names + descriptions: the model picks tools from them.
  • Narrow, task-shaped tools beat one generic "run SQL" tool.
  • Return concise, structured output; paginate large results.
  • Validate inputs; enforce least-privilege credentials server-side.
  • Treat tool output as untrusted (prompt injection); require approval for writes.
  • Log calls for audit; add timeouts and rate limits.

Talking points

  • Problem: engineers spent time gathering deploy/incident context across tools.
  • Built MCP servers wrapping internal APIs (deploy history, logs, tickets) so the assistant could fetch context directly.
  • Result: faster deployment planning and prod-support triage.