Introduction: What is MCP and Why Does It Matter?
Imagine the model (like ChatGPT) is a brilliant chef, but the real kitchen (databases, files, services) is in the next room. MCP is like a standardized door between the rooms: the chef can ask through the door "bring tomatoes" (a tool called search) and then "give me tomatoes #1, #2" (a tool called fetch).
In practice, MCP is a simple protocol that allows a client (the model) to communicate with a server that provides tools. The server declares what tools it has and how to feed them input, and the model can call them at runtime.
What Do We Get?
- Connect the model to organizational/private knowledge (DB, files, APIs) without exposing everything as text
- Control: you decide which operations are allowed
- Modularity: start small and expand at your own pace
Basic Terms
- Server — A small HTTP service that returns a list of tools and can execute them
- Tools — Operations the model is allowed to invoke (e.g., search, fetch, create_ticket)
- Client — The model/API that communicates with the server to use tools
What We'll Build
We'll build a minimal MCP server with Python and FastAPI that includes two tools: search and fetch. We'll expose it to the internet with ngrok and connect it to ChatGPT and the OpenAI API.
Prerequisites
- Computer with Python 3.10+
- Basic terminal knowledge
- Free ngrok account (for internet exposure)
Part 1 — Minimal MCP Server in Python
Quick installation:
python -m venv .venv
source .venv/bin/activate
pip install fastapi uvicorn pydantic
Create a main.py file with two tools: search and fetch. The server defines the tools, exposes them via /tools/list, and executes them via /tools/call.
Run locally:
uvicorn main:app --host 0.0.0.0 --port 8000
Internet Exposure (ngrok)
ngrok config add-authtoken <TOKEN>
ngrok http 8000
Part 2 — Connecting to ChatGPT
Custom connectors (MCP) are available for Pro and Business accounts. Steps: In ChatGPT → Settings → Connectors → Add Custom MCP. Enter the public Base URL, confirm permissions, and in conversation enable Use connectors.
Part 3 — Using via OpenAI API
You can define MCP as a tool in the Responses API. The example uses curl to send a request to the API with type: "mcp" configuration and server URL.
Part 4 — Troubleshooting
- "doesn't implement our specification" → Usually missing/changed search/fetch or non-matching schema
- Running behind NAT/Firewall → Use ngrok; ensure the URL is publicly accessible
- Latency/Scale → Use workers/hardening for production
Upgrades to Consider
- Authentication layer (OAuth/JWT) per your gateway
- Helper libraries: FastMCP and Replit example
- Docker: Basic Dockerfile for running the server in a container
Summary
MCP (Model Context Protocol) is a powerful tool that enables direct connection between AI models and external work tools. In this guide, we learned how to build a basic MCP server with Python and FastAPI, connect it to ChatGPT and the OpenAI API, and handle common issues. With this knowledge, you can start building custom integrations that save time and enable advanced automations for your organization.