Skip to content

Extend the MCP tool wrapper to work with stdio #307

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

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

AnuradhaKaruppiah
Copy link
Contributor

@AnuradhaKaruppiah AnuradhaKaruppiah commented May 21, 2025

Description

Closes #304

This PR extends the MCP tool client usage via stdio using a format similar to cursor/claude-desktop i.e. by providing {tool_name, command, args, env}

class MCPToolConfig(FunctionBaseConfig, name="mcp_tool_wrapper"):
>>>>>>>>>>>>>>>>> SNIP >>>>>>>>>>>>>>
    mcp_tool_name: str = Field(description="The name of the tool served by the MCP Server that you want to use")
    client_type: str = Field(default="sse", description="The type of client to use ('sse' or 'stdio')")
    command: str | None = Field(default=None, description="The command to run for stdio mode (e.g. 'docker' or 'python')")
    args: list[str] | None = Field(default=None, description="Additional arguments for the stdio command")
    env: dict[str, str] | None = Field(default=None, description="Environment variables to set for the stdio process")
>>>>>>>>>>>>>>>>> SNIP >>>>>>>>>>>>>>

The MCP stdio_client connects to a server by spawning a process and communicating with it over stdin/stdout.

Note: MCP SSE client is the recommended way for accessing remote tools and remains the default. The MCP stdio client is available for rapid-development/easy prototyping.

A. Sample usage with github MCP service

  1. CLI Sample:
aiq info mcp --client-type stdio --command docker --args "run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server" --env "GITHUB_PERSONAL_ACCESS_TOKEN=your_github_token"

Sample Output:

GitHub MCP Server running on stdio
add_issue_comment
add_pull_request_review_comment
create_branch
create_issue
create_or_update_file
create_pull_request
create_pull_request_review
create_repository
>>>>>>>>>>>>>>>>>> SNIP >>>>>>>>>>>>>>>>>>>>>

B. Sample usage with datetime MCP service
0. Install mcp_server_time package in your venv:

uv pip install mcp-server-time
  1. CLI Sample:
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
  1. Sample Client (new simple_calculator config file, config-mcp-date-stdio.yml) -
aiq run --config_file examples/simple_calculator/configs/config-mcp-date-stdio.yml --input "Is the product of 2 * 4 greater than the current hour of the day?" 

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

@AnuradhaKaruppiah AnuradhaKaruppiah self-assigned this May 21, 2025
@AnuradhaKaruppiah AnuradhaKaruppiah added improvement Improvement to existing functionality non-breaking Non-breaking change labels May 21, 2025
@AnuradhaKaruppiah AnuradhaKaruppiah marked this pull request as draft May 21, 2025 01:53
@AnuradhaKaruppiah AnuradhaKaruppiah marked this pull request as ready for review May 22, 2025 18:26
@AnuradhaKaruppiah AnuradhaKaruppiah requested a review from Copilot May 22, 2025 19:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the MCP tool wrapper to support stdio mode in addition to the existing SSE mode. Key changes include:

  • Updating the MCPToolConfig schema and client builder to support stdio parameters (command, args, env).
  • Refactoring the MCP client structure by introducing a base client and a dedicated MCPStdioClient.
  • Enhancing CLI commands, tests, and documentation to demonstrate and verify the stdio mode usage.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/aiq/tools/test_mcp.py Added tests for both SSE and stdio client usage, and for the MCPBuilder functionality.
src/aiq/tool/mcp/mcp_tool.py Updated configuration handling to support stdio mode with new parameters and validation.
src/aiq/tool/mcp/mcp_client.py Refactored client architecture by introducing a base client and a dedicated MCPStdioClient, and updated MCPBuilder accordingly.
src/aiq/cli/commands/info/list_mcp.py Enhanced CLI options to support stdio mode configuration including command, args, and environment variables.
examples/simple_calculator/src/aiq_simple_calculator/configs/config-mcp-date-stdio.yml Added sample config demonstrating usage of MCP stdio mode.
docs/source/workflows/mcp/mcp-client.md Updated documentation to include examples and explanation for both SSE and stdio mode configurations.

Copy link
Collaborator

@mdemoret-nv mdemoret-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could improve design a bit now that we have two client types by removing MCPBuilder

@AnuradhaKaruppiah AnuradhaKaruppiah force-pushed the ak-mcp-tool-stdio branch 2 times, most recently from 0eea228 to 22f704a Compare May 22, 2025 21:34
AnuradhaKaruppiah and others added 18 commits May 27, 2025 21:18
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to existing functionality non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA]: Add support for stdio MCP Servers
2 participants