Skip to main content

The simplest way to build and connect MCP servers and clients.

Project description

MCPSDK

The simplest way to build and connect MCP (Model Context Protocol) servers and clients in Python.

No async. No boilerplate. Just define your tools and go.

Install

pip install mcpsdk

Quickstart

Build a server

from mcpsdk import MCPServer

server = MCPServer("my-server")

@server.tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny in {city}, 22C"

@server.tool
def calculate(expression: str) -> str:
    """Evaluate a math expression."""
    return str(eval(expression))

server.run()              # stdio (default)
server.run(mode="sse")    # SSE on http://0.0.0.0:8000

Connect a client

from mcpsdk import MCPClient

# SSE — server already running
with MCPClient.from_sse("http://localhost:8000/sse") as client:
    tools  = client.list_tools()
    result = client.call_tool("get_weather", {"city": "Tokyo"})
    print(result)

# stdio — client spawns the server
with MCPClient.from_stdio("python", ["server.py"]) as client:
    tools  = client.list_tools()
    result = client.call_tool("calculate", {"expression": "12 * 7"})
    print(result)

Use with any LLM

list_tools() returns raw MCP format — convert to your LLM's format yourself:

from mcpsdk import MCPClient

with MCPClient.from_sse("http://localhost:8000/sse") as client:
    tools = client.list_tools()
    # tools → [{ "name", "description", "parameters" }]

    # Anthropic
    anthropic_tools = [{"name": t["name"], "description": t["description"], "input_schema": t["parameters"]} for t in tools]

    # OpenAI
    openai_tools = [{"type": "function", "function": {"name": t["name"], "description": t["description"], "parameters": t["parameters"]}} for t in tools]

    # when LLM picks a tool:
    result = client.call_tool(tool_name, params)

API

MCPServer

Method Description
MCPServer(name) Create a server
@server.tool Register a function as a tool
server.run(mode, host, port) Start the server (mode="stdio" or "sse")

MCPClient

Method Description
MCPClient.from_sse(url) Create client for remote SSE server
MCPClient.from_stdio(command, args) Create client for local stdio server
client.connect() Open connection
client.disconnect() Close connection
client.list_tools() Get all tools from server
client.call_tool(name, params) Call a tool, get result as string
client.tool_info(name) Get details of one tool

Transport modes

stdio SSE
Where Same machine Anywhere
Server startup Client spawns it Already running
Connect with from_stdio(cmd, args) from_sse(url)
Best for Local tools Remote / shared servers

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcpsdk-0.1.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcpsdk-0.1.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file mcpsdk-0.1.2.tar.gz.

File metadata

  • Download URL: mcpsdk-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for mcpsdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e67ef3bf45a687334bff8616b6624db4198e069b8b81fa53cc432bef611329ef
MD5 87ba7327cc791c43ed74b1f8d4f4bfea
BLAKE2b-256 764391d8946d943a39668b1ef3abd59749b66724b9ca493568b1c255a9583345

See more details on using hashes here.

File details

Details for the file mcpsdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mcpsdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for mcpsdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e08335b2b68833ec740893e38210c13d793e620afead5311035a35286a72de10
MD5 079dd7ef94029646801cbf78a0dcc8ae
BLAKE2b-256 e70f05cb345fe46ab3f19ec8873aba337aec3dc937bbd4f07fe1718bc9462d8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page