Skip to content

MCP connections and tools

Connect an agent to remote tools and expose application capabilities through MCP.

  • Libraries Runtime.Agents Runtime.AgentsAiChatAgent Runtime.AgentsMcpClient
  • npm agents 0.22.0
  • Upstream/API Uses the pinned Agents SDK interfaces

Client and server roles

An MCP client discovers and calls tools offered by another service. An MCP server publishes tools, resources, and prompts for other clients. Decide which role your application needs before configuring a connection.

The SDK binds server capabilities through its agent modules and client management through Runtime.AgentsMcpClient.Mcp.Client. Cloudflare's MCP documentation covers the supported integration patterns.

Connection lifecycle

For new client integrations, use registerServer followed by connectToServer. Registration and establishing a live connection are separate operations. Authentication can return a continuation that the user must complete before discovery succeeds.

On recovery, restore the configured connections and wait for discovery before constructing the model's tool catalog. Use listServers to inspect server state and listTools or getAITools to obtain the currently available tools.

Read the discovered catalog

This helper is called after the manager has registered and started connecting to its servers. It waits up to five seconds for pending connection and discovery work, then returns the names currently available. Waiting does not make a failed connection successful; check individual server states when a required tool is missing.

open Fable.Core

module Mcp = FSharp.CloudEdge.Runtime.AgentsMcpClient.Mcp.Client

let availableTools (manager: Mcp.MCPClientManager) =
    async {
        let wait = Mcp.MCPClientManager.WaitForConnections.Options.Create(timeout = 5000.)
        do! manager.waitForConnections wait |> Async.AwaitPromise
        return manager.listTools () |> Array.map (fun tool -> tool.name)
    }
    |> Async.StartAsPromise

Match tool access to the task

Choose which connected servers and tools are available to a particular agent or user. Keep OAuth callbacks and connection state with the owning application identity. A discovered tool can still require authorization or fail at execution time, so handle tool errors separately from discovery.

Close connections that are no longer needed. For persistent agents, use the SDK's restoration lifecycle rather than assuming an in-memory network connection survives hibernation.

Testing and feedback

Useful test cases include connection and OAuth states, discovery after recovery, namespaced tool shapes, and tool error decoding.

Verify bindings explains how to run checks and report an issue. Include a small reproduction and the package versions used; working examples are welcome too.

NuGet packages

Runtime.Agents 0.1.0, Runtime.AgentsAiChatAgent 0.1.0, Runtime.AgentsMcpClient 0.1.0.

See installation and release availability.

Edit this page