Skip to main content

API Reference

This page provides a reference for the public APIs exposed by mcpfy-sdk. The examples in this document target mcpfy-sdk@0.3.1.

Server

Import the server APIs from:

MCPServer

Creates an MCP server.

MCPServerConfig

The server configuration supports:

name

Required server name.

version

Required server version.

description

Optional description for the server.

basePath

Optional HTTP MCP endpoint path. The default is:
Example:

icon

Optional server icon. mcpfy supports remote URLs, data URIs, local file paths, and file: URLs.

auth

Optional HTTP authentication configuration.
See Authentication.

widgetsDir

Optional widget root directory. The default is:

server.tool()

Registers a tool with the MCP server.
The tool definition contains:
  • name
  • description
  • schema
  • optional widget configuration
The callback receives validated input.

Tool Return Helpers

text()

Creates a text result:

markdown()

Creates a Markdown result:

object()

Creates a structured result:
Tool callbacks should use these helpers instead of returning an arbitrary object directly.

server.listen()

Starts the MCP server.

stdio

HTTP

HTTP listen results include information such as:

Port Resolution

The HTTP port is resolved in this order:
  1. listen() option
  2. --port command-line argument
  3. PORT environment variable
  4. 3000
For example:
takes precedence over:
and:

Host

The HTTP host can be configured with:

Silent Startup

Suppress the HTTP startup message with:

server.close()

Closes the server and its underlying resources.

server.nativeServer

Provides access to the underlying native MCP server.
This can be used when functionality from the official MCP SDK is required directly.

Client

Import the client from:

MCPClient

Creates an MCP client.

HTTP Server

stdio Server

The client determines the connection type from the server configuration. A transport property is not required for stdio configuration.

Resources

server.resource()

Registers a resource.
The callback receives the tool context. The registered URI is available from the definition.

server.resourceTemplate()

Registers a resource template. The callback signature receives:
Example:
The parameters are:
  • uri — resolved resource URI
  • params — values extracted from the template
  • ctx — request context

Prompts

Prompts are reusable prompt definitions exposed by an MCP server.

Prompt Definition

Prompt arguments are described using a Zod schema.
The prompt definition uses schema; there is no arguments property on the prompt definition.

Context

Tool and resource callbacks can receive a context object.

ctx.log()

Logs a message using a specified level.
The first argument is the log level and the second is the message.

Authentication

Import the authentication helpers from the server package:

jwksVerifier()

Creates a JWT verifier using a JWKS endpoint.
Use it in the server configuration:
The authentication discriminant is:
not:

NodeOAuthClientProvider

For Node.js OAuth clients, create the provider through its static create() method:
The constructor is private and should not be called directly.

ensureAuthorized()

Ensures that an OAuth provider is authorized for a server.
Both the provider and the target server URL are required. Example:

Authentication Header Forwarding

mcpfy exposes helpers for forwarding supported authentication headers to upstream services.

extractForwardableAuthHeaders

Extracts supported authentication headers from incoming headers.

forwardAuthHeaders

Prepares supported authentication headers for forwarding:

FORWARDABLE_AUTH_HEADER_NAMES

The SDK exports:
This identifies the authentication-related header names that can be forwarded. Applications should not blindly forward arbitrary inbound headers.

Widgets

Widgets can be associated with tools.
The widget name corresponds to the widget directory:
The standard entry point is:
Build widgets using:
For development:
See Widgets.

Widget Content

Widget content can be represented as HTML:
or as a URL:
HTML should not be supplied as a bare string.

Widget Size

Widget dimensions use a width/height tuple:

Widget React APIs

The React integration is available through the widget React package. Common APIs include:
  • useHostProtocol()
  • useCallTool()
  • useToolPayload()
  • CallToolHandle
For detailed React integration, see Widget React.

Widget Bridge

The widget bridge provides communication between widget applications and the MCP host. The package exposes APIs including:
These APIs allow widget applications to communicate with the host runtime.

CLI

mcpfy provides CLI commands for widget development and production builds.

mcpfy dev

Starts the development workflow:

mcpfy build

Builds widget assets for production:
Production deployments should run the build before starting a server that depends on built widgets.

create-mcpfy-app

For a new project, the recommended fast-start command is:
This creates a new mcpfy application using the project scaffolding provided by the SDK ecosystem.

Complete Example

The following example combines the core APIs:
The server exposes:
  • two executable tools
  • one MCP resource
  • an HTTP MCP endpoint
  • structured and text tool responses
For complete guides and usage examples, see the individual documentation pages for servers, clients, tools, resources, prompts, widgets, and authentication.