Skip to content
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

feat: add anthropic mcp endpoint #5148

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

feat: add anthropic mcp endpoint #5148

wants to merge 25 commits into from

Conversation

phact
Copy link
Collaborator

@phact phact commented Dec 7, 2024

Anthropic released model context protocol a few days ago https://modelcontextprotocol.io/introduction

It's an open protocol for LLM applications (first one being the claude desktop ui) and external data sources and tools. In this integration, any flow in langflow becomes a tool in mcp and can be accessed directly by claude from claude desktop. Here's a screenshot from mcp inspector https://github.com/modelcontextprotocol/inspector

image

This pull request introduces the integration of the mcp module into the project. The changes include adding the mcp dependency, updating the API routing to include mcp, and implementing the mcp server functionality.

Key changes include:

Dependency Addition

  • Added mcp version 0.9.1 to the project dependencies in pyproject.toml.

API Routing Updates

  • Included mcp_router in the API router configurations in src/backend/base/langflow/api/router.py. [1] [2]
  • Imported and added mcp_router to the list of routers in src/backend/base/langflow/api/v1/__init__.py. [1] [2]

MCP Server Implementation

  • Created src/backend/base/langflow/api/v1/mcp.py to implement the mcp server with endpoints for handling tool listings, tool execution requests, and server-sent events (SSE).

MCP Client components

Also includes two new components for mcp clients sse and stdio

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Dec 7, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 7, 2024
Copy link

codspeed-hq bot commented Dec 7, 2024

CodSpeed Performance Report

Merging #5148 will not alter performance

Comparing mcp (2167e78) with main (a97c29f)

Summary

✅ 15 untouched benchmarks

@phact phact self-assigned this Dec 16, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 17, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 17, 2024
Comment on lines 111 to 132
for flow in flows:
if flow.user_id is None:
continue
# Generate unique name by appending _N if needed
base_name = flow.name
if base_name in name_count:
name_count[base_name] += 1
unique_name = f"{base_name}_{name_count[base_name]}"
else:
name_count[base_name] = 0
unique_name = base_name

tool = types.Tool(
name=str(flow.id), # Use flow.id instead of name
description=f"{unique_name}: {flow.description}"
if flow.description
else f"Tool generated from flow: {unique_name}",
inputSchema=json_schema_from_flow(flow),
)
tools.append(tool)

return tools
Copy link
Contributor

Choose a reason for hiding this comment

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

Names are unique per user. What if we added the id like name ({id})?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually ended up using the flow.id as the unique name so let's take out the _N stuff

Copy link
Contributor

Choose a reason for hiding this comment

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

But it would be good for the user to see the name, wouldn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The name of the flow? It's in the description. It looks like this:

image

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2024
@phact
Copy link
Collaborator Author

phact commented Dec 18, 2024

hitting modelcontextprotocol/python-sdk#103 for progress notifications so we need to disable them for now

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 19, 2024
@phact
Copy link
Collaborator Author

phact commented Dec 19, 2024

gotta redo the Tools on the components because #5084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants