-
Notifications
You must be signed in to change notification settings - Fork 481
MCP enhancements: improves server config and adds support for all transport types (stdio, streamable-http) #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MCP enhancements: improves server config and adds support for all transport types (stdio, streamable-http) #718
Conversation
Sample Usage: aiq info mcp --client-type stdio --command python --args "-m mcp_server_time --local-timezone=America/Los_Angeles" Sample Output: get_current_time convert_time Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Anuradha Karuppiah <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Michael Demoret <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Start of dynamic_functions Signed-off-by: Anuradha Karuppiah <[email protected]>
This will need some iterating Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
If no default is defined in the schema, and the field isn’t in the "required" list, it should default to None (i.e., optional). Earlier logic marked the field as required (using ...) unless "default" is explicitly set i.e. it would mark optional fields with no default as required. Signed-off-by: Anuradha Karuppiah <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Anuradha Karuppiah <[email protected]>
|
@coderabbitai pause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (5)
src/nat/tool/mcp/mcp_client_base.py (5)
38-38: Confirm Python version compatibility foroverrideimport.The import statement for
overridedirectly fromtypingis compatible with Python 3.12+, but the project supports Python 3.11+. Ensure that the fallback totyping_extensionsis in place if needed.#!/bin/bash # Check if there's a compatibility layer for the override import rg -n "from typing import override" --type=py # Check if typing_extensions is a dependency cat pyproject.toml | grep -i "typing.extensions" # Check for any existing compatibility handling for override rg -n "typing_extensions.*override" --type=py
119-121: Update docstring to include all supported transport types.The docstring mentions 'sse', 'stdio', and 'streamable-http', which is accurate. However, to ensure consistency, verify that this list matches all supported transports mentioned elsewhere in the code.
68-71: Enum member names may fail with special characters or leading digits.Raw enum values containing spaces, hyphens, or leading digits will cause
ValueErrorwhen creating the Enum. Consider sanitizing these values.
203-204: Docstring incorrectly states it raises ValueError instead of MCPToolNotFoundError.The docstring should correctly document the exception type that's actually raised.
Apply this diff to fix the docstring:
Raises: - MCPToolNotFoundError: If no tool is available with that name. + MCPToolNotFoundError: If no tool is available with that name.
340-344: Update MCPToolClient docstring to match current parameters.The docstring still references
connect_fnwhich has been replaced withsession. Update the documentation to reflect the current implementation.Apply this diff to fix the docstring:
Args: - connect_fn (callable): Function that returns an async context manager for connecting to the server + session (ClientSession): The active ClientSession to use for tool calls tool_name (str): The name of the tool to wrap tool_description (str): The description of the tool provided by the MCP server. tool_input_schema (dict): The input schema for the tool.
🧹 Nitpick comments (1)
src/nat/tool/mcp/mcp_client_base.py (1)
172-223: Consider adding validation for session state in call_tool.While
get_toolandcall_toolboth check for session initialization, onlyget_toolchecks for_exit_stack. Consider consistent validation across both methods for robustness.Apply this diff for consistency:
@mcp_exception_handler async def call_tool(self, tool_name: str, tool_args: dict | None): + if not self._exit_stack: + raise RuntimeError("MCPBaseClient not initialized. Use async with to initialize.") + if not self._session: raise RuntimeError("MCPBaseClient not initialized. Use async with to initialize.")
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/nat/tool/mcp/mcp_client_base.py(5 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
{src/**/*.py,packages/*/src/**/*.py,examples/*/**/*.py}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Use abbreviations: 'nat' for API namespace and CLI tool, 'nvidia-nat' for package name, 'NAT' only for env var prefixes and informal code comments (never in documentation)
Files:
src/nat/tool/mcp/mcp_client_base.py
src/**/*.py
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
All importable Python code must live under src/ so namespace packages resolve correctly
Files:
src/nat/tool/mcp/mcp_client_base.py
**/*.py
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.py: Format Python code with yapf (PEP8 base, column_limit=120) run second in the toolchain
Run ruff (ruff check --fix) using configuration in pyproject.toml; fix warnings unless explicitly ignored; ruff is a linter only (not for formatting)
Respect naming: snake_case for functions and variables, PascalCase for classes, UPPER_CASE for constants
Prefer typing/collections.abc abstractions (e.g., Sequence over list)
Use typing.Annotated for units or extra metadata when useful
Treat pyright warnings (configured in pyproject.toml) as errors during development
Prefer httpx with SSL verification enabled by default for HTTP requests; follow OWASP Top-10
Use async/await for I/O-bound work (HTTP, DB, file reads)
Cache expensive computations with functools.lru_cache or an external cache when appropriate
Leverage NumPy vectorized operations when beneficial
Files:
src/nat/tool/mcp/mcp_client_base.py
**/*.{py,md,sh,yml,yaml,toml,json,ini,cfg,txt,rst,pyi}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Indent with 4 spaces (no tabs) and ensure every file ends with a single trailing newline
Files:
src/nat/tool/mcp/mcp_client_base.py
{src/**/*.py,packages/*/src/**/*.py}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
{src/**/*.py,packages/*/src/**/*.py}: All public APIs require Python 3.11+ type hints on parameters and return values
Provide Google-style docstrings for every public module, class, function and CLI command
Docstring first line must be a concise description ending with a period
Files:
src/nat/tool/mcp/mcp_client_base.py
**/*.{py,sh,md,yml,yaml,toml,json,ini,txt,cfg,rst,pyi}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{py,sh,md,yml,yaml,toml,json,ini,txt,cfg,rst,pyi}: Every file must start with the standard SPDX Apache-2.0 header
All source files must include the SPDX Apache-2.0 header template
Files:
src/nat/tool/mcp/mcp_client_base.py
**/*.{py,md}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Version numbers are derived by setuptools-scm; never hard-code versions in code or documentation
Files:
src/nat/tool/mcp/mcp_client_base.py
**/*
⚙️ CodeRabbit configuration file
**/*: # Code Review Instructions
- Ensure the code follows best practices and coding standards. - For Python code, follow
PEP 20 and
PEP 8 for style guidelines.- Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
Example:def my_function(param1: int, param2: str) -> bool: passDocumentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any
words listed in the
ci/vale/styles/config/vocabularies/nat/reject.txtfile, words that might appear to be
spelling mistakes but are listed in theci/vale/styles/config/vocabularies/nat/accept.txtfile are OK.Misc. - All code should be licensed under the Apache License 2.0, and should contain an Apache License 2.0 header
comment at the top of each file.
- Confirm that copyright years are up-to date whenever a file is changed.
Files:
src/nat/tool/mcp/mcp_client_base.py
src/nat/**/*
⚙️ CodeRabbit configuration file
This directory contains the core functionality of the toolkit. Changes should prioritize backward compatibility.
Files:
src/nat/tool/mcp/mcp_client_base.py
🔇 Additional comments (5)
src/nat/tool/mcp/mcp_client_base.py (5)
117-163: LGTM! Well-designed base class with proper async lifecycle management.The
MCPBaseClientbase class provides a clean abstraction for different transport types with proper async context manager support, session management, and exit stack handling. The implementation follows best practices for async resource management.
225-255: LGTM! SSE client implementation maintains backward compatibility.The
MCPSSEClientproperly extends the base class and maintains the existing SSE transport functionality. Good use of the@overridedecorator and consistent server_name property implementation.
257-301: LGTM! Stdio client implementation addresses security concerns.The
MCPStdioClientimplementation properly addresses the security concern about exposing sensitive environment variables in theserver_nameproperty by only including the command. The implementation correctly usesStdioServerParametersfor subprocess management.
303-333: LGTM! Streamable-HTTP client implementation is clean and consistent.The
MCPStreamableHTTPClientfollows the same pattern as other transport implementations and properly integrates with the MCP library's streamable-http transport.
383-405: LGTM! Proper error handling in MCPToolClient.acall method.The method properly aggregates text content from results and raises
RuntimeErrorwhenresult.isErroris true, providing clear error feedback.
✅ Actions performedReviews paused. |
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
2f7f1a7 to
93caf56
Compare
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Will Killian <[email protected]>
mpenn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good, just a few comments to address.
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
|
/merge |
1 similar comment
|
/merge |
Description
Closes #304 #314
This PR enhances MCP (Model Context Protocol) support by refactoring the client architecture and adding support for multiple transport types including stdio and streamable-http. SSE transport mechanism has been maintained for backwards compat but the default transport mechanism has been changed to streamable-http making this a
BREAKINGchange.MCP Server Changes:
MCP Client Changes:
mcp_clientto allow onboarding all tools dynamically from a MCP server (see Cursor Style MCP server config below). The earlier formatmcp_tool_wrapperis still available and can be used as before for sse and streamable-http. Howevermcp_tool_wrapperis NOT recommended for stdio if there are multiple tools available from the same server.[Experimental] Cursor Style MCP server config:
mcp_clientfunction has been added. This function connects to the server, discovers tools and adds them as dynamic functions (mcp_single_tool) to the NAT workflow builder.Changes to examples:
sseurl to themcp/streamable-http URLexamples/MCP/simple_calculator_mcp/configs/config-mcp-date-stdio.ymlDependency Changes
Additional Changes
These changes are not directly to MCP but were needed for handling new syntax:
Steps for testing streamable-http:
Steps for testing
stdio:Pending items:
stdio with fastapi is not working at the moment. To repro use steps 1&2 from above but instead of doing an nat run do a nat serve and curl the input:
Fastapi->mcp_client->mcp_server(stdio) is showing that the child_catcher is disabled. We need to undertand why that is happening.
By Submitting this PR I confirm:
Summary by CodeRabbit
New Features
Documentation
Chores
Tests