MCP 模块¶
服务器工厂¶
toolregistry_server.mcp.create_mcp_server ¶
Create an MCP server from a RouteTable.
This is an alias for route_table_to_mcp_server() for convenience.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_table
|
RouteTable
|
The RouteTable to expose. |
required |
name
|
str
|
Server name for MCP identification. |
'ToolRegistry-Server'
|
Returns:
| Type | Description |
|---|---|
Server
|
A configured MCP Server instance. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If MCP SDK is not installed. |
Source code in src/toolregistry_server/mcp/__init__.py
适配器¶
toolregistry_server.mcp.adapter ¶
MCP adapter that creates an MCP low-level Server from a RouteTable.
This module bridges RouteTable and the MCP Python SDK's low-level Server API, ensuring tool enable/disable state is always read directly from the route table at request time (no drift).
route_table_to_mcp_server ¶
Create an MCP low-level Server from a RouteTable.
Registers list_tools and call_tool handlers that read directly from the route table, ensuring enable/disable state is always in sync (no drift).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_table
|
RouteTable
|
The RouteTable instance to expose as MCP tools. |
required |
name
|
str
|
Server name for MCP identification. |
'ToolRegistry-Server'
|
Returns:
| Type | Description |
|---|---|
Server
|
A configured mcp.server.lowlevel.Server instance. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If MCP SDK is not installed. |
Source code in src/toolregistry_server/mcp/adapter.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
传输运行器¶
toolregistry_server.mcp.server ¶
MCP server runner functions.
This module provides functions to run an MCP server with different transports: - stdio: Standard input/output transport - SSE: Server-Sent Events over HTTP - streamable-http: Streamable HTTP transport
The server should be created using route_table_to_mcp_server() from adapter.py, then run using the functions in this module.
Example
run_sse
async
¶
Run an MCP server over SSE (Server-Sent Events) transport.
This transport is suitable for web-based MCP clients that connect via HTTP and receive events through SSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The MCP Server instance to run. |
required |
host
|
str
|
Host address to bind to. |
'127.0.0.1'
|
port
|
int
|
Port number to bind to. |
8000
|
path
|
str
|
URL path for the SSE endpoint. |
'/sse'
|
Source code in src/toolregistry_server/mcp/server.py
run_stdio
async
¶
Run an MCP server over stdio transport.
This is the simplest transport, suitable for local tool execution where the MCP client spawns the server as a subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The MCP Server instance to run. |
required |
Source code in src/toolregistry_server/mcp/server.py
run_streamable_http
async
¶
run_streamable_http(server: Server, host: str = '127.0.0.1', port: int = 8000, path: str = '/mcp') -> None
Run an MCP server over streamable HTTP transport.
This is the recommended HTTP transport for production use, supporting bidirectional streaming over HTTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The MCP Server instance to run. |
required |
host
|
str
|
Host address to bind to. |
'127.0.0.1'
|
port
|
int
|
Port number to bind to. |
8000
|
path
|
str
|
URL path for the MCP endpoint. |
'/mcp'
|