API Reference
This page provides a reference for the public APIs exposed bymcpfy-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:
icon
Optional server icon.
mcpfy supports remote URLs, data URIs, local file paths, and file: URLs.
auth
Optional HTTP authentication configuration.
widgetsDir
Optional widget root directory.
The default is:
server.tool()
Registers a tool with the MCP server.
namedescriptionschema- optional widget configuration
Tool Return Helpers
text()
Creates a text result:
markdown()
Creates a Markdown result:
object()
Creates a structured result:
server.listen()
Starts the MCP server.
stdio
HTTP
Port Resolution
The HTTP port is resolved in this order:listen()option--portcommand-line argumentPORTenvironment variable3000
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.
Client
Import the client from:MCPClient
Creates an MCP client.
HTTP Server
stdio Server
transport property is not required for stdio configuration.
Resources
server.resource()
Registers a resource.
server.resourceTemplate()
Registers a resource template.
The callback signature receives:
uri— resolved resource URIparams— values extracted from the templatectx— request context
Prompts
Prompts are reusable prompt definitions exposed by an MCP server.Prompt Definition
Prompt arguments are described using a Zod schema.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.
Authentication
Import the authentication helpers from the server package:jwksVerifier()
Creates a JWT verifier using a JWKS endpoint.
NodeOAuthClientProvider
For Node.js OAuth clients, create the provider through its static create() method:
ensureAuthorized()
Ensures that an OAuth provider is authorized for a server.
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:
Widgets
Widgets can be associated with tools.Widget Content
Widget content can be represented as HTML: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
Widget Bridge
The widget bridge provides communication between widget applications and the MCP host. The package exposes APIs including:CLI
mcpfy provides CLI commands for widget development and production builds.mcpfy dev
Starts the development workflow:mcpfy build
Builds widget assets for production:
create-mcpfy-app
For a new project, the recommended fast-start command is:
Complete Example
The following example combines the core APIs:- two executable tools
- one MCP resource
- an HTTP MCP endpoint
- structured and text tool responses

