promptgarten 🌱
Guide●●●7 min Β· +65 XP

Writing Your Own MCP Server

An MCP server exposes tools, data, or templates to any MCP-capable client – from Claude Code to Antigravity.

Three building blocks

An MCP server offers a client like Claude Code or Antigravity three kinds of capability: Tools (functions the model actively calls, e.g. a database query), Resources (passive data like files or API responses that the application supplies), and Prompts (ready-made templates that users deliberately pick).

The minimal flow

A server runs as its own process and talks to the client over a fixed protocol (typically standard I/O or HTTP). On startup, the client calls tools/list, gets back a list of tool definitions with a JSON schema for the parameters, and calls tools/call with the right arguments when needed. So your server only has to: register tools with a name, description, and input schema, and return a result when called.

Official SDKs

The modelcontextprotocol organization maintains official SDKs for Python, TypeScript, Java, Kotlin, C#, Go, PHP, Ruby, Rust, and Swift – you don't have to implement the protocol by hand.

Connecting to a client

A finished server gets registered in the client's configuration (e.g. mcpServers in Claude Code or mcp_config.json in Antigravity), usually with a command and arguments to start the server process. After that it shows up in the client's MCP manager, and its tools become available to the model.

EXAMPLE

A minimal Python server core (using the official SDK): an `@mcp.tool()` decorator registers a function `get_forecast(latitude, longitude)` as a tool – the client discovers it automatically via `tools/list` and calls it when needed.

πŸ› οΈ EXERCISE β€” TRY IT YOURSELF

Use an official MCP SDK (e.g. Python) to build a minimal server with exactly one tool, and connect it to an MCP-capable client.

  1. Install the official SDK for your language and create a server with a single tool (e.g. a function that returns the current date).
  2. Register the server in your client's MCP configuration (e.g. Claude Code or Antigravity) with a start command and arguments.
  3. Open your client's MCP manager (e.g. /mcp), check that the server is connected, and let the model call your tool.

βœ… SELF-CHECK

  • ☐ Did the client discover your tool automatically via tools/list, without you registering it manually anywhere else?
  • ☐ What happens if your server process (on STDIO transport) accidentally logs to stdout instead of stderr?
  • ☐ Could you now connect the same server to a different MCP client without rewriting it?

QUICK QUIZ

What's the difference between an MCP "Tool" and an MCP "Resource"?

Share:𝕏inπŸ’¬

SOURCES

RELATED TOPICS

MCP (Model Context Protocol): How AI Tools Connect ●●○Tool Use: How LLMs Call Tools ●●○Claude Code: Anthropic's CLI Agent ●●○Plugins: Extensions for AI Coding Tools ●○○