Skip to content

MCP (Model Context Protocol)

Call a remote MCP tool

Python SDK 0.3.2 provides real MCP client sessions for stdio, sse and streamable-http. Install the optional dependency before invoking a tool:

pip install "langstitch-sdk[mcp]>=0.3.2"
from langstitch.mcp_client import call_mcp_tool

result = call_mcp_tool(
    {"transport": "streamable-http", "url": "http://localhost:8000/mcp"},
    "echo",                         # replace with a tool exposed by your server
    {"text": "hello"},              # the tool's declared argument schema
    timeout=30,
)

For a local subprocess, use a server configuration such as {"transport": "stdio", "command": "python", "args": ["server.py"]}. Use await call_mcp_tool_async(...) inside an active event loop. Each call owns and closes its transport/session; invalid settings, timeout and remote tool errors raise errors. The returned dictionary is the MCP result envelope.

Generated Python MCP nodes use this adapter. Java and Go MCP export remains unsupported. The client does not accept http as a transport alias or support WebSocket transport.

Register server metadata

The server decorators below register tools, resources and prompts as application metadata. Registration does not itself start a listening MCP server; your server integration must bind those entries to its transport and implement authorization. Do not infer client transport support from the values accepted by the decorator.

from langstitch import (
    langstitch_mcp_server, mcp_tool, mcp_resource, mcp_prompt,
)

@langstitch_mcp_server(protocol="stdio")   # stdio | sse | streamable-http | http | websocket
class MCPServer:
    """My MCP server."""

    @mcp_tool(name="now", roles=["agent"], description="Current server time.")
    def now(self) -> str:
        from datetime import datetime, timezone
        return datetime.now(timezone.utc).isoformat()

    @mcp_resource(name="readme", uri="file://README.md", mime_type="text/markdown")
    def readme(self) -> str:
        return open("README.md").read()

    @mcp_prompt(name="summarize", description="Summarize text", arguments=["text"])
    def summarize(self, text: str) -> str:
        return f"Summarize the following:\n\n{text}"

Server metadata transport names

These names describe registry metadata. They are not evidence of a running server or of transport support in the 0.3.2 client adapter above.

protocol Use
stdio Local subprocess servers (default for many clients).
sse Server-Sent Events over HTTP.
streamable-http / http HTTP streaming transport.
websocket Bidirectional WebSocket transport.

Primitives

Decorator Exposes Key options
@mcp_tool a callable tool name, roles, description
@mcp_resource a readable resource name, uri, mime_type
@mcp_prompt a reusable prompt name, description, arguments

Pinning config

Like the graph server, the MCP server accepts properties= to pin the config file loaded at startup; when omitted, discovery is used (application.json preferred, else application.yaml).

@langstitch_mcp_server(protocol="stdio", properties="application.yaml")
class MCPServer: ...