tool_bridge
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| ToolBridge llmling_models.tool_bridge Exposes Python functions as an MCP server. |
||
| ToolBridgeConfig llmling_models.tool_bridge Configuration for the ToolBridge. |
🛈 DocStrings¶
MCP server bridge for exposing Python functions to MCP clients.
This module provides a bridge that exposes Python functions as an MCP server using HTTP transport. This allows Agents to use custom tools which have runtime access to our internals via Context objects.
The bridge runs in-process and handles the MCP protocol automatically.
MCPTransport
module-attribute
¶
Transports supported for serving the tool bridge.
ToolBridge
dataclass
¶
Exposes Python functions as an MCP server.
This bridge lets an MCP client (a model or agent that can connect to MCP servers) call custom Python functions via MCP transport.
Example
Source code in src/llmling_models/tool_bridge.py
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 | |
config
class-attribute
instance-attribute
¶
config: ToolBridgeConfig = field(default_factory=ToolBridgeConfig)
Bridge configuration.
__aenter__
async
¶
__aexit__
async
¶
get_mcp_server_tool
¶
Get a pydantic-ai MCPServerTool for a model that supports MCP servers.
Returns:
| Type | Description |
|---|---|
MCPServerTool
|
MCPServerTool configured to connect to this bridge. |
Source code in src/llmling_models/tool_bridge.py
start
async
¶
Start the HTTP MCP server in the background.
stop
async
¶
Stop the HTTP MCP server.
Source code in src/llmling_models/tool_bridge.py
ToolBridgeConfig
dataclass
¶
Configuration for the ToolBridge.
Source code in src/llmling_models/tool_bridge.py
port
class-attribute
instance-attribute
¶
Port to bind to (0 = auto-select available port).
server_name
class-attribute
instance-attribute
¶
Name for the MCP server.
transport
class-attribute
instance-attribute
¶
transport: MCPTransport = 'sse'
Transport protocol: 'sse' or 'streamable-http'.
create_tool_bridge
async
¶
create_tool_bridge(
tools: list[Callable[..., Any]],
*,
host: str = "127.0.0.1",
port: int = 0,
transport: MCPTransport = "sse",
server_name: str = "pydantic-ai-tools",
) -> AsyncGenerator[ToolBridge]
Create and start a ToolBridge as a context manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
list[Callable[..., Any]]
|
Functions to expose as MCP tools |
required |
host
|
str
|
Host to bind to |
'127.0.0.1'
|
port
|
int
|
Port to bind to (0 = auto-select) |
0
|
transport
|
MCPTransport
|
Transport protocol ('sse' or 'streamable-http') |
'sse'
|
server_name
|
str
|
Name for the MCP server |
'pydantic-ai-tools'
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[ToolBridge]
|
Running ToolBridge instance |