Third-party toolUpdated 2026.11.14

FastMCP: Test a Python MCP Tool Before Connecting an AI Host

Build a FastMCP 4.2.0 tool and test discovery, a known response, and an unknown-ID error using an in-memory client. HTTP deployment is not covered.

Aaron recommends Open official GitHub

FastMCP is a Python framework for building and connecting MCP tools. Testing the data contract before adding an AI host makes failures easier to locate. This 4.2.0 test used an in-memory client to check discovery, a known response, and an error. It opened no HTTP port and did not ask a model to choose or call a tool.

After starting the server, check its interface through MCP Inspector's tool calls. For file-tool scope, refer to Filesystem MCP's allowed directories.

Define a tool with a known answer

The dispatch_cutoff tool accepts a string note. NOTE-31 returns 08:30; any other identifier raises ValueError. Keep the first tool small so a data-contract failure is visible before adding authentication, a database, or a model.

Pin and exercise the local contract

Run the shell block below in a Python 3.12 virtual environment to install the pinned package and execute the embedded Python example. Client(mcp) connects directly to the server object. That exercises the in-memory transport and does not establish that stdio, HTTP, or a remote host works.

These commands use a POSIX shell. The test ran in Linux; Windows shell behavior was not tested.

python -m pip install "fastmcp==4.2.0"
python - <<'PY'
import asyncio
from fastmcp import FastMCP, Client
mcp = FastMCP("DispatchFixture")
@mcp.tool
def dispatch_cutoff(note: str) -> str:
    if note != "NOTE-31":
        raise ValueError("Unknown synthetic dispatch")
    return "08:30"
async def check():
    async with Client(mcp) as client:
        print(await client.list_tools())
        print(await client.call_tool("dispatch_cutoff", {"note": "NOTE-31"}))
asyncio.run(check())
PY

Three observed checks

list_tools exposed dispatch_cutoff with a required string note. The valid call returned 08:30 in text and a structured result. An unknown identifier raised ToolError with the synthetic failure reason. These checks validate the interface; correct tool selection by a model needs a separate test.

Evidence still needed before deployment

HTTP, stdio, OAuth, authorization, and Gateway behavior are described from official v4.2.0 material and the saved upstream snapshot; they were not locally tested. An in-memory success does not make external inputs trustworthy or provide operating-system isolation. Transport, timeouts, permissions, and real data sources need their own checks before connecting an AI host.

Official sources and test scope

Codex ran this synthetic-data test in a credential-free, non-root, network-disabled container. It is not a claim that the site owner tested it. Package version: 4.2.0; documentation snapshot: a8745d61e650.

Subscribe to AI tool picks and practical advice

Get worthwhile tool picks, test findings and important updates in your inbox.

Get a monthly-updated list of AI tools and Skills right away. We email when there are worthwhile tool picks, test findings or important updates. Unsubscribe anytime. Privacy

Almost done: check your inboxClick the button in the confirmation email and you will get the download link for the tool list. If you do not see it, check your spam or Promotions folder.

Or follow us on: