@@ -60,19 +60,23 @@ async def list_tools_and_schemas(command, url, tool_name=None, client_type='sse'
60
60
args = []
61
61
from aiq .tool .mcp .mcp_client import MCPSSEClient
62
62
from aiq .tool .mcp .mcp_client import MCPStdioClient
63
+ from aiq .tool .mcp .mcp_client import MCPStreamableHTTPClient
63
64
64
65
try :
65
66
if client_type == 'stdio' :
66
67
client = MCPStdioClient (command = command , args = args , env = env )
67
- else :
68
+ elif client_type == 'streamable-http' :
69
+ client = MCPStreamableHTTPClient (url = url )
70
+ else : # sse
68
71
client = MCPSSEClient (url = url )
69
72
70
- if tool_name :
71
- tool = await client .get_tool (tool_name )
72
- return [format_tool (tool )]
73
- else :
74
- tools = await client .get_tools ()
75
- return [format_tool (tool ) for tool in tools .values ()]
73
+ async with client :
74
+ if tool_name :
75
+ tool = await client .get_tool (tool_name )
76
+ return [format_tool (tool )]
77
+ else :
78
+ tools = await client .get_tools ()
79
+ return [format_tool (tool ) for tool in tools .values ()]
76
80
except Exception as e :
77
81
click .echo (f"[ERROR] Failed to fetch tools via MCP client: { e } " , err = True )
78
82
return []
@@ -85,6 +89,7 @@ async def list_tools_direct(command, url, tool_name=None, client_type='sse', arg
85
89
from mcp .client .sse import sse_client
86
90
from mcp .client .stdio import StdioServerParameters
87
91
from mcp .client .stdio import stdio_client
92
+ from mcp .client .streamable_http import streamablehttp_client
88
93
89
94
try :
90
95
if client_type == 'stdio' :
@@ -93,7 +98,13 @@ def get_stdio_client():
93
98
return stdio_client (server = StdioServerParameters (command = command , args = args , env = env ))
94
99
95
100
client = get_stdio_client
96
- else :
101
+ elif client_type == 'streamable-http' :
102
+
103
+ def get_streamable_http_client ():
104
+ return streamablehttp_client (url = url )
105
+
106
+ client = get_streamable_http_client
107
+ else : # sse
97
108
98
109
def get_sse_client ():
99
110
return sse_client (url = url )
@@ -125,9 +136,9 @@ def get_sse_client():
125
136
@click .option ('--url' ,
126
137
default = 'http://localhost:9901/sse' ,
127
138
show_default = True ,
128
- help = 'For SSE: MCP server URL (e.g. http://localhost:8080/sse)' )
139
+ help = 'For SSE/StreamableHTTP : MCP server URL (e.g. http://localhost:8080/sse)' )
129
140
@click .option ('--client-type' ,
130
- type = click .Choice (['sse' , 'stdio' ]),
141
+ type = click .Choice (['sse' , 'stdio' , 'streamable-http' ]),
131
142
default = 'sse' ,
132
143
show_default = True ,
133
144
help = 'Type of client to use' )
@@ -151,12 +162,14 @@ def list_mcp(ctx, direct, url, client_type, command, args, env, tool, detail, js
151
162
click .echo ("[ERROR] --command is required when using stdio client type" , err = True )
152
163
return
153
164
154
- if client_type == 'sse' :
165
+ if client_type in [ 'sse' , 'streamable-http' ] :
155
166
if not url :
156
- click .echo ("[ERROR] --url is required when using sse client type" , err = True )
167
+ click .echo ("[ERROR] --url is required when using sse or streamable-http client type" , err = True )
157
168
return
158
169
if command or args or env :
159
- click .echo ("[ERROR] --command, --args, and --env are not allowed when using sse client type" , err = True )
170
+ click .echo (
171
+ "[ERROR] --command, --args, and --env are not allowed when using sse or streamable-http client type" ,
172
+ err = True )
160
173
return
161
174
162
175
stdio_args = args .split () if args else []
0 commit comments