Skip to main content

@flow-state-dev/tools/mcp

Type Aliases​

CreateMcpCapabilityOptions​

type CreateMcpCapabilityOptions =
| object & CommonCapabilityOptions
| object & CommonCapabilityOptions;

CreateMcpManagerOptions​

type CreateMcpManagerOptions = object;

Properties​

_createClient?​
_createClient?: (config) => Promise<MCPClient>;

Test-only / advanced escape hatch.

Parameters​
config​

MCPServerConfig

Returns​

Promise<MCPClient>

servers​
servers: MCPServerConfig[];

EnrichDescriptionsMode​

type EnrichDescriptionsMode = "prefix" | "category" | false;

FilterTools​

type FilterTools = (ctx, tools) => GeneratorTool[] | Promise<GeneratorTool[]>;

Parameters​

ctx​

CapabilityPresetCtx

tools​

GeneratorTool[]

Returns​

GeneratorTool[] | Promise<GeneratorTool[]>


MCPCallToolOptions​

type MCPCallToolOptions = object;

Options for MCPManager.callTool.

Properties​

signal?​
signal?: AbortSignal;

Aborts the call: handed to the server's client, which cancels the request.


MCPCatalog​

type MCPCatalog = object;

Properties​

servers​
servers: MCPCatalogServer[];

MCPCatalogServer​

type MCPCatalogServer = object;

Properties​

error?​
error?: string;
metadata​
metadata: MCPServerMetadata;
name​
name: string;
status​
status: "pending" | "connected" | "errored";
tools​
tools: MCPCatalogTool[];

MCPCatalogTool​

type MCPCatalogTool = object;

Properties​

description​
description: string;
inputSchema​
inputSchema: unknown;
jsonSchema​
jsonSchema: Record<string, unknown>;

The tool's input JSON Schema as plain JSON, as the server published it: what a caller relaying the tool to another MCP client hands on unchanged. { type: "object" } when the server published none.

name​
name: string;
originalName​
originalName: string;

MCPClient​

type MCPClient = object;

Methods​

close()​
close(): Promise<void>;
Returns​

Promise<void>

tools()​
tools(): Promise<Record<string, AiSdkMcpTool>>;
Returns​

Promise<Record<string, AiSdkMcpTool>>


MCPManager​

type MCPManager = object;

Methods​

callTool()​
callTool(
name,
args,
options?
): Promise<unknown>;

Call one tool by its namespaced name (mcp__<server>__<tool>) on its server's connection, and return what the server answered, as the server's client returns it (an MCP CallToolResult, isError included). Connects first if getTools() has not run yet.

Parameters​
name​

string

args​

Record<string, unknown>

options?​

MCPCallToolOptions

Returns​

Promise<unknown>

Throws​

When no connected server has a tool by that name, or the call itself fails (an abort included).

close()​
close(): Promise<void>;
Returns​

Promise<void>

getCatalog()​
getCatalog(): MCPCatalog;
Returns​

MCPCatalog

getConnectedServerNames()​
getConnectedServerNames(): string[];
Returns​

string[]

getServerConfigs()​
getServerConfigs(): MCPServerConfig[];

The configs the manager was built with, headers included. A header can hold a credential: never log, record or emit what this returns.

Returns​

MCPServerConfig[]

getTools()​
getTools(): Promise<GeneratorTool[]>;
Returns​

Promise<GeneratorTool[]>


MCPServerConfig​

type MCPServerConfig = object & MCPServerMetadata;

Type Declaration​

name​
name: string;
transport​
transport: MCPTransportConfig;

MCPServerMetadata​

type MCPServerMetadata = object;

Properties​

category?​
category?: string;
description?​
description?: string;
examples?​
examples?: string[];
whenToUse?​
whenToUse?: string;

MCPToolMeta​

type MCPToolMeta = object;

Properties​

mcp​
mcp: object;
originalName​
originalName: string;
server​
server: string;

MCPTransportConfig​

type MCPTransportConfig = object;

Properties​

headers?​
headers?: Record<string, string>;
type​
type: "sse" | "http";

"http" is the Streamable HTTP transport and the recommended default for remote MCP servers. "sse" remains supported for servers that have not migrated yet, but most providers (including Linear) are deprecating it.

url​
url: string;

Variables​

defaultMcpFilterTools​

const defaultMcpFilterTools: FilterTools;

Default filter: reads ctx.request.state.mcp.disabledTools and disabledServers and removes any matching entries. Tools without MCPToolMeta always pass through.


MCP_TOOL_META​

const MCP_TOOL_META: unique symbol;

mcpRequestStateSchema​

const mcpRequestStateSchema: z.ZodObject<{
mcp: z.ZodOptional<z.ZodObject<{
disabledServers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
disabledTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
disabledServers?: string[];
disabledTools?: string[];
}, {
disabledServers?: string[];
disabledTools?: string[];
}>>;
}, "strip", z.ZodTypeAny, {
mcp?: {
disabledServers?: string[];
disabledTools?: string[];
};
}, {
mcp?: {
disabledServers?: string[];
disabledTools?: string[];
};
}>;

Schema contributed to the flow's requestStateSchema. Gives flows a typed ctx.request.state.mcp surface consumed by defaultMcpFilterTools.

Functions​

createMcpCapability()​

function createMcpCapability(options): DefinedCapability;

Public API for the MCP integration module.

Re-exports the factory functions, default implementations, and types needed to wire MCP servers into a flow via uses: [createMcpCapability(...)].

Parameters​

options​

CreateMcpCapabilityOptions

Returns​

DefinedCapability


createMcpManager()​

function createMcpManager(options): MCPManager;

Parameters​

options​

CreateMcpManagerOptions

Returns​

MCPManager


defaultMcpGuidanceFormatter()​

function defaultMcpGuidanceFormatter(catalog): string;

Format an MCP catalog into a markdown system-prompt block. Only connected servers are included. Returns an empty string if no servers are connected.

Parameters​

catalog​

MCPCatalog

Returns​

string


getMcpToolMeta()​

function getMcpToolMeta(tool): MCPToolMeta | null;

Reads the MCPToolMeta marker attached to a GeneratorTool. Returns null for tools that did not originate from an MCP manager.

Parameters​

tool​

unknown

Returns​

MCPToolMeta | null


redactSecrets()​

function redactSecrets(text, secrets): string;

text with each secret replaced by …, longest first so a value and a word inside it both go. Empty secrets are skipped. The one redaction rule for MCP error text: this manager's connection failures and a relay's own.

Parameters​

text​

string

The message to redact.

secrets​

readonly (string | undefined)[]

Values that must not appear in it, such as a key or an address.

Returns​

string

The message with every secret taken out.