Metadata-Version: 2.4
Name: respan-instrumentation-mcp
Version: 0.1.0
Summary: Respan instrumentation plugin for Model Context Protocol (MCP)
License: Apache 2.0
Author: Respan
Author-email: team@respan.ai
Requires-Python: >=3.11,<3.14
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: mcp (>=1.27.0)
Requires-Dist: openinference-instrumentation-mcp (>=2.0.0)
Requires-Dist: opentelemetry-semantic-conventions-ai (>=0.4.1)
Requires-Dist: respan-instrumentation-openinference (>=1.2.2)
Requires-Dist: respan-sdk (>=2.5.0)
Requires-Dist: respan-tracing (>=2.16.1,<3.0.0)
Requires-Dist: wrapt (>=1.16.0)
Description-Content-Type: text/markdown

# respan-instrumentation-mcp

Respan instrumentation plugin for [Model Context Protocol](https://modelcontextprotocol.io/) Python applications.

The package enables upstream OpenInference MCP transport context propagation and adds Respan spans for common `mcp.ClientSession` operations such as tool listing, tool calls, resource reads, and prompt fetches.

## Configuration

### 1. Install

```bash
pip install respan-ai respan-instrumentation-mcp mcp
```

### 2. Set Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `RESPAN_API_KEY` | Yes | Your Respan API key. Authenticates tracing export. |
| `RESPAN_BASE_URL` | No | Defaults to `https://api.respan.ai/api`. |

## Quickstart

```python
import asyncio
import sys

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from respan import Respan, workflow
from respan_instrumentation_mcp import MCPInstrumentor

respan = Respan(instrumentations=[MCPInstrumentor()])


@workflow(name="mcp_tool_call_workflow")
async def run_mcp_client() -> None:
    server_params = StdioServerParameters(
        command=sys.executable,
        args=["server.py"],
    )

    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            print([tool.name for tool in tools.tools])
            result = await session.call_tool(
                "summarize_city",
                arguments={"city": "Paris"},
            )
            print(result)


asyncio.run(run_mcp_client())
respan.flush()
respan.shutdown()
```

## Further Reading

See the [Respan example projects](https://github.com/respanai/respan-example-projects) for runnable MCP scripts.

