Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
386fa99
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
945d3ff
clean up v2/mcp
HzaRashid Nov 27, 2025
9afc891
ruff (mcp)
HzaRashid Nov 27, 2025
98235f4
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
5d4a5f3
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
07909c4
fix mcp auto install tests
HzaRashid Nov 28, 2025
9295f06
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 28, 2025
9583ee7
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Nov 28, 2025
c3e0f0a
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
6a7c5e9
clean up v2/mcp
HzaRashid Nov 27, 2025
c73c033
ruff (mcp)
HzaRashid Nov 27, 2025
d25e2fb
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
d9c5a2b
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
dcc4a23
fix mcp auto install tests
HzaRashid Nov 28, 2025
1a515c2
misc
HzaRashid Nov 28, 2025
592923c
refactor mcp and mcp_projects
HzaRashid Nov 28, 2025
a6ac93a
fix mcp ctx mgmt in main.py
HzaRashid Nov 29, 2025
023b007
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
e44bf85
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
953e260
return noop response in streamable dispatcher
HzaRashid Nov 30, 2025
dca3f83
docs
HzaRashid Nov 30, 2025
fb77727
docs (main.py)
HzaRashid Nov 30, 2025
4228eb1
use classes for http mgrs
HzaRashid Dec 1, 2025
cf8cd4c
use asyncio tg for mcp projects session mgrs mgmt
HzaRashid Dec 1, 2025
e3b717f
docs
HzaRashid Dec 1, 2025
edbdf19
clean up project tasks class
HzaRashid Dec 1, 2025
bc5df6a
recover original behaviour for /{project_id} endpoint
HzaRashid Dec 1, 2025
1554c3a
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
6f873b6
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 1, 2025
49db8c5
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Dec 1, 2025
e44d9b9
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 1, 2025
e69f395
fix for backwards compatilibility for sse requests
HimavarshaVS Dec 1, 2025
dbe619b
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
8b599f2
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
625499d
clean up v2/mcp
HzaRashid Nov 27, 2025
3edd952
ruff (mcp)
HzaRashid Nov 27, 2025
716207f
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
1b7146b
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
88d1f2a
fix mcp auto install tests
HzaRashid Nov 28, 2025
cb3d1a6
misc
HzaRashid Nov 28, 2025
78faaf7
refactor mcp and mcp_projects
HzaRashid Nov 28, 2025
6baa7dd
fix mcp ctx mgmt in main.py
HzaRashid Nov 29, 2025
fc2e11b
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
d93ccf7
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
c261a29
return noop response in streamable dispatcher
HzaRashid Nov 30, 2025
66e449e
docs
HzaRashid Nov 30, 2025
a9ecfc3
docs (main.py)
HzaRashid Nov 30, 2025
6624dc0
use classes for http mgrs
HzaRashid Dec 1, 2025
c1a7618
use asyncio tg for mcp projects session mgrs mgmt
HzaRashid Dec 1, 2025
e96266a
docs
HzaRashid Dec 1, 2025
719b7e6
clean up project tasks class
HzaRashid Dec 1, 2025
84e48e9
recover original behaviour for /{project_id} endpoint
HzaRashid Dec 1, 2025
565ae37
implement asyncio.TaskGroup backport for python 3.10
HzaRashid Dec 1, 2025
c8a9352
remove unused const
HzaRashid Dec 1, 2025
9cfeca4
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
981f85e
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 1, 2025
6fb668f
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Dec 1, 2025
e310825
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 2, 2025
2941572
replace asyncio with anyio
HzaRashid Dec 2, 2025
f7e574f
touch ups
HzaRashid Dec 2, 2025
7402173
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 2, 2025
f892748
Merge branch 'main' into feat/http-stream-mcp
HimavarshaVS Dec 3, 2025
c0ebc4f
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 3, 2025
d0f0489
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 3, 2025
f2146eb
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 3, 2025
4c2d301
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 3, 2025
bbc3584
handle shutdown properly
HimavarshaVS Dec 3, 2025
71513e4
Merge branch 'main' into feat/http-stream-mcp
HimavarshaVS Dec 3, 2025
40df8e2
Update test_mcp_projects.py
erichare Dec 3, 2025
d606968
Fix mypy errors
erichare Dec 3, 2025
f06a9ed
rollback start manager changes
HimavarshaVS Dec 3, 2025
04914c5
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 3, 2025
75ade96
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
ae02720
return noop response in streamable dispatcher
HzaRashid Nov 30, 2025
b91ace6
docs
HzaRashid Nov 30, 2025
06d40b5
docs (main.py)
HzaRashid Nov 30, 2025
4a4920e
use classes for http mgrs
HzaRashid Dec 1, 2025
379a487
use asyncio tg for mcp projects session mgrs mgmt
HzaRashid Dec 1, 2025
ca4fe98
docs
HzaRashid Dec 1, 2025
c05de69
clean up project tasks class
HzaRashid Dec 1, 2025
d1c39e4
recover original behaviour for /{project_id} endpoint
HzaRashid Dec 1, 2025
f5441c0
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
1a1b2ce
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 1, 2025
60da51d
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Dec 1, 2025
64b35d8
fix for backwards compatilibility for sse requests
HimavarshaVS Dec 1, 2025
8117663
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
27f8ab5
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
2cc0fec
clean up v2/mcp
HzaRashid Nov 27, 2025
23c6046
ruff (mcp)
HzaRashid Nov 27, 2025
b37b6fe
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
e49e5fe
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
144bd01
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
7a83a76
clean up v2/mcp
HzaRashid Nov 27, 2025
3a493b1
ruff (mcp)
HzaRashid Nov 27, 2025
c2ee46b
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
04bd598
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
3966682
fix mcp auto install tests
HzaRashid Nov 28, 2025
3b59b7e
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 28, 2025
dfd52ff
refactor mcp and mcp_projects
HzaRashid Nov 28, 2025
bbc5daf
fix mcp ctx mgmt in main.py
HzaRashid Nov 29, 2025
77d0804
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
2a7edeb
fix mcp auto install tests
HzaRashid Nov 28, 2025
d47c259
misc
HzaRashid Nov 28, 2025
873916f
refactor mcp and mcp_projects
HzaRashid Nov 28, 2025
e4059fc
fix mcp ctx mgmt in main.py
HzaRashid Nov 29, 2025
07a8666
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
6a9a3b2
use global exit stack mcp project servers
HzaRashid Nov 29, 2025
aca1ece
return noop response in streamable dispatcher
HzaRashid Nov 30, 2025
166d974
docs
HzaRashid Nov 30, 2025
c76cfb1
docs (main.py)
HzaRashid Nov 30, 2025
0f0257d
use classes for http mgrs
HzaRashid Dec 1, 2025
3d7ff92
use asyncio tg for mcp projects session mgrs mgmt
HzaRashid Dec 1, 2025
323258f
docs
HzaRashid Dec 1, 2025
6add199
clean up project tasks class
HzaRashid Dec 1, 2025
58d621f
recover original behaviour for /{project_id} endpoint
HzaRashid Dec 1, 2025
c52fbd5
implement asyncio.TaskGroup backport for python 3.10
HzaRashid Dec 1, 2025
c5c8fcd
remove unused const
HzaRashid Dec 1, 2025
13deb16
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 1, 2025
2321075
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 1, 2025
eefbc02
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Dec 1, 2025
78885b6
replace asyncio with anyio
HzaRashid Dec 2, 2025
52142dd
touch ups
HzaRashid Dec 2, 2025
81c847d
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 3, 2025
924f59a
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Dec 3, 2025
a0663e5
handle shutdown properly
HimavarshaVS Dec 3, 2025
040ca64
rollback start manager changes
HimavarshaVS Dec 3, 2025
c206c0a
Update test_mcp_projects.py
erichare Dec 3, 2025
8935e53
Fix mypy errors
erichare Dec 3, 2025
1694e3b
graceful termination of mcp projects /streamable endpoint
HzaRashid Dec 3, 2025
5654ceb
delete removed file
HzaRashid Dec 3, 2025
9f7014d
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 3, 2025
6d75e3b
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] Nov 28, 2025
fad1b43
migrate mcp transport to http streamable
HzaRashid Nov 26, 2025
ca2941f
clean up v2/mcp
HzaRashid Nov 27, 2025
44ed389
ruff (mcp)
HzaRashid Nov 27, 2025
8b191e0
add back ensure_session_mgr_running handler
HzaRashid Nov 27, 2025
245e3c9
refactor mcp server and set default mcp settings on project creation
HzaRashid Nov 28, 2025
bb5faba
misc
HzaRashid Nov 28, 2025
02d5319
Merge branch 'main' into feat/http-stream-mcp
HimavarshaVS Dec 4, 2025
44b185f
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 4, 2025
2aa111e
Merge branch 'feat/http-stream-mcp' of https://github.com/langflow-ai…
HimavarshaVS Dec 4, 2025
3b4c4bd
build component index
HimavarshaVS Dec 4, 2025
173a2d1
Merge remote-tracking branch 'origin' into feat/http-stream-mcp
HimavarshaVS Dec 4, 2025
3d3def6
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 4, 2025
aea5f78
[autofix.ci] apply automated fixes (attempt 3/3)
autofix-ci[bot] Dec 1, 2025
510cc65
add health check endpoint for streamable
HzaRashid Dec 4, 2025
99705e0
sync starter projects with main
HzaRashid Dec 4, 2025
1c2f734
remove unused delete method from sse transport
HzaRashid Dec 4, 2025
eea4849
Merge remote-tracking branch 'upstream/main' into feat/http-stream-mcp
HzaRashid Dec 5, 2025
269dd1e
get user-level files in handle_list_resources
HzaRashid Dec 7, 2025
0c709b3
Merge remote-tracking branch 'upstream/main' into feat/http-stream-mcp
HzaRashid Dec 8, 2025
b943b6e
add backwards compat tests for sse transport
HzaRashid Dec 8, 2025
d0925df
merge with main
HzaRashid Dec 8, 2025
d458fc2
fix frontend tests
HzaRashid Dec 8, 2025
b973b41
fix lfx test
HzaRashid Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate mcp transport to http streamable
fix tests

refactor mcp and mcp_projects

backwards compat with SSE transport

provide streamable http option for json mcp config

remove streamable_http mgmt and update tests
  • Loading branch information
HzaRashid committed Dec 3, 2025
commit 27f8ab5958d316b1061ab08f81e65a7e4f2d7622
3 changes: 2 additions & 1 deletion src/backend/base/langflow/api/utils/mcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from langflow.api.utils.mcp.config_utils import (
auto_configure_starter_projects_mcp,
get_composer_streamable_http_url,
get_project_sse_url,
get_project_streamable_http_url,
get_project_sse_url,
get_url_by_os,
)

__all__ = [
"auto_configure_starter_projects_mcp",
"get_composer_streamable_http_url",
"get_project_streamable_http_url",
"get_project_sse_url",
"get_project_streamable_http_url",
"get_url_by_os",
Expand Down
100 changes: 7 additions & 93 deletions src/backend/base/langflow/api/v1/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,8 @@ async def handle_global_call_tool(name: str, arguments: dict) -> list[types.Text
return await handle_call_tool(name, arguments, server)


########################################################
# The transports handle the full ASGI response.
# FastAPI still expects the endpoint to return
# a Response, while Starlette's middleware
# stream validation panics when
# a http.response.start message
# is encountered twice within the same stream.
# This class nullifies the redundant
# response to end streams gracefully.
########################################################
class ResponseNoOp(Response):
async def __call__(self, scope, receive, send) -> None: # noqa: ARG002
return

sse = SseServerTransport("/api/v1/mcp/")
streamable_http_manager = StreamableHTTPSessionManager(server)

def find_validation_error(exc):
"""Searches for a pydantic.ValidationError in the exception chain."""
Expand Down Expand Up @@ -148,73 +136,6 @@ async def handle_messages(request: Request):
raise HTTPException(status_code=500, detail=f"Internal server error: {e}") from e


################################################################################
# Streamable HTTP Transport
################################################################################
class StreamableHTTP:
def __init__(self):
self.session_manager: StreamableHTTPSessionManager | None = None
self._context_stack: AsyncExitStack | None = None
self._started = False
self._start_stop_lock = asyncio.Lock()

async def start(self, *, stateless: bool = True) -> None:
"""Create and enter the Streamable HTTP session manager lifecycle."""
async with self._start_stop_lock:
if self._started:
await logger.adebug("Streamable HTTP session manager already running; skipping start")
return

manager = StreamableHTTPSessionManager(server, stateless=stateless)
stack = AsyncExitStack()
try:
await stack.enter_async_context(manager.run())
except Exception:
await stack.aclose()
raise

self.session_manager = manager
self._context_stack = stack
self._started = True
await logger.adebug("Streamable HTTP session manager started")

def get_manager(self) -> StreamableHTTPSessionManager:
"""Fetch the active Streamable HTTP session manager or raise if it is unavailable."""
if not self._started or self.session_manager is None:
raise HTTPException(status_code=503, detail="MCP Streamable HTTP transport is not initialized")
return self.session_manager

async def stop(self) -> None:
"""Close the Streamable HTTP session manager context."""
async with self._start_stop_lock:
if not self._started:
return

try:
if self._context_stack is not None:
await self._context_stack.aclose()
finally:
self._context_stack = None
self.session_manager = None
self._started = False
await logger.adebug("Streamable HTTP session manager stopped")


_streamable_http = StreamableHTTP()


async def start_streamable_http_manager(stateless: bool = True) -> None: # noqa: FBT001, FBT002
await _streamable_http.start(stateless=stateless)


def get_streamable_http_manager() -> StreamableHTTPSessionManager:
return _streamable_http.get_manager()


async def stop_streamable_http_manager() -> None:
await _streamable_http.stop()


async def _dispatch_streamable_http(
request: Request,
current_user: CurrentActiveMCPUser,
Expand All @@ -229,8 +150,7 @@ async def _dispatch_streamable_http(

context_token = current_user_ctx.set(current_user)
try:
manager = get_streamable_http_manager()
await manager.handle_request(request.scope, request.receive, request._send) # noqa: SLF001
await streamable_http_manager.handle_request(request.scope, request.receive, request._send) # noqa: SLF001
except HTTPException:
raise
except Exception as exc:
Expand All @@ -239,17 +159,11 @@ async def _dispatch_streamable_http(
finally:
current_user_ctx.reset(context_token)

return ResponseNoOp()


streamable_http_route_config = {
"methods": ["GET", "POST", "DELETE"],
"response_class": ResponseNoOp,
}

return Response()

@router.api_route("/streamable", **streamable_http_route_config)
@router.api_route("/streamable/", **streamable_http_route_config)
streamable_http_methods = ["GET", "POST", "DELETE"]
@router.api_route("/streamable", methods=streamable_http_methods)
@router.api_route("/streamable/", methods=streamable_http_methods)
async def handle_streamable_http(request: Request, current_user: CurrentActiveMCPUser):
"""Streamable HTTP endpoint for MCP clients that support the new transport."""
return await _dispatch_streamable_http(request, current_user)
Loading