MCP server integrations
MCP server integrations let OpenSRE use tools from user-configured Model Context Protocol servers as normal agent tools. The lifecycle covers named server settings, local or remote transport, bounded tool discovery, schema and safety handling, setup, display-safe summaries, and live verification.
Server configuration
An MCP server configuration describes how OpenSRE reaches one server and which of its tools may enter the agent tool set. Each named server is an instance of the mcp integration, so several servers can coexist without sharing identity or credentials. (integrations/…/config.py• L35-47)
The configuration supports three transport modes:
| Transport | Connection source | Main endpoint value |
|---|---|---|
streamable-http | Remote HTTP MCP server | url |
sse | Remote server using server-sent events | url |
stdio | Local process | command and args |
If no mode is set, a command without a URL selects stdio; other configurations select streamable-http. HTTP credentials become request headers. A bearer token supplies an Authorization header unless an explicit authorization header already exists. Credentials stay outside tool arguments. (integrations/…/config.py• L49-59, integrations/…/config.py• L91-124)
The configuration also controls exposure. allowed_tools narrows the server tool names, while read_only exposes only tools that the server marks as read-only. Invalid transport settings are rejected instead of being treated as an empty or wider configuration. (integrations/…/config.py• L26-32, integrations/…/config.py• L106-130)
References: integrations/…/config.py• L35-47 integrations/…/config.py• L49-59 integrations/…/config.py• L91-130
Connection and transport bridging
The shared MCP client turns a normalized configuration into an initialized MCP session. It keeps the server-facing transport choice separate from the rest of the integration layer, so discovery, verification, and tool calls use the same connection rules. (integrations/mcp_client.py• L26-75)
The connection path is:
flowchart LR
A[Named server configuration] --> B{Transport mode}
B -->|stdio| C[Start local command]
B -->|sse| D[Open SSE session]
B -->|streamable-http| E[Open HTTP stream]
C --> F[Initialize MCP session]
D --> F
E --> F
F --> G[List or call server tools]
Every session uses configured time limits and closes its transport after the operation. The streamable HTTP adapter also accepts the stream shape used by both newer and older MCP client packages, which keeps the integration contract stable across SDK versions. (integrations/mcp_client.py• L84-151, integrations/mcp_streamable_http_compat.py• L24-73)
References: integrations/mcp_client.py• L26-75 integrations/mcp_client.py• L84-151 integrations/mcp_transport.py• L14-23 integrations/mcp_streamable_http_compat.py• L24-73
Tool discovery
Tool discovery asks each configured server for its advertised tools before OpenSRE builds the tool list for a turn. The discovery result keeps the server name, tool name, description, input schema, and read-only hint needed to create a safe runtime tool. (integrations/…/discovery.py• L35-44, integrations/…/discovery.py• L79-99)
Discovery is parallel and bounded so one slow server does not block the full turn. Successful listings are reused for five minutes. Failures and timeouts contribute no tools and are remembered for one minute before another attempt. A changed server configuration gets a new cache identity. (integrations/…/discovery.py• L27-32, integrations/…/discovery.py• L102-159)
The runtime assembles the flow through a dynamic tool source. It resolves configured instances, skips invalid or duplicate server names, discovers their tools, and adds the resulting tools to each turn. (integrations/harness_adapters.py• L75-107, integrations/…/bridge.py• L137-176)
References: integrations/…/discovery.py• L27-32 integrations/…/discovery.py• L35-44 integrations/…/discovery.py• L79-99 integrations/…/discovery.py• L102-159 integrations/…/bridge.py• L137-176 integrations/harness_adapters.py• L75-107
Tool bridging
The bridge converts each discovered server tool into a first-class OpenSRE tool. The model sees the server tool's purpose and typed arguments directly instead of calling a generic proxy and naming the remote operation itself. (integrations/…/bridge.py• L1-8, integrations/…/bridge.py• L105-120)
Names use the stable form mcp__<server>__<tool>. Names are cleaned for provider limits, and a short hash keeps distinct server-tool pairs distinct when cleaning or length limits could cause a collision. The server name also appears in the description and display label so the source remains clear to the model and operator. (integrations/…/bridge.py• L30-64, integrations/…/bridge.py• L105-116)
The server's readOnlyHint controls the tool's effect level. Read-only tools can run as reads and are safe for concurrent use. Other tools are external actions and pass through the existing approval rules. A server-level read-only setting or allowlist can remove tools before they reach this stage. (integrations/…/bridge.py• L67-120)
When a call fails, the bridge returns the shared unavailable result with the server and remote tool named in the error. This keeps a remote outage visible without turning it into an unhandled runtime failure. (integrations/…/bridge.py• L67-102)
References: integrations/…/bridge.py• L1-8 integrations/…/bridge.py• L30-64 integrations/…/bridge.py• L67-120 core/…/mcp_bridge.py• L1-64
Tool schema handling
MCP input schemas become provider-safe argument schemas before the model receives the bridged tool. The bridge keeps object properties, required fields, enums, defaults, and other argument meaning while normalizing the outer shape for provider routes. (integrations/…/schema.py• L99-112)
Local JSON Schema references are inlined so a provider that drops $ref and $defs does not lose the argument definition. The walker understands schema containers rather than treating argument names as schema keywords. Recursive or very large schemas stay bounded; unresolved references are not allowed to expand without limit. (integrations/…/schema.py• L1-11, integrations/…/schema.py• L49-86)
References: integrations/…/schema.py• L1-11 integrations/…/schema.py• L18-43 integrations/…/schema.py• L49-109
Setup and persistence
Setup creates or updates one named MCP server at a time. The setup surface chooses either a remote HTTP URL with an optional bearer token or a local command with optional arguments. It also collects the read-only choice and an optional tool allowlist. (integrations/…/setup.py• L19-29, integrations/…/setup.py• L80-149)
The shared setup flow validates the fields, runs the MCP verifier, and saves the server only after verification passes. Named server instances are store-only because one environment variable cannot safely represent many independently named servers. Updating one name preserves other servers and carries forward settings that the form does not edit, such as a tuned timeout or HTTP headers. (integrations/…/setup.py• L31-53, integrations/setup_flow.py• L265-281, integrations/setup_flow.py• L408-467)
The setup lifecycle is:
flowchart LR
A[Choose transport and enter server settings] --> B[Normalize configuration]
B --> C[Connect and list exposed tools]
C -->|verification passes| D[Save named mcp instance]
C -->|verification fails| E[Do not save]
D --> F[Discover tools during later turns]
References: integrations/…/setup.py• L31-53 integrations/…/setup.py• L80-149 integrations/setup_flow.py• L265-281 integrations/setup_flow.py• L408-467
Server summaries
Server summaries provide a safe operational view of configured MCP servers. They show the server name, transport, endpoint, and read-only state without showing tokens, headers, URL query data, URL credentials, or command arguments. (integrations/…/summary.py• L20-55)
The summary layer reads all named instances in configuration order. Remote endpoints keep only scheme, host, port, and path. Local servers show the command basename. Verification results can be paired with these summaries so one server can be listed or diagnosed without hiding the state of its siblings. (integrations/…/summary.py• L30-71, tests/…/test_manage.py• L76-119)
References: integrations/…/summary.py• L20-71 tests/…/test_manage.py• L76-119
Verification
Verification checks one configured server by connecting to it and listing the tools that would be exposed under its current allowlist and read-only rules. A passing result reports the total exposed tools and separates read-only tools from tools that require approval. (integrations/…/verifier.py• L1-12, integrations/…/verifier.py• L20-47)
Verification distinguishes invalid configuration, connection or listing failure, and a successful connection that exposes no tools. The check runs per named instance, so a failed server does not conceal a working server in the same mcp integration. (integrations/…/verifier.py• L20-47, tests/…/test_manage.py• L35-50)
References: integrations/…/verifier.py• L1-12 integrations/…/verifier.py• L20-47 tests/…/test_manage.py• L35-50
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the transport values aligned across configuration validation, session opening, setup choices, summaries, and SDK compatibility.
- Keep server instance names aligned across stored records, discovery identity, bridged tool names, allowlists, removal commands, and verification rows.
- Preserve the rule that a failed setup verification does not save a new or updated server.
- Keep the server-level allowlist and read-only filter applied before tool registration and verification counts.
- Preserve per-server discovery time bounds, success and failure cache lifetimes, and cache invalidation after configuration changes.
- Keep the bridged name within provider limits while preserving uniqueness for cleaned or truncated names.
- Keep local schema reference expansion bounded and preserve argument names that resemble JSON Schema keywords.
- Keep summaries free of credentials and command arguments when endpoint or management output changes.
- Keep MCP tool calls on the shared result and error path so remote failures remain unavailable results.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A remote server has no URL or a stdio server has no command | The configuration is skipped or setup fails | Transport validation requires the matching endpoint |
| A server does not answer during discovery | That server contributes no tools for the turn | Per-server timeouts, bounded discovery wait, and short failure caching |
allowed_tools or read_only filters every advertised tool | Verification fails and no bridged tools appear | Verification reports the empty exposed set and names the filters to check |
| Two configured servers use the same name | The later server is ignored | Discovery keeps the first name and skips duplicates |
| A cleaned or long tool name could collide | The model could call the wrong remote tool | The bridge adds a hash suffix when the plain name is not lossless |
| A server returns a non-object or oversized schema | Provider tool arguments can become unusable or too large | The bridge normalizes the outer object and bounds reference expansion |
| A bridged tool call cannot open a session or times out | The agent receives an unavailable result instead of a normal tool payload | Shared call timeouts and root-cause error handling |
| A summary includes raw URL or command data | Tokens or secrets can appear in operator output | Summaries remove URL credentials, query strings, headers, and arguments |
Key files
| File | Why to read it |
|---|---|
| integrations/…/config.py | Defines the normalized per-server contract and exposure rules. |
| integrations/…/setup.py | Defines the named-server setup choices and update behavior. |
| integrations/setup_flow.py | Shows the shared verify-before-save setup lifecycle. |
| integrations/mcp_client.py | Defines session opening, tool listing, tool calls, time limits, and result normalization. |
| integrations/…/discovery.py | Explains bounded per-server tool discovery and caching. |
| integrations/…/bridge.py | Shows how remote tools become first-class agent tools and receive safety labels. |
| integrations/…/schema.py | Defines provider-safe handling of MCP input schemas. |
| integrations/…/summary.py | Defines the credential-safe server list view. |
| integrations/…/verifier.py | Defines the live check and its per-server result meaning. |
| integrations/harness_adapters.py | Connects MCP tool discovery to each runtime turn. |
| integrations/mcp_streamable_http_compat.py | Preserves streamable HTTP behavior across MCP SDK shapes. |
| tests/…/test_bridge.py | Demonstrates end-to-end discovery, schema, naming, filtering, and call gating. |
| tests/…/test_setup.py | Demonstrates verify-before-save and named-instance update behavior. |
| tests/…/test_manage.py | Demonstrates per-server verification, removal, and safe summaries. |