HomeServer Architecture
Protocol Specification & Developer Hub

Model Context Protocol Server Guide

Learn how MCP servers communicate over JSON-RPC 2.0, expose typed tools and resources, and safely connect Claude Desktop, Cursor, and autonomous AI agents to your code and databases.

1. Tools (Actions)

Executable functions with JSON Schema parameter definitions. Claude and Cursor call tools to modify databases, query APIs, or write files.

2. Resources (Context)

Read-only context providers that expose documents, schemas, and logs via URI schemes (e.g., postgres://mydb/schema).

3. Transports (stdio & SSE)

Lightweight local communication over standard input/output (stdio) for zero-latency execution, or Server-Sent Events (SSE) for distributed setups.

5-Minute Quickstart

Build an MCP Server in TypeScript or Python

Choose your runtime to view a functional Model Context Protocol server exposing custom tools.

server.ts
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
  CallToolRequestSchema,
  ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";

// 1. Initialize MCP Server
const server = new Server(
  { name: "my-custom-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

// 2. Define exposed tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
  return {
    tools: [
      {
        name: "calculate_tax",
        description: "Calculate sales tax for a transaction",
        inputSchema: {
          type: "object",
          properties: {
            amount: { type: "number", description: "Transaction amount in USD" },
            state: { type: "string", description: "Two-letter US state code" },
          },
          required: ["amount", "state"],
        },
      },
    ],
  };
});

// 3. Handle tool invocation
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === "calculate_tax") {
    const { amount, state } = request.params.arguments as { amount: number; state: string };
    const rate = state === "CA" ? 0.0725 : 0.05;
    const tax = amount * rate;
    return {
      content: [{ type: "text", text: `Tax for ${state} on $${amount} is $${tax.toFixed(2)}` }],
    };
  }
  throw new Error("Tool not found");
});

// 4. Connect via stdio
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("MCP Server running on stdio");
Communication Protocol

Standard Input/Output (stdio) vs Server-Sent Events (SSE)

Model Context Protocol supports two standardized transports for connecting clients to servers.

stdio Transport (Recommended for Local Dev)

Sub-Process Pipes

The host application (Claude Desktop or Cursor) spawns the MCP server as a child process using npx, uvx, or docker run.

  • Zero network ports or firewall configurations needed
  • Instant process termination when client closes
  • Highest security: credentials stay in process environment
SSE Transport (Remote & Cloud Microservices)

HTTP Server-Sent Events

The MCP server runs as a standalone HTTP microservice. The client establishes an SSE stream to receive server messages and sends client requests via HTTP POST.

  • Host centralized enterprise tools in your VPC or AWS
  • Multiple AI clients can share a single running server
  • Standard Bearer token and OAuth authentication support
Best Practices

Production Server Checklist

Ensure your custom MCP server functions reliably with Claude Desktop, Cursor, and Cline.

Never log to stdout in stdio mode

Standard stdout is strictly reserved for JSON-RPC messages. Always use console.error() or stderr for debugging logs.

Provide detailed JSON Schemas

Write clear parameter descriptions in your input schema so LLMs know exactly what data format and required values to pass.

Return graceful error messages

When a database query or API call fails, return the error message in the tool response text so the agent can self-correct instead of crashing.

Publish to npm or PyPI for 1-click install

Package with an executable bin so users can instantly launch your server via npx your-server or uvx your-server.

Comprehensive Directory

Looking for existing servers to integrate today?

Discover 20,780+ production-ready servers for PostgreSQL, GitHub, Docker, Slack, and cloud APIs.

Explore All 20,780+ Servers
Autonomous Integration

Connect any MCP server to Claude Desktop & Cursor

The Model Context Protocol gives AI agents direct access to tools, context, databases, and APIs with zero boilerplate code.

Three-Step Deployment

1

Select an MCP Module

Browse our index of 20,780+ servers and pick the integration matching your stack.

2

Copy JSON Configuration

Use our 1-click config generator to copy the preformatted config snippet for your client.

3

Execute in Your IDE

Save the JSON file and restart Claude Desktop or Cursor for instant tool availability.

Standardized JSON-RPC 2.0 transport over stdio and SSE
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost:5432/mydb"]
    }
  }
}
Paste into claude_desktop_config.json