Model Context Protocol: how MCP works and how to build on it
What MCP is, how it standardizes tool calling for LLMs, and how to build an MCP server that exposes your data or APIs to ChatGPT, Claude, and Cursor.
How to
Install the SDK and scaffold the project
Run npm i @modelcontextprotocol/sdk. Create src/server.ts and src/index.ts; set type=module and bin in package.json.
Declare the three primitives: tools / resources / prompts
Tools are callables with input schemas; resources are structured data sources (files, DB, API); prompts are reusable templates. Return them from ListTools / ListResources / ListPrompts.
Pick a transport: stdio / Streamable HTTP / SSE
Local subprocesses: stdio. Cloud-hosted: Streamable HTTP. Legacy clients: SSE. For local testing stdio is enough.
Write a minimal tool and self-test it
For example server.setRequestHandler(CallToolRequestSchema, ...) for an echo tool. Verify ListTools + CallTool with MCP Inspector or the SDK's test client.
Wire up ChatGPT / Claude / Cursor and add OAuth
Register OAuth 2.0 metadata on the server, hook up your own auth backend. Document the per-host integration steps in the README. Before launch, run a prompt-injection mitigation checklist.
Model Context Protocol: how MCP works and how to build on it
MCP is an open standard for LLM tool calling. Clients (ChatGPT, Claude, Cursor) talk to servers over JSON-RPC and consume three primitives: tools, resources, and prompts.
1. Overview
The Model Context Protocol (MCP) is an open standard, originally proposed by Anthropic, that lets LLMs call any tool or data source through a single contract. This guide covers the architecture, transports, and how to build an MCP server for your own product.
2. Key points
- Three roles: Hosts (the chat product), Clients (the SDK), Servers (your service)
- Transports: stdio for local subprocesses, Streamable HTTP for cloud, SSE for older servers
- Tools are callables with an input schema; Resources are structured data sources; Prompts are reusable templates
- A minimal TypeScript MCP server is usually 50–200 lines using @modelcontextprotocol/sdk
- Before shipping: OAuth auth, rate limits, allowlist of sensitive tools to avoid prompt-injection abuse
3. How it works
The sections below unpack each point. Skim alongside the OpenAI documentation for full context.
4. Practical steps
- Define 'done' up front — what does success look like?
- Pick the right model using the comparison above.
- Run the minimal example end to end; record parameters and the model version.
- Integrate into your existing code.
- Monitor logs and failure modes; review weekly.
5. Common errors and fixes
- 401: invalid or expired API key — rotate it.
- 429: rate limit hit — enable exponential backoff retries.
- 400: bad request — verify the model name and messages shape.
- Poor quality output: try a different model, add few-shot examples, trim the prompt.
6. Next steps
Once you are comfortable here, continue with:
- ChatGPT Complete Guide (2026): From Beginner to Expert
- Prompt Engineering Core Patterns: 8 Templates That 2x GPT Output
- OpenAI API Beginner: Your First GPT-5.6 Call
Key points
- Three roles: Hosts (the chat product), Clients (the SDK), Servers (your service)
- Transports: stdio for local subprocesses, Streamable HTTP for cloud, SSE for older servers
- Tools are callables with an input schema; Resources are structured data sources; Prompts are reusable templates
- A minimal TypeScript MCP server is usually 50–200 lines using @modelcontextprotocol/sdk
- Before shipping: OAuth auth, rate limits, allowlist of sensitive tools to avoid prompt-injection abuse
❓ Frequently asked questions
Official references
Subscribe to GPTMap Weekly
One email every Monday: curated OpenAI updates, deep dives, and best practices. No ads, unsubscribe anytime.