Tools, Skills and MCP

Capability Purpose
Built-in tools File, process, planning, and other runtime operations exposed through the v2 catalog/executor.
Skills Reusable instructions and resources, discovered and loaded through Skill providers.
MCP External servers whose discovered tools join the host’s tool catalog.

Desktop

Configure tools and Skills on the Agent, and add MCP connections in Settings. Enabled connections are discovered during catalog/runtime composition. Discovery failures are reported rather than silently ignored. load_skill activates selected resources; selecting a Skill alone does not mean its full content is already in model context.

Server

Use model/Agent/Skill/MCP management in the web client. Skills support ZIP upload and per-Agent selection. MCP management uses /api/mcp; refresh a connection to rediscover tools. See HTTP API.

Server accepts only sse and streamable_http MCP transports; it rejects tenant stdio commands. Desktop may use stdio. Skill catalog descriptions are complete, including multiline YAML; only loaded active Skill content has a separate token budget. The full catalog still counts toward the overall context budget.

Embedded hosts

The minimal quick start intentionally has no file or shell tools. Official tools require an OfficialToolRuntime with explicit workspace and sandbox bindings. Host-provided tool execution must validate grants at the resource boundary. An in-memory manifest does not authorize access to arbitrary host files.

Use the integration manual to select catalogs, executors, Skill sources, and policy providers. The mcp_servers/ directory also contains integrations used by older applications; their presence does not enable them in v2 automatically.

Authenticated remote MCP in v2

This guide describes the current sagents/v2 and app/v2 source paths, which require Python 3.12+. Use the instructions for your host; a v1 configuration or legacy Desktop installer does not establish support for these v2 entry points.

Connection and credentials

For a Bearer-authenticated server, use these values in Desktop’s Settings → MCP connection dialog or Server’s MCP management:

Setting Example Meaning
Name remote A name for this connection.
Protocol streamable_http Streamable HTTP, rather than stdio or SSE.
URL https://mcp.example.com/mcp Replace with the server’s actual endpoint.
API key / api_key Your token, without Bearer The SDK session adds the Authorization: Bearer prefix. This is the MCP service credential, not the model API key.

Server uses url in /api/mcp requests; Desktop’s connection payload uses streamable_http_url. Let each host’s interface construct its own payload. The current bridge accepts an API key for Bearer authentication; this is not an arbitrary-header or OAuth configuration example.

Embedded hosts register a complete tool.provider implementation with builder.register(ExtensionRegistration(...)), then select its plugin, Run scope and serializable parameters in runtime configuration. The factory receives the authenticated Run through a declared execution.environment dependency. It can construct McpToolPlugin for that Run without assembling any Agent execution components.

Declare credentials.provider as a dependency and resolve a CredentialRef using the Run’s request context. Keep credential material in the provider instance; runtime configuration and durable metadata contain references rather than secret values. ${REMOTE_MCP_API_KEY} in an API-key field is a literal value, not automatic environment expansion. Do not commit tokens to configuration or include them in screenshots or logs.

The runnable standard host reference exercises MCP alongside files, Shell, Skills, nested Teams and restart recovery. See the host integration manual for the registration, configuration and lifecycle contracts.

Discover, authorize, call, and close

  1. Discover: Enable the connection and inspect the tools actually returned by the catalog, including their Sage names and input schemas. Server’s refresh action rediscovers tools. A saved connection or a successful tool listing does not prove that a tool call succeeds.
  2. Authorize: In the Server UI, select individual MCP/A2A tools under Agent → Edit → Available tools → External tools. The Server API external_tools allowlist defaults to empty (disabled). Standard packages keep these names in tools; the Server filters providers before injection. Newly discovered tools require explicit selection. For embedded Agents, include the discovered names in the Agent’s tools allowlist. The host must also give the actor the required tool.external_side_effect scope. The MCP bridge marks every external tool as WRITE and requires_approval=True, even if its name or annotations suggest a read-only search. The default CONFIGURED policy asks for approval after scope checks; a host’s selected strategy and approval memory can change that interaction. A service API key does not replace Sage authorization.
  3. Call: Review the selected tool and arguments in the host’s approval flow, then inspect its result. Distinguish discovery/authentication failures from a tool response with isError. A timeout, cancellation, or lost response can leave the remote effect unknown; check the remote result before considering a retry.
  4. Close: The default bridge opens a short-lived SDK session for discovery or one call and closes its context afterward. Keep await application.close() in your embedded host’s shutdown path. Disable or remove the connection to stop future use, and cancel an active Run separately; closing a local session does not revoke the service’s API key or prove that remote work stopped.

MCP calls default to a finite 7200-second (2-hour) deadline. Set call_timeout_seconds per server to another positive finite duration; legacy null values use the default. On timeout the Agent receives an unknown-outcome result and checks status or existing outputs before deciding whether retry is safe; the timeout itself does not request human intervention.

This bounds one remote MCP call, not generic tool execution or the lifetime of an internal Team or delegated child Run. Internal child tasks have no default two-hour deadline; explicit task and ancestor deadlines, budgets, and cancellation still apply. For long jobs submitted through an external MCP service, each request retains its MCP deadline; use the service’s submission and status APIs. A local request timeout does not prove cancellation of the remote job.

Keyless Parallel search example

The runnable SAgents example uses Parallel Search MCP over Streamable HTTP to discover and execute web search and page fetch through the v2 bridge without a Parallel API key. It demonstrates explicit host-side calls; see the authorization steps above when wiring an Agent.

Keyless Keenable search example

The Keenable example uses Keenable’s MCP server over Streamable HTTP the same way: the public endpoint without credentials, or the keyed endpoint with an X-API-Key header when KEENABLE_API_KEY is set. It is also an explicit host-side call demo. Its page lists what is sent to the hosted service and links the service’s rate limits and privacy information.

Optional session reuse for embedded hosts

Hosts can explicitly inject McpSessionPool as the bridge’s session_factory. The default bridge still opens a session per discovery/call; Desktop and Server configuration do not automatically enable pooling. The host owns the pool and must keep it open for the lifetime of its MCP work. In this example, servers is a tuple of McpServerConfig values and run_agent uses the supplied plugin as its tool catalog/executor:

from sagents.v2.tool import McpSessionPool, McpToolPlugin

async def run_with_mcp(servers, run_agent):
    pool = McpSessionPool(
        idle_timeout_seconds=300,
        shutdown_timeout_seconds=10,
        cleanup_timeout_seconds=5,
    )
    try:
        async with pool:
            plugin = McpToolPlugin(servers, session_factory=pool)
            await run_agent(plugin)
    finally:
        await pool.wait_closed()  # No deadline: keep the loop alive for teardown.
        # Inspect pool.cleanup_errors in the host shutdown diagnostics.

Each pool belongs to one event loop and one host-selected security scope. Create separate pools for different tenants or credential scopes. Matching effective configurations share one initialized session, including concurrent borrowers; releasing or cancelling one borrower does not close another borrower’s session. Credentials, URL, command, args, environment and timeout settings participate in identity. Configuration or credential changes create a separate entry. The host must replace its pool if the inherited process environment changes.

timeout_seconds bounds each acquisition/initialization independently of call_timeout_seconds. Pool timeouts and acquisition timeouts must be finite and positive. Idle eviction starts after the final lease returns (or after an unused initialization). An exceptional operation retires the connection; a later acquisition can replace it after active leases drain. The pool does not retry tool calls, implement backoff/keepalive, or refresh tool lists on notifications.

aclose() rejects new acquisitions and wakes pending borrowers, waits up to shutdown_timeout_seconds for active leases, then closes remaining sessions. SDK contexts always exit in the task that entered them. Cleanup runs concurrently with a separate cleanup_timeout_seconds bound on the host wait. Interrupted HTTP/custom initialization receives one cancellation, allowing asynchronous teardown to run. Default SDK stdio initialization uses its own timeout_seconds deadline; its initialization/teardown owner is retained even if the host wait expires; interrupting its graceful shutdown could orphan descendants. Grace expiry can interrupt an active call; it does not prove the server stopped or that replay is safe. Cancelling the caller awaiting aclose() leaves shared cleanup running; another aclose() waits for the same bounded shutdown phase. A closed pool cannot be re-entered.

wait_closed() starts shutdown if needed and waits until all retained owner tasks finish. It has no deadline and can be called repeatedly or by concurrent waiters. Cancelling or timing out a waiter does not cancel SDK teardown; a later wait_closed() can still observe completion. An uncooperative custom factory can keep this wait pending indefinitely.

The bounded cleanup_errors tuple contains sanitized lifecycle codes, including session_cleanup_failed, cleanup_timeout and cleanup_incomplete; include these in host shutdown diagnostics. SDK stdio teardown or a custom factory that suppresses cancellation can outlive the host wait; cleanup_incomplete reports this, its task remains tracked, and the entry is not reused. Keep the event loop alive until wait_closed() finishes; closing the loop immediately can interrupt retained cleanup. These codes are historical diagnostics, not a completion flag, and remain after cleanup finishes. Successful responses remain authoritative even if later transport cleanup fails. Pooling does not add a durable operation ledger or exactly-once execution.


Sage documentation for the current repository layout. Source available under the MIT license.

This site uses Just the Docs, a documentation theme for Jekyll.