mcp¶
The MCP module provides integration with the Model Context Protocol (MCP) for Bridgic.
This module enables Bridgic to connect to and interact with MCP servers, allowing:
- Connection Management: Establish and manage connections to MCP servers via different transport protocols (stdio, streamable HTTP, etc.)
- Tool Integration: Use MCP tools as callable tools within Bridgic agentic systems
- Prompt Integration: Access and use prompts from MCP servers in Bridgic workflows
- Worker Integration: Execute MCP tools through Bridgic's worker system
Core Components
McpServerConnection: Abstract base class for MCP server connectionsMcpServerConnectionStdio: Connection implementation using stdio transportMcpServerConnectionStreamableHttp: Connection implementation using streamable HTTPMcpServerConnectionManager: Manager for multiple MCP connections with shared event loopMcpToolSpec: Tool specification for MCP toolsMcpToolSetBuilder: Builder for creating exclusive McpToolSpec instances for ReCentAutomaMcpToolWorker: Worker implementation for executing MCP toolsMcpPromptTemplate: Prompt template implementation for MCP prompts
Examples:
Create a connection to an MCP server using stdio transport and list available tools:
McpServerConnection ¶
Bases: ABC
The abstract base class for Connection to an MCP server.
This class is responsible for establishing a connection to an MCP server and providing a session to interact with the server. The connection can be established using different transport protocols, which depends on the specific implementation.
Methods:
| Name | Description |
|---|---|
connect | Establish a connection to an MCP server. |
get_mcp_client | Get a MCP client to interact with the server. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
request_timeout instance-attribute ¶
The timeout in seconds for the requests to the MCP server. Default is 30 seconds.
client_kwargs instance-attribute ¶
The keyword arguments to pass to the MCP client.
connect ¶
Establish a connection to the MCP server. Call this method once before using the connection.
If the connection is not registered in a specific manager explicitly, it will be registered in the default manager (manager_name="default-mcp-manager"). If the connection needs to be registered in a specific manager, the connect method should be called after the registration.
Notes
The event loop responsible for managing the session is determined at the time when connect() is called. Therefore, it is required to register the connection to the desired manager before calling connect(). Otherwise, the connection will be registered to the default manager. All registrations could not be changed later.
Examples:
Create a connection to a streamable HTTP MCP server and register it to a manager:
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
close ¶
Close the connection to the MCP server.
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
get_mcp_client ¶
abstractmethod Get an MCP client.
Returns:
| Type | Description |
|---|---|
_AsyncGeneratorContextManager[Any, None] | An async context manager for the MCP client transport. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
list_prompts ¶
list_prompts() -> List[McpPromptTemplate]
List the prompts from the MCP server.
Returns:
| Type | Description |
|---|---|
List[McpPromptTemplate] | The list of prompt template instances from the server. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
alist_prompts ¶
async alist_prompts() -> List[McpPromptTemplate]
Asynchronously list the prompts from the MCP server.
Returns:
| Type | Description |
|---|---|
List[McpPromptTemplate] | The list of prompt template instances from the server. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
get_prompt ¶
Synchronously get a prompt from the MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_name | str | The name of the prompt to retrieve. | required |
arguments | Optional[Dict[str, Any]] | Arguments to pass to the prompt. | None |
Returns:
| Type | Description |
|---|---|
GetPromptResult | The prompt result from the server. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
aget_prompt ¶
async Asynchronously get a prompt from the MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_name | str | The name of the prompt to retrieve. | required |
arguments | Optional[Dict[str, Any]] | Arguments to pass to the prompt. | None |
Returns:
| Type | Description |
|---|---|
GetPromptResult | The prompt result from the server. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
list_tools ¶
list_tools() -> List[McpToolSpec]
List the tools from the MCP server.
This method synchronously retrieves the list of tools available from the connected MCP server and wraps each tool in an McpToolSpec instance for use within the bridgic framework.
Returns:
| Type | Description |
|---|---|
List[McpToolSpec] | The list of tool specification instances from the server. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established and cannot be established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
alist_tools ¶
async alist_tools() -> List[McpToolSpec]
Asynchronously list the tools from the MCP server.
This method asynchronously retrieves the list of tools available from the connected MCP server and wraps each tool in an McpToolSpec instance for use within the bridgic framework.
Returns:
| Type | Description |
|---|---|
List[McpToolSpec] | The list of tool specification instances from the server. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established and cannot be established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
call_tool ¶
Synchronously call a tool on the MCP server.
This method synchronously invokes a tool on the connected MCP server with the specified arguments and returns the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name | str | The name of the tool to call. | required |
arguments | Optional[Dict[str, Any]] | The arguments to pass to the tool. If None, an empty dictionary will be used. | None |
Returns:
| Type | Description |
|---|---|
CallToolResult | The result of the tool call from the server, containing content and optionally structured content. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established and cannot be established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
acall_tool ¶
async Asynchronously call a tool on the MCP server.
This method asynchronously invokes a tool on the connected MCP server with the specified arguments and returns the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name | str | The name of the tool to call. | required |
arguments | Optional[Dict[str, Any]] | The arguments to pass to the tool. If None, an empty dictionary will be used. | None |
Returns:
| Type | Description |
|---|---|
CallToolResult | The result of the tool call from the server, containing content and optionally structured content. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established and cannot be established. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
McpServerConnectionStdio ¶
Bases: McpServerConnection
The connection to an MCP server using stdio.
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
encoding instance-attribute ¶
The encoding to use for the connection.
env instance-attribute ¶
The environment variables to use for the connection.
get_mcp_client ¶
Get an MCP client transport for stdio.
Returns:
| Type | Description |
|---|---|
_AsyncGeneratorContextManager[Any, None] | An async context manager for the stdio client transport. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
McpServerConnectionStreamableHttp ¶
Bases: McpServerConnection
The connection to an MCP server using streamable http.
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
http_client instance-attribute ¶
The HTTP client to use for the connection.
terminate_on_close instance-attribute ¶
Whether to terminate the session when the connection is closed.
get_mcp_client ¶
Get an MCP client transport for streamable http.
Returns:
| Type | Description |
|---|---|
_AsyncGeneratorContextManager[Any, None] | An async context manager for the streamable HTTP client transport. |
Source code in bridgic/protocols/mcp/_mcp_server_connection.py
McpServerConnectionManager ¶
Manages multiple MCP server connections, sharing a single thread and event loop.
This manager ensures that all MCP operations run in a dedicated thread with its own event loop, avoiding issues with cross-thread event loop usage.
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
get_instance ¶
classmethod get_instance(
manager_name: str = "default-mcp-manager",
) -> McpServerConnectionManager
Get a manager instance by name, creating it if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager_name | str | The name of the manager instance to retrieve. Defaults to "default-mcp-manager". | 'default-mcp-manager' |
Returns:
| Type | Description |
|---|---|
McpServerConnectionManager | The manager instance with the specified name. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
get_connection ¶
classmethod get_connection(
connection_name: str,
) -> Optional[McpServerConnection]
Get a connection by its name across all manager instances.
It first finds the manager that owns the connection using the class-level connection-to-manager mapping, then retrieves the connection from that manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_name | str | The name of the connection to retrieve. | required |
Returns:
| Type | Description |
|---|---|
Optional[McpServerConnection] | The connection with the specified name, or None if not found, the manager doesn't exist, or the connection has been garbage collected. |
Raises:
| Type | Description |
|---|---|
KeyError | If the connection is not found. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
register_connection ¶
register_connection(connection: McpServerConnection)
Register a connection into the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection | McpServerConnection | The connection to register. | required |
Raises:
| Type | Description |
|---|---|
McpServerConnectionError | If a connection with the same name is already registered. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
unregister_connection ¶
unregister_connection(connection: McpServerConnection)
Unregister a connection from the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection | McpServerConnection | The connection to unregister. | required |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
get_connection_by_name ¶
get_connection_by_name(
name: str,
) -> Optional[McpServerConnection]
Get a connection by its name from this manager instance.
This method looks up a registered connection by its name within this manager. If the connection has been garbage collected, weakref.WeakValueDictionary will automatically remove it and None will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the connection to retrieve. | required |
Returns:
| Type | Description |
|---|---|
Optional[McpServerConnection] | The connection with the specified name, or None if not found or has been garbage collected. |
Raises:
| Type | Description |
|---|---|
KeyError | If the connection is not found. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
run_sync ¶
Submit a coroutine to the manager's event loop and wait for the result synchronously.
This method blocks until the coroutine completes, suitable for use in synchronous contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro | Coroutine | The coroutine to run. | required |
timeout | Optional[float] | Timeout in seconds. If None, no timeout. | None |
Returns:
| Type | Description |
|---|---|
Any | The result of the coroutine execution. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the event loop is not running. |
TimeoutError | If the coroutine execution times out. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
run_async ¶
async Submit a coroutine to the manager's event loop and await its result in a non-blocking way.
This method submits the coroutine to the manager's dedicated event loop, and then waits for its completion in a non-blocking way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro | Coroutine | The coroutine to run. | required |
timeout | Optional[float] | Timeout in seconds. If None, no timeout. | None |
Returns:
| Type | Description |
|---|---|
Any | The result of the coroutine execution. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the event loop is not running. |
TimeoutError | If the coroutine execution times out. |
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
shutdown ¶
Shutdown the manager and stop the event loop.
This method also removes the manager from the class-level registry and cleans up all connection-to-manager mappings for connections registered with this manager.
Source code in bridgic/protocols/mcp/_mcp_server_connection_manager.py
McpToolSpec ¶
Bases: ToolSpec
A tool specification that represents an MCP tool from a connected MCP server.
This class provides a bridge between MCP tools and the Bridgic framework, allowing MCP tools to be used seamlessly within Bridgic agentic systems.
Source code in bridgic/protocols/mcp/_mcp_tool_spec.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 | |
tool_info instance-attribute ¶
The raw MCP tool definition from the server.
server_connection property ¶
server_connection: McpServerConnection
Get the server connection, loading it from the server connection manager if necessary.
This property implements lazy loading of the server connection. If the connection is not available (e.g., after deserialization), it will be retrieved from the server connection manager by its name.
Returns:
| Type | Description |
|---|---|
McpServerConnection | The server connection instance. |
Raises:
| Type | Description |
|---|---|
McpServerConnectionError | If the connection cannot be found in the manager. |
from_raw ¶
classmethod from_raw(
tool_name: str,
server_connection: Union[str, McpServerConnection],
) -> McpToolSpec
Create a McpToolSpec from a specified server connection and tool name.
Source code in bridgic/protocols/mcp/_mcp_tool_spec.py
to_tool ¶
to_tool() -> Tool
Transform this McpToolSpec to a Tool object used by LLM.
Returns:
| Type | Description |
|---|---|
Tool | A |
Source code in bridgic/protocols/mcp/_mcp_tool_spec.py
create_worker ¶
create_worker() -> Worker
Create a Worker from the information included in this McpToolSpec.
Returns:
| Type | Description |
|---|---|
Worker | A new |
Source code in bridgic/protocols/mcp/_mcp_tool_spec.py
McpToolSetBuilder ¶
Bases: ToolSetBuilder
A builder for creating exclusive McpToolSpec instances from a newly created MCP server connection.
This builder creates a new MCP server connection from scratch, ensuring that the connection is exclusive and not shared with other instances. This is important for stateful connections that should not be shared to different owners.
Examples:
Create a builder for stdio connection and build a tool set:
Create a builder for streamable HTTP connection and build a tool set:
Source code in bridgic/protocols/mcp/_mcp_tool_set_builder.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
stdio ¶
classmethod stdio(
command: str,
*,
args: Optional[List[str]] = None,
env: Optional[Dict[str, str]] = None,
encoding: Optional[str] = None,
request_timeout: Optional[int] = None,
tool_names: Optional[List[str]] = None
) -> McpToolSetBuilder
Create a builder for a stdio-based MCP server connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command | str | The command to use for the connection (e.g., "npx", "python"). | required |
args | Optional[List[str]] | The arguments to pass to the command. | None |
env | Optional[Dict[str, str]] | Environment variables to set for the process. | None |
encoding | Optional[str] | The encoding to use for the connection. Defaults to "utf-8". | None |
request_timeout | Optional[int] | The timeout in seconds for MCP requests. Default is 30 seconds. | None |
tool_names | Optional[List[str]] | Optional list of tool names to include. If None, all available tools will be included. | None |
Returns:
| Type | Description |
|---|---|
McpToolSetBuilder | A builder instance configured for stdio connection. |
Source code in bridgic/protocols/mcp/_mcp_tool_set_builder.py
streamable_http ¶
classmethod streamable_http(
url: str,
*,
http_client_config: Optional[HttpClientConfig] = None,
terminate_on_close: Optional[bool] = None,
request_timeout: Optional[int] = None,
tool_names: Optional[List[str]] = None
) -> McpToolSetBuilder
Create a builder for a streamable HTTP-based MCP server connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | The URL of the MCP server. | required |
http_client_config | Optional[HttpClientConfig] | Optional configuration for creating the HTTP client. If None, a default client will be created with MCP defaults. | None |
terminate_on_close | Optional[bool] | If True, send a DELETE request to terminate the session when the connection is closed. Defaults to True. | None |
request_timeout | Optional[int] | The timeout in seconds for MCP requests. Default is 30 seconds. | None |
tool_names | Optional[List[str]] | Optional list of tool names to include. If None, all available tools will be included. | None |
Returns:
| Type | Description |
|---|---|
McpToolSetBuilder | A builder instance configured for streamable HTTP connection. |
Source code in bridgic/protocols/mcp/_mcp_tool_set_builder.py
build ¶
build() -> ToolSetResponse
Build and return McpToolSpec instances from a newly created server connection.
This method creates a new connection on each call, ensuring that each call gets its own exclusive connection instance. The builder acts as a factory for creating connections.
Returns:
| Type | Description |
|---|---|
ToolSetResponse | A response containing the list of McpToolSpec instances with |
Raises:
| Type | Description |
|---|---|
McpServerConnectionError | If the connection cannot be created or accessed. |
RuntimeError | If the connection fails to establish. |
Source code in bridgic/protocols/mcp/_mcp_tool_set_builder.py
McpToolWorker ¶
Bases: Worker
A worker that executes an MCP tool on a connected MCP server.
This worker receives tool arguments as keyword arguments and calls the corresponding tool on the MCP server, returning the result.
Source code in bridgic/protocols/mcp/_mcp_tool_worker.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
server_connection property ¶
server_connection: McpServerConnection
Get the server connection, loading it from the server connection manager if necessary.
This property implements lazy loading of the server connection. If the connection is not available (e.g., after deserialization), it will be retrieved from the server connection manager by its name.
Returns:
| Type | Description |
|---|---|
McpServerConnection | The server connection instance. |
Raises:
| Type | Description |
|---|---|
McpServerConnectionError | If the connection cannot be found in the manager. |
arun ¶
async Asynchronously execute the MCP tool with the provided arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs | Dict[str, Any] | The arguments to pass to the tool. These are typically provided from the tool call arguments generated by the LLM. | {} |
Returns:
| Type | Description |
|---|---|
CallToolResult | The result of the tool call from the MCP server, containing content and optionally structured content. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the connection is not established and cannot be established. |
Source code in bridgic/protocols/mcp/_mcp_tool_worker.py
McpPromptTemplate ¶
Bases: BasePromptTemplate
This template implementation is used to generate a prompt from a connected MCP server.
Source code in bridgic/protocols/mcp/_mcp_template.py
prompt_info instance-attribute ¶
The raw information of the prompt.
format_messages ¶
format_messages(**kwargs) -> List[Message]
Format the prompt template from a connected MCP server into messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs | Any | The keyword arguments to pass to the prompt template. | {} |
Returns:
| Type | Description |
|---|---|
List[Message] | The list of messages. |