dspy-mcp-tool-integration

Solid

This skill should be used when the user asks to "use MCP tools with DSPy", "connect an MCP server to ReAct", "convert MCP tools to DSPy tools", mentions Model Context Protocol, `dspy.Tool.from_mcp_tool`, streamable HTTP MCP transport, stdio MCP servers, or needs to expose MCP-compatible tools to a DSPy agent.

AI & Automation 78 stars 10 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 90/100

Stars 20%
63
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# DSPy MCP Tool Integration ## Goal Connect an MCP server with the MCP Python client, convert its tools to `dspy.Tool`, and use them in an async DSPy agent. ## Install ```bash pip install -U "dspy[mcp]>=3.2.1,<3.3" ``` DSPy converts tools but does not manage MCP connections. Keep the `ClientSession` alive for as long as the DSPy tools are in use. ## Streamable HTTP Server ```python import asyncio import dspy from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client async def main(): async with streamablehttp_client("http://localhost:8000/mcp") as (read, write): async with ClientSession(read, write) as session: await session.initialize() response = await session.list_tools() tools = [dspy.Tool.from_mcp_tool(session, tool) for tool in response.tools] agent = dspy.ReAct("task -> result", tools=tools, max_iters=5) output = await agent.acall(task="Check the weather in Tokyo") print(output.result) asyncio.run(main()) ``` ## Local Stdio Server ```python import asyncio import dspy from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client async def main(): params = StdioServerParameters( command="python3", args=["path/to/server.py"], env=None, ) async with stdio_client(params) as (read, write): async with ClientSession(read, write) as session: await session.initial...

Details

Author
OmidZamani
Repository
OmidZamani/dspy-skills
Created
5 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Solid

mcp-integration

This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", or discusses MCP server types (SSE, stdio, HTTP, WebSocket). Provides comprehensive guidance for integrating Model Context Protocol servers into Claude Code plugins for external tool and service integration.

29,969 Updated today
anthropics
AI & Automation Solid

mcp-integration

This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", or discusses MCP server types (SSE, stdio, HTTP, WebSocket). Provides comprehensive guidance for integrating Model Context Protocol servers into Claude Code plugins for external tool and service integration.

27,984 Updated today
davila7
AI & Automation Solid

mcp-integration

This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", or discusses MCP server types (SSE, stdio, HTTP, WebSocket). Provides comprehensive guidance for integrating Model Context Protocol servers into Claude Code plugins for external tool and service integration.

340 Updated 3 weeks ago
tzachbon