Task 2.2

MCP Server Implementation

The Model Context Protocol (MCP) is an open standard for connecting AI models to external data and tools. An MCP server exposes tools, resources, and prompts through a standardized protocol.

MCP Architecture

MCP follows a client-server architecture. The server exposes capabilities (tools, resources, prompts) and the client connects to consume them. Communication happens over transports: stdio (for local processes) or SSE/streamable HTTP (for remote servers).

A key design decision is the transport. Stdio is simplest — the MCP client launches the server as a subprocess and communicates via stdin/stdout. SSE is for remote servers accessible over HTTP. Choose stdio for local development tools and SSE for shared services.

Building an MCP Server

An MCP server is built using the MCP SDK (available in Python and TypeScript). You create a server instance, register tools with schemas and handlers, and start the server on a transport.

Each tool registration includes: a name, a description, an input schema (JSON Schema), and a handler function that receives the parameters and returns results. The pattern is similar to defining API endpoints in a web framework.

Resources and Prompts

Beyond tools, MCP servers can expose resources (data sources the model can read) and prompts (reusable prompt templates). Resources are identified by URIs and can be static or dynamic. Prompts are templates with parameters that clients can fill in.

Resources are useful for giving the model access to documentation, configuration files, or live data feeds. Prompts are useful for standardizing common interactions across different clients.

Key Concept

MCP Servers Are Reusable Integrations

The power of MCP is reusability. An MCP server you build once can be used by Claude Code, the Claude desktop app, any IDE with MCP support, and your own custom applications. This contrasts with building tool integrations directly into a single application. MCP separates the integration (server) from the consumption (client).

Exam Traps

EXAM TRAP

Confusing MCP tools with Claude API tools

MCP tools are exposed by MCP servers and consumed by MCP clients. Claude API tools are defined directly in the API call. An MCP client translates MCP tools into Claude API tool format before sending to the API.

EXAM TRAP

Choosing the wrong transport

Stdio is for local processes; SSE/HTTP is for remote servers. The exam may present scenarios where the transport choice matters for security, performance, or deployment.

EXAM TRAP

Ignoring MCP resources

MCP is not just about tools. Resources provide read access to data, and prompts provide reusable templates. The exam tests understanding of all three MCP primitives.

Check Your Understanding

You want to build an MCP server that gives Claude access to your company's internal documentation. The server will be used by multiple developers on their laptops via Claude Code. Which MCP primitives and transport should you use?

Build Exercise

Build an MCP Server

Intermediate45 minutes

What you'll learn

  • Create an MCP server with the TypeScript SDK
  • Register tools with schemas and handlers
  • Add resources for data access
  • Test with an MCP client
  1. Install the MCP TypeScript SDK and create a new server instance. Register a simple tool (e.g., get_time) that returns the current time.

    WHY: Starting with a minimal server helps you understand the basic MCP server lifecycle.

    YOU SHOULD SEE: A running MCP server that responds to tool calls.

  2. Add a more complex tool with multiple parameters and input validation. For example, a search_notes tool that accepts a query string and a limit parameter.

    WHY: Real tools need parameter validation and structured schemas.

    YOU SHOULD SEE: The tool validates inputs and returns structured results.

  3. Add a resource that exposes a static data file (e.g., a configuration or documentation file).

    WHY: Resources demonstrate MCP's data access capabilities beyond tool calls.

    YOU SHOULD SEE: The resource is listed when the client queries available resources.

  4. Test your server with Claude Code by adding it to the MCP configuration. Verify tools and resources are available.

    WHY: End-to-end testing with a real client validates your server implementation.

    YOU SHOULD SEE: Claude Code can discover and use your tools and resources.

Sources

Previous

Tool Schema Design