@flow-state-dev/mcp
Interfaces
CreateMcpTransportAdapterOptions
@flow-state-dev/mcp — MCP transport adapter for the Flow State Dev
runtime. Exposes every flow with mcp.enabled: true as its own MCP
server over Streamable HTTP at POST /api/flows/:kind/mcp.
Mount alongside the built-in HTTP adapter:
import { createFlowApiRouter } from "@flow-state-dev/engine"; import { createMcpTransportAdapter } from "@flow-state-dev/mcp";
const router = createFlowApiRouter({ registry, stores, adapters: [createMcpTransportAdapter()] });
v1 limitations: stateless only, a single JSON tool result, no progress notifications.
Properties
allowedOrigins?
allowedOrigins?: string[] | "*";
Origin allowlist for cross-origin clients. Defaults to "same-origin
only" — the adapter responds 403 to any request carrying an
Origin header that does not match the request URL's origin. Pass
"*" to allow any origin (only use for local development), or an
explicit list of origin strings.
basePath?
basePath?: string;
Endpoint base path. Defaults to /api/flows, or /mcp when
dedicatedBasePath is enabled.
dedicatedBasePath?
dedicatedBasePath?: boolean;
Treat basePath as MCP-exclusive and mount at <basePath>/:kind
instead of <basePath>/:kind/mcp. The dedicated base must include a
non-root prefix so it cannot claim every single-segment route. Defaults to
false.
forwardQueryParams?
forwardQueryParams?: string[];
Allowlist of endpoint query-string params to forward into the
tools/call action input. When a request URL carries one of these params
(e.g. .../mcp?source=claude-desktop), its value is merged into the
dispatched tool input under the same key. This is the seam for
installation-level values an operator sets once on the endpoint URL,
rather than per-call arguments the model supplies.
The forwarded value is authoritative: it overrides a same-named
argument in the tool call, since the point is provenance the model should
not be able to override. Listing a param name is the operator's explicit
opt-in that it becomes endpoint-controlled. A forwarded param only takes
effect if the target action's input schema accepts it — otherwise the
existing zod boundary strips or rejects it, exactly as for any other input
key. Only tools/call is affected; initialize / tools/list /
resources/* and auth are untouched. Defaults to forwarding nothing.
McpTool
MCP Tool shape returned by tools/list. We hand-build this rather
than depending on the SDK type to keep the v1 surface tight; the
fields covered here are the entire v1 contract.
Properties
description
description: string;
inputSchema
inputSchema: JsonSchemaObject;
name
name: string;
McpToolResult
Properties
content
content: McpToolContent[];
isError?
isError?: boolean;
Variables
MCP_TRANSPORT_SOURCE
const MCP_TRANSPORT_SOURCE: "mcp" = "mcp";
Stable provenance identifier stamped onto every MCP-originated request.
Functions
actionToMcpTool()
function actionToMcpTool(toolName, action): McpTool;
Build an MCP Tool from an ActionConfig. Caller is responsible for
ensuring action.description is non-empty (validated in defineFlow).
Parameters
toolName
string
action
ActionConfig
Returns
createMcpTransportAdapter()
function createMcpTransportAdapter(options?): InboundTransportAdapter;
Construct the MCP transport adapter. Pure synchronous factory — the
returned InboundTransportAdapter is mounted by createFlowApiRouter
via the adapters option.
Parameters
options?
CreateMcpTransportAdapterOptions
Returns
InboundTransportAdapter
resolveExposedActions()
function resolveExposedActions(flowKind, actions): Map<string, {
action: ActionConfig;
actionKey: string;
}>;
Resolve the set of actions exposed via MCP for a given flow.
Excludes actions that opt out via action.mcp.enabled === false.
Tool names come from action.mcp.name when set, otherwise are derived
deterministically from the action key. Throws if two exposed actions
resolve to the same tool name — the MCP client cache keys on tool
name, so collisions are catastrophic and must surface at startup.
Returns Map<toolName, { actionKey, action }> so the dispatcher can
look up the underlying action by tool name in O(1).
Parameters
flowKind
string
actions
Record<string, ActionConfig>
Returns
Map<string, {
action: ActionConfig;
actionKey: string;
}>
toolInputJsonSchema()
function toolInputJsonSchema(schema): JsonSchemaObject;
Convert a Zod schema to a JSON Schema suitable for MCP tools/list
inputSchema. The result always has type: "object" at the top level
— MCP requires tool inputs to be objects.
Parameters
schema
ZodTypeAny
Returns
JsonSchemaObject
toolNameFromActionKey()
function toolNameFromActionKey(actionKey): string;
Derive the MCP tool name from an action key. Uses decamelize with
underscore separators and consecutive-uppercase normalization so
URLParser → url_parser and getHTTPSProxy → get_https_proxy.
Hyphens in the source key are preserved as-is (legal per MCP's
[A-Za-z0-9_.-]{1,128} charset).
Parameters
actionKey
string
Returns
string
toolResultFromExecution()
function toolResultFromExecution(result): McpToolResult;
Build an MCP tool result from a runtime ExecutionResult.
Parameters
result
ExecutionResult