Metadata-Version: 2.4
Name: mcpsdk
Version: 0.1.2
Summary: The simplest way to build and connect MCP servers and clients.
License: MIT
Project-URL: Homepage, https://github.com/yourname/mcpeasy
Project-URL: Bug Tracker, https://github.com/yourname/mcpeasy/issues
Keywords: mcp,ai,agent,llm,tools,model-context-protocol
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: mcp>=1.0.0
Requires-Dist: httpx>=0.27.0

# 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

```bash
pip install mcpsdk
```

## Quickstart

### Build a server

```python
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

```python
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:

```python
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
