A minimal example showing how to expose a tool via FastMCP and call it using OpenAI’s MCP tool integration.
The MCP server runs locally, is exposed publicly via ngrok, and the OpenAI client connects to the MCP endpoint to discover tools and invoke them (tool calling).
- Starts a FastMCP server that exposes a single tool:
greet(name: str) -> str - Uses ngrok to create a public URL for the local server
- Runs an OpenAI client script that:
- connects to the MCP server URL
- retrieves the tool list
- calls the tool through OpenAI tool calling
- prints the greeting result
- Python 3.12 recommended
- An OpenAI API key
- ngrok installed and logged in
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel
#Dependencies
python -m pip install -U fastmcp openai python-dotenv