Skip to content

Add MCP (Model Control Protocol) Client Support #84

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

Merged
merged 10 commits into from
Mar 28, 2025
Merged

Add MCP (Model Control Protocol) Client Support #84

merged 10 commits into from
Mar 28, 2025

Conversation

wendy-aw
Copy link
Contributor

Background

Model Context Protocol provides a standardized way for LLMs to use external tools. This PR adds support for connecting to MCP servers and letting models use tools working with both Anthropic, OpenAI and Gemini models.

Changes

  • Add a complete MCP client implementation for connecting to both SSE and stdio MCP servers
  • Add comprehensive testing suite with live API and server connection tests
  • Integrate with current Anthropic, OpenAI and Gemini API handling

How to Use MCPClient

from defog.llm.utils_mcp import initialize_mcp_client


# Initialize with config file
client = await initialize_mcp_client("path/to/config.json",
"claude-3-haiku")

# Chat with tool usage
response, tool_outputs = await client.mcp_chat("Use tools to help me
   multiply 12 and 34")

# Clean up
await client.cleanup()

@wendy-aw wendy-aw requested a review from rishsriv March 27, 2025 16:35
Copy link
Member

@rishsriv rishsriv left a comment

Choose a reason for hiding this comment

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

Thank you! This is awesome, and I'm super excited to use it in more of our apps!

Just 1 request – looks good to merge after that is changed!

print("All MCP server connections closed.")


async def initialize_mcp_client(config_path, model):
Copy link
Member

Choose a reason for hiding this comment

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

Instead of the first input param being a config_path, let's rename it config – where the type can either be dict or a string (filepath)

With this, calling this function from other apps becomes significantly more flexible. We can either pass a dict (which can be programmatically generated) to the function, or we can pass a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok done! Lemme know if this is ok!

Copy link
Member

@rishsriv rishsriv left a comment

Choose a reason for hiding this comment

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

Thank you!

@rishsriv rishsriv merged commit 8898e70 into main Mar 28, 2025
2 checks passed
@rishsriv rishsriv deleted the wendy/mcp branch March 28, 2025 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants