geekskai Logogeekskai
ToolsBlogPricing
Sign in
Sign in
ToolsBlogSign in
Sunday, June 8, 2025|3.115Mins Read

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

Authors
  • avatar
    Name
    Geeks Kai
    Twitter
    @KaiGeeks
Discuss on Twitter • View on GitHub

Tags

MCPLLMServerAIDevelopmentTutorial

Previous Article

Best AI Stocks: Your Guide to Smart Investments

Next Article

Online Earning Through Guest Posts: A Smart Way to Monetize Your Expertise
← Back to the blog
geekskai Logo
geekskai

Public tools for developers and creators, plus optional Geekskai Audio Toolkit plans. Built with care.

Popular Tools

SoundCloud DownloaderSoundCloud to MP3SoundCloud to WAVSoundCloud PlaylistSoundCloud Artwork
View All Tools

Resources

BlogAbout MePricingTagsProjectsPrivacy PolicyTerms of ServiceRefund Policy

Connect With Us

mailMail
githubGitHub
twitterTwitter
linkedinLinkedin
© 2026 geekskai • All rights reserved
MCP server development

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.

1. Install the matching SDK

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.

2. Save server.py

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.

3. Save check_mcp.py

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.

4. Inspect or connect the server

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.

Troubleshooting

SymptomCheck
ImportError or ModuleNotFoundErrorConfirm the active interpreter and installed mcp major version
Tool is missingConfirm the decorated function is imported and the host uses the intended script
Invalid resultInspect is_error and content before using the returned value
Server works in-process but not in a hostCheck 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.