RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /MCP Server Implementation
  6. /Ch. 4
MCP Server Implementation

04. Python SDK Setup

Chapter 4 of 22 · 20 min
KEY INSIGHT

The MCP Python SDK abstracts protocol details, letting developers focus on capability implementation rather than message handling. The MCP Python SDK (`mcp`) provides the building blocks for server implementation. Installation and basic project structure come first. **Installation:** The SDK installs via pip: ```bash pip install mcp ``` Verify the installation: ```python import mcp print(mcp.__version__) ``` **Minimal Server Structure:** A basic MCP server requires three components: transport setup, request handlers, and capability definitions. ```python from mcp.server import Server from mcp.server.stdio import stdio_server from mcp.types import Tool, TextResource app = Server("my-first-server") @app.list_tools() async def list_tools() -> list[Tool]: return [ Tool( name="hello", description="Returns a greeting", inputSchema={"type": "object", "properties": {}} ) ] @app.call_tool() async def call_tool(name: str, arguments: dict) -> str: if name == "hello": return "Hello from MCP server!" raise ValueError(f"Unknown tool: {name}") ``` **Async Considerations:** MCP servers use async/await patterns throughout. The SDK relies on Python's `asyncio` for concurrent request handling. Server implementations must be async-compatible. ```python import asyncio async def main(): async with stdio_server() as (read_stream, write_stream): await app.run( read_stream, write_stream, app.create_initialization_options() ) if __name__ == "__main__": asyncio.run(main()) ``` **Debugging Setup:** When developing, run the server directly to see JSON-RPC messages: ```bash python my_server.py ``` Input requests manually to test responses. The stdio transport outputs JSON directly, making debugging straightforward. **Common Installation Failures:** - Python version mismatch: MCP SDK requires Python 3.10+ - Missing optional dependencies: `pip install mcp[cli]` for additional tools - Virtual environment conflicts: Ensure activation before installation **Testing Without a Client:** The SDK includes testing utilities: ```python from mcp.testing import ClientSession from mcp.server.stdio import stdio_server async def test_server(): async with stdio_server() as streams: async with ClientSession(streams[0], streams[1]) as session: await session.initialize() tools = await session.list_tools() print(tools) ```

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Create a working MCP server that implements a single tool returning the current server time. Test it by running the server and manually sending an initialization request followed by a tools/call request via stdin.

← Chapter 3
Architecture: Client vs Server
Chapter 5 →
Resources in MCP