Software Engineering

MCP for Developers: Connecting AI to Real Software Systems

The Model Context Protocol gives AI assistants a standard way to use your tools and data. Three months after its release, clients and servers are multiplying fast. This hands-on guide explains MCP's building blocks and walks through writing a small server that exposes an internal system to an AI assistant.

By EthicalHat Research · · 3 min read
Infographic: How an MCP server connects AI to your systems

Every team that has tried to connect an LLM to internal systems has written the same glue code: describe a function to the model, parse its tool call, call an API, feed the result back. Each AI application did it differently, so integrations could not be reused.

In November, Anthropic released the Model Context Protocol (MCP), an open standard for that glue. Since then, support has appeared in Claude Desktop, IDEs and coding tools such as Zed, Cursor, Continue and Sourcegraph Cody, and the community has published hundreds of servers for GitHub, databases, file systems, Slack, browsers and more.

This guide is for developers who want to build an MCP server for their own systems.

The building blocks

MCP uses JSON-RPC 2.0 between a client (inside an AI application, the host) and a server (your code). A server can offer three kinds of capability:

PrimitiveControlled byExample
ToolsThe model decides when to call themsearch_tickets(query), create_ticket(title, body)
ResourcesThe application or user chooses what to attachtickets://OPS-1234, a file, a database schema
PromptsThe user selects them, like templates"Summarise this incident for leadership"

Servers run in one of two ways:

  • Locally, over stdio: the host launches your server as a subprocess. This is ideal for developer tools and personal use.
  • Remotely, over HTTP (with server-sent events for streaming): useful for shared, centrally managed servers.
sequenceDiagram
  participant H as Host (LLM app)
  participant S as Your MCP server
  participant API as Ticketing API
  H->>S: initialize
  H->>S: tools/list
  S-->>H: search_tickets, get_ticket (+ JSON schemas)
  Note over H: Model decides to call a tool
  H->>S: tools/call search_tickets {"query":"login outage"}
  S->>API: GET /tickets?q=login outage
  API-->>S: results
  S-->>H: tool result (text / JSON)

Writing a server in Python

The official Python SDK includes a high-level FastMCP interface. A read-only server for an internal ticketing system:

python
# tickets_server.py
import os
import httpx
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("tickets")
API = os.environ["TICKETS_API_URL"]
HEADERS = {"Authorization": f"Bearer {os.environ['TICKETS_READ_TOKEN']}"}

@mcp.tool()
async def search_tickets(query: str, status: str = "open", limit: int = 10) -> list[dict]:
    """Search tickets by text. status is one of: open, closed, all. Returns id, title, status, assignee."""
    limit = max(1, min(limit, 25))
    async with httpx.AsyncClient(timeout=10) as client:
        r = await client.get(f"{API}/tickets", params={"q": query, "status": status, "limit": limit}, headers=HEADERS)
        r.raise_for_status()
        return [{k: t[k] for k in ("id", "title", "status", "assignee")} for t in r.json()["items"]]

@mcp.resource("tickets://{ticket_id}")
async def ticket(ticket_id: str) -> str:
    """Full text of one ticket, including comments."""
    async with httpx.AsyncClient(timeout=10) as client:
        r = await client.get(f"{API}/tickets/{ticket_id}", headers=HEADERS)
        r.raise_for_status()
        return r.json()["markdown"]

if __name__ == "__main__":
    mcp.run()   # stdio transport by default

The type hints and docstrings become the tool's JSON schema and description, which is what the model reads to decide when and how to call it.

To use it in Claude Desktop, register the server in the app's configuration file:

json
{
  "mcpServers": {
    "tickets": {
      "command": "uv",
      "args": ["run", "tickets_server.py"],
      "env": {
        "TICKETS_API_URL": "https://tickets.internal.example.com/api",
        "TICKETS_READ_TOKEN": "..."
      }
    }
  }
}

The TypeScript SDK follows the same model, and the MCP Inspector tool lets you test servers interactively without an LLM.

Designing good tools

Models are users of your API that read only the documentation. Design accordingly:

  • Narrow tools beat generic ones. search_tickets and get_ticket are easier for a model to use correctly, and safer, than run_sql(query).
  • Write precise descriptions. State what the tool does, what each parameter means, valid values and what it returns. Keep them factual; descriptions are instructions to the model.
  • Validate everything. Clamp limits, check enums and reject unexpected input. Never pass model-generated strings to a shell or build SQL from them.
  • Return concise, structured results. Large blobs waste context and confuse the model. Return the fields that matter, plus IDs for follow-up calls.
  • Make errors informative. "Unknown status 'opened'; expected one of open, closed, all" lets the model correct itself.
  • Prefer idempotent operations, because models sometimes retry.

Security from the start

MCP servers are privileged integrations driven by text, so:

  • Start read-only. Most value comes from letting the model find information.
  • Scope credentials to exactly what the server needs, ideally per user rather than a shared service account.
  • Require confirmation for writes. Hosts show tool calls to users, so keep write tools separate and clearly named so users know what they are approving.
  • Treat returned content as untrusted. Ticket text and documents may contain prompt-injection attempts. Keep that in mind when combining your server with others that can send data externally.
  • Do not put secrets in tool descriptions or results.

Where MCP fits

MCP does not replace your APIs. It is an adapter layer that makes them usable by AI applications in a standard way. Write a server once, and it works with every MCP-capable client your developers and colleagues use.

Our agentic AI security team builds production MCP servers for internal systems, with the scoping and review workflows enterprises need.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.