-
Notifications
You must be signed in to change notification settings - Fork 8
[PR-1092][PR-1093] Optimised MCPModelClass and supports for Sdtio MCP servers #872
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR introduces a new bridge class for integrating Node.js MCP (Model Context Protocol) servers with Python FastMCP servers within the Clarifai platform. The implementation automatically discovers and registers tools from Node.js MCP servers, making them available to MCP clients through a Python interface.
Key Changes:
- Adds
NodeJSMCPModelClassthat extendsMCPModelClassto bridge Node.js and Python MCP servers - Implements
NodeMCPClientfor communicating with Node.js MCP servers via stdio - Provides automatic tool discovery and registration with dynamic function generation
Comments suppressed due to low confidence (2)
clarifai/runners/models/nodejs_mcp_class.py:59
- 'except' clause does nothing but pass and there is no explanatory comment.
except Exception:
clarifai/runners/models/nodejs_mcp_class.py:63
- 'except' clause does nothing but pass and there is no explanatory comment.
except Exception:
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.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 25 comments.
Comments suppressed due to low confidence (1)
clarifai/runners/models/mcp_class.py:258
- 'except' clause does nothing but pass and there is no explanatory comment.
except Exception:
|
@luv-bansal I've opened a new pull request, #873, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@luv-bansal I've opened a new pull request, #874, to work on those changes. Once the pull request is ready, I'll request review from you. |
Minimum allowed line rate is |
Summary
This PR introduces a major architectural improvement to the MCPModelClass by implementing persistent session management and adding support for bridging stdio MCP servers to Python FastMCP.
Problem
The previous
MCPModelClassimplementation suffered from significant performance overhead:asyncio.run()async with self.clientFor opensourced Sdtio MCP servers, there was no built-in support in clarifai, the only way to host MCP server with Clarifai is by implementing own custom server with implementing all tools.
Solution
1. Refactored
MCPModelClasswith Persistent Sessionsload_model()and reused for all subsequent requestsasyncio.run_coroutine_threadsafe()shutdown()method for clean resource cleanup2. New
StdioMCPModelClassfor stdio MCP Serversnpx -y @modelcontextprotocol/server-github) starts once and stays runningClientSessionto the stdio server with double-checked locking for thread safetyconfig.yamlwith support for environment variables and secrets