teff.tool.mcp¶
teff.tool.mcp
¶
Model Context Protocol (MCP) bridge and ready-made server presets.
Public surface of the MCP integration:
- :class:
~teff.tool.mcp.bridge.McpToolGroup— a lazily-opened connection to one MCP server whose tools become<id>__<tool>members. - :func:
~teff.tool.mcp.bridge.mcp_tools/ :func:~teff.tool.mcp.bridge.open_tools— connection helpers. - :class:
~teff.tool.mcp.presets.McpPresetand :data:MCP_PRESETS— ready-made launch configs for known servers; subclassMcpPresetand it is registered automatically (each subclass needs a uniquename).
Modules:
| Name | Description |
|---|---|
bridge |
Bridge to Model Context Protocol (MCP) servers. |
presets |
Ready-made launch configs for known MCP servers. |
Classes:
| Name | Description |
|---|---|
FetchPreset |
Fetch: download web content as Markdown. |
GitPreset |
Git: read and edit Git repositories. |
GmailPreset |
Gmail: search, read, draft and send messages. |
GoogleCalendarPreset |
Google Calendar: read, create and update events. |
GoogleDrivePreset |
Google Drive: file search, read, create, upload. |
McpPreset |
Base class for launch configs of known MCP servers. |
McpTool |
A :class: |
McpToolGroup |
A lazily-opened MCP server connection, exposing its tools. |
SQLitePreset |
SQLite: inspect and query SQLite databases. |
TimePreset |
Time / Timezone: current time and timezone conversion. |
Functions:
| Name | Description |
|---|---|
mcp_tools |
Connect to an MCP server and yield its tools as Teff :class: |
open_tools |
Expand :class: |
FetchPreset
¶
Bases: McpPreset
Fetch: download web content as Markdown.
Source code in teff/tool/mcp/presets.py
104 105 106 107 108 109 | |
GitPreset
¶
Bases: McpPreset
Git: read and edit Git repositories.
Source code in teff/tool/mcp/presets.py
96 97 98 99 100 101 | |
GmailPreset
¶
Bases: McpPreset
Gmail: search, read, draft and send messages.
Source code in teff/tool/mcp/presets.py
68 69 70 71 72 73 74 75 76 77 78 79 | |
GoogleCalendarPreset
¶
Bases: McpPreset
Google Calendar: read, create and update events.
Source code in teff/tool/mcp/presets.py
82 83 84 85 86 87 88 89 90 91 92 93 | |
GoogleDrivePreset
¶
Bases: McpPreset
Google Drive: file search, read, create, upload.
Source code in teff/tool/mcp/presets.py
54 55 56 57 58 59 60 61 62 63 64 65 | |
McpPreset
¶
Base class for launch configs of known MCP servers.
Subclasses declare the canonical registry name plus either the
stdio command (or streamable-http url) and the env keys the
server expects. env values are overridable defaults;
from_preset merges any caller-provided env over them (same key
wins), and an explicit command/url fully replaces the preset's
transport.
Source code in teff/tool/mcp/presets.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
McpTool
¶
Bases: Tool
A :class:~teff.tool.Tool that forwards calls to an MCP server.
Instances are created by :func:mcp_tools. The tool's JSON schema
comes from the server's tool definition instead of being inferred
from type hints.
Source code in teff/tool/mcp/bridge.py
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 | |
McpToolGroup
¶
A lazily-opened MCP server connection, exposing its tools.
Holds the connection config (url or command, env, cwd) without any
live connection. The session is opened on first :meth:open and kept
open until :meth:aclose, so several graph.run calls (daemon ticks,
conversation turns, resumes) share a single connection instead of
re-spawning the server each time.
Instances are created from a workflow's tools: block (type: mcp)
or directly::
group = McpToolGroup(id="drive", command=["uvx", "mcp-server-google-drive"])
tools = await group.open() # -> [McpTool, ...] named ``drive__<tool>``
...
await group.aclose()
Ready-made presets for known servers give the launch command and its env-var keys in one shot; overrides merge on top::
group = McpToolGroup.from_preset(
"google_drive",
env={"GOOGLE_DRIVE_REFRESH_TOKEN": os.environ["GDRIVE"]},
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Server id; member tools are prefixed |
'mcp'
|
url
|
str | None
|
Streamable HTTP endpoint (mutually exclusive with command). |
None
|
command
|
list[str] | None
|
Stdio server command, a list of argv tokens. |
None
|
env
|
dict[str, str] | None
|
Optional extra environment variables for stdio servers. |
None
|
cwd
|
str | None
|
Optional working directory for stdio servers. |
None
|
client_info
|
dict | None
|
Optional dict overrides for the client
|
None
|
Methods:
| Name | Description |
|---|---|
aclose |
Close the connection if it was opened. Idempotent. |
from_preset |
Build a group from a named :data: |
open |
Return the server's tools, opening the connection on first use. |
Source code in teff/tool/mcp/bridge.py
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 | |
aclose
async
¶
aclose()
Close the connection if it was opened. Idempotent.
Source code in teff/tool/mcp/bridge.py
265 266 267 268 269 270 | |
from_preset
classmethod
¶
from_preset(name, *, env=None, **overrides)
Build a group from a named :data:MCP_PRESETS entry.
The preset class supplies its canonical name (used as the
default id), the launch command (or url) and its default
env keys. env entries merge over the preset's defaults (same
key overrides); command/url/id/cwd overrides fully
replace the preset's value.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known preset. |
Source code in teff/tool/mcp/bridge.py
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 | |
open
async
¶
open()
Return the server's tools, opening the connection on first use.
Repeated calls return the cached member tools; the underlying
session stays open until :meth:aclose.
Source code in teff/tool/mcp/bridge.py
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 | |
SQLitePreset
¶
Bases: McpPreset
SQLite: inspect and query SQLite databases.
Source code in teff/tool/mcp/presets.py
120 121 122 123 124 125 | |
TimePreset
¶
Bases: McpPreset
Time / Timezone: current time and timezone conversion.
Source code in teff/tool/mcp/presets.py
112 113 114 115 116 117 | |
mcp_tools
async
¶
mcp_tools(url=None, command=None, *, env=None, cwd=None, client_info=None)
Connect to an MCP server and yield its tools as Teff :class:Tool\s.
Exactly one of url or command must be given:
url: Streamable HTTP endpoint of an MCP server, e.g.http://localhost:8000/mcp.command: Subprocess invocation for a stdio server, e.g.["uvx", "mcp-server-git"]or["npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"].
The session stays open for the duration of the async with block;
tools keep working until it exits, after which the connection is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str | None
|
Streamable HTTP endpoint. |
None
|
command
|
list[str] | None
|
Stdio server command (list of argv tokens). |
None
|
env
|
dict[str, str] | None
|
Optional extra environment variables for stdio servers. |
None
|
cwd
|
str | None
|
Optional working directory for stdio servers. |
None
|
client_info
|
dict | None
|
Optional dict overrides for the client
|
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[list[McpTool]]
|
A list of :class: |
Source code in teff/tool/mcp/bridge.py
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 | |
open_tools
async
¶
open_tools(tools)
Expand :class:McpToolGroup entries in tools into their members.
Groups are opened on entry (so an async with open_tools(...) around
a whole daemon loop keeps every server connected for its duration) and
closed on exit. Plain tools pass through untouched.
Yields:
| Type | Description |
|---|---|
AsyncIterator[list[Tool]]
|
A flat list of ready-to-call tools (group members replacing their |
AsyncIterator[list[Tool]]
|
groups). |
Source code in teff/tool/mcp/bridge.py
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 | |