Repository navigation
Conversation
ahmeshaf
force-pushed
the
feat/mcp_adapter
branch
from
February 23, 2026 05:49
3f17a58 to
ce562f9
Compare
Add async context managers that handle the full MCP session lifecycle (connect, initialize, list/filter tools) and yield ready-to-use dspy.Tool lists. Supports include_tools/exclude_tools filtering, unknown tool name validation, and read_timeout propagation via ClientSession. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ahmeshaf
force-pushed
the
feat/mcp_adapter
branch
from
February 23, 2026 07:03
ce562f9 to
6f407d0
Compare
…apters Replace manual MCP session boilerplate with the new convenience context managers in both the MCP programming guide and the airline booking tutorial. Add docs for include_tools/exclude_tools filtering and timeout parameters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… with mcp The previous pin (weaviate-client~=4.5.4) required httpx<=0.27.0 which conflicted with mcp>=1.20.0 requiring httpx>=0.27.1. Also replace mcp-proxy test dependency with FastMCP's built-in streamable-http transport. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 task done
ahmeshaf
marked this pull request as ready for review
February 24, 2026 20:01
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ahmeshaf
force-pushed
the
feat/mcp_adapter
branch
from
February 25, 2026 19:39
4561928 to
7bb1160
Compare
|
To use Codex here, create a Codex account and connect to github. |
Contributor
Author
|
@codex can you review this |
|
To use Codex here, create a Codex account and connect to github. |
ahmeshaf
marked this pull request as draft
February 26, 2026 20:39
…mcp dep version Co-authored-by: ahmeshaf <10776106+ahmeshaf@users.noreply.github.com>
fix(dspy): fix falsy bug in mcp tool filtering, extract shared helper, add __all__, harden tests, pin mcp dep
ahmeshaf
marked this pull request as ready for review
February 26, 2026 21:02
Signed-off-by: Rehan Ahmed <ahmeshaf.rehan@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simplifying MCP integration:
stdio_mcp_toolsandhttp_mcp_toolsconvenience adaptersSummary
Two async context managers that collapse the MCP boilerplate (connect → initialize → list → convert) into a single
async withstatement. Each addresses the friction of manually wiring upClientSession,list_tools(), andTool.from_mcp_toolevery time you use MCP with DSPy. All changes are backwards-compatible —convert_mcp_tool/Tool.from_mcp_toolstill work as before.+375 lines, −126 lines across 6 files (excluding
uv.lockchurn).The changes
1.
stdio_mcp_tools— async context manager for stdio MCP serversProblem: Connecting to a local MCP server via stdio requires 3 nested context managers, manual
initialize(),list_tools(), and a list comprehension to convert tools — ~12 lines of boilerplate every time.Solution:
stdio_mcp_tools(server_params)handles the full lifecycle and yields a ready-to-uselist[dspy.Tool].2.
http_mcp_tools— async context manager for streamable-HTTP MCP serversProblem: Same boilerplate issue for remote MCP servers, plus the
streamablehttp_clientimport and the 3-tuple unpacking.Solution:
http_mcp_tools(url)wraps the HTTP transport with the same clean interface.3. Tool filtering with validation
Problem: Users often want a subset of tools from an MCP server but have to filter manually after conversion.
Solution: Both adapters accept
include_tools/exclude_toolswith strict validation — unknown tool names raiseValueErrorimmediately instead of silently returning fewer tools.4. Timeout propagation
timeout(in seconds) is forwarded asread_timeout_secondstoClientSession, so long-running tool calls don't hang indefinitely.5. Dependency fix:
weaviate-client/mcphttpx conflictProblem:
weaviate-client~=4.5.4pinnedhttpx<=0.27.0, conflicting withmcp>=1.20.0which requireshttpx>=0.27.1.Solution: Widen to
weaviate-client>=4.5.4and pinmcp>=1.20.0.File-by-file
dspy/utils/mcp.pystdio_mcp_tools,http_mcp_tools, shared helpers (_build_tools_from_session,_filter_mcp_tools,_validate_tool_names),__all__exporttests/utils/test_mcp.pytests/utils/resources/mcp_server.py--transportand--portCLI args for streamable-HTTP test fixturedocs/docs/learn/programming/mcp.mddocs/docs/tutorials/mcp/index.mdstdio_mcp_toolspyproject.tomlweaviate-clientconstraint, pinmcp>=1.20.0uv.lockTest summary
stdio_mcp_tools(basic, include, exclude, conflict, timeout, unknown names)http_mcp_tools(basic, include, exclude, unknown names)convert_mcp_tool(unchanged)Docs updates
docs/docs/learn/programming/mcp.md: Rewrote HTTP and stdio examples to use the new adapters. Replaced "Tool Conversion" section with "Filtering Tools" and "Timeout" sections.docs/docs/tutorials/mcp/index.md: Updated the airline booking tutorial to usestdio_mcp_tools, removing manual session management code.Breaking change:
mcpminimum version bumped to 1.20.0The
mcpoptional dependency is pinned to>=1.20.0(was unpinned). This is required becausemcp1.20.0 renamed the streamable-HTTP client import:mcp<1.20):from mcp.client.streamable_http import streamablehttp_clientmcp>=1.20):from mcp.client.streamable_http import streamable_http_clienthttp_mcp_toolsuses the newstreamable_http_clientname, so oldermcpversions will raiseImportError. Users on older versions will need to upgrade:pip install --upgrade "mcp>=1.20.0". Thestdio_mcp_toolsadapter is unaffected by this rename.Implementation notes
convert_mcp_toolandTool.from_mcp_toolremain available for advanced use casesmcpdependencies are imported inside the context managers, so the module loads withoutmcpinstalledinclude_toolsandexclude_toolsare mutually exclusive (raisesValueErrorif both specified)ValueErrorwith the available tool set listed in the messageis not Nonechecks (not truthiness) so empty lists are handled correctly🤖 Generated with Claude Code
PR format inspired by #9295.