Build an MCP Server for LLMs: Python Setup and a Working Tool Test
- Authors

- Name
- Geeks Kai
- @KaiGeeks

An MCP server exposes capabilities through the Model Context Protocol. LLM means large language model. The server does not need to train, download, or host a model to provide a tool.
This tutorial builds one deterministic tool and checks it through an MCP client. For the roles of host, client, and server, read AI MCP for beginners.
Use Python 3.11 or later and a new virtual environment. Docker and a database are not needed for this example. The commands below use a POSIX shell:
mkdir geekskai-mcp-demo
cd geekskai-mcp-demo
python3 -m venv .venv
. .venv/bin/activate
python -m pip install "mcp[cli]>=2,<3"
python -m pip show mcp
On Windows, create the environment with your Python launcher and activate it with the command appropriate for PowerShell or Command Prompt.
The official SDK installation instructions describe the package and Python requirement. The migration guide explains why 1.x FastMCP imports differ from 2.x MCPServer imports.
from mcp.server import MCPServer
mcp = MCPServer("Geekskai addition demo")
@mcp.tool()
def add(left: int, right: int) -> int:
"""Return the sum of two integers without external side effects."""
return left + right
if __name__ == "__main__":
mcp.run()
The function's type hints describe its input. This server performs no file writes, database calls, or model requests.
This check uses the SDK client's in-process transport. It exercises tool discovery, a successful call, and invalid input without opening a network port.
import asyncio
from mcp import Client
from server import mcp
async def main() -> None:
async with Client(mcp) as client:
tool_listing = await client.list_tools()
tool_names = [tool.name for tool in tool_listing.tools]
assert "add" in tool_names, tool_names
addition_result = await client.call_tool("add", {"left": 3, "right": 4})
assert not addition_result.is_error, addition_result.content
assert addition_result.structured_content == {"result": 7}
invalid_result = await client.call_tool("add", {"left": "not-a-number", "right": 4})
assert invalid_result.is_error, invalid_result.content
print("PASS: discovery, addition result, and invalid input")
if __name__ == "__main__":
asyncio.run(main())
Run it from the directory containing both files:
python check_mcp.py
Expected output includes:
PASS: discovery, addition result, and invalid input
Tool failures can be returned as error results rather than Python exceptions. Check is_error before trusting structured_content; do not treat every completed request as a successful operation.
For an interactive check, run the SDK's development command:
mcp dev server.py
In Inspector, connect to the server, list tools, select add, and enter integer arguments. The official getting-started guide covers the Inspector workflow.
Running python server.py starts the stdio server and waits for a client; an idle terminal is expected. A host using stdio must launch the server with the correct Python environment and absolute script path. Keep diagnostic output on stderr so it does not interfere with protocol messages.
The in-process test does not validate a host configuration or remote deployment. Add those checks separately when choosing a transport and deployment environment. Do not expose this development setup publicly just to test it.
| Symptom | Check |
|---|---|
| ImportError or ModuleNotFoundError | Confirm the active interpreter and installed mcp major version |
| Tool is missing | Confirm the decorated function is imported and the host uses the intended script |
| Invalid result | Inspect is_error and content before using the returned value |
| Server works in-process but not in a host | Check the launch command, environment, transport, and stderr logs |
After this check passes, replace the addition function with one small capability and add an independently checkable input and expected result for it.