Skip to main content
The createSdkMcpServer() function creates an MCP server instance that runs in the same process as your SDK application.

Import

Signature

Parameters

CreateSdkMcpServerOptions
required
Configuration options for the MCP server.

CreateSdkMcpServerOptions

string
required
Unique name for the MCP server. Used to identify the server in logs and error messages.
string
default:"'1.0.0'"
Server version string. Used for compatibility and debugging.
SdkMcpToolDefinition[]
Array of tools created with the tool() function.

Return Value

object
A server configuration object that can be passed directly to the mcpServers option in query().

Examples

Basic Server with One Tool

Server with Multiple Tools

Multiple Servers

Server with Stateful Tools

Server with Async Operations

Server with Environment Access

Validation

Tool Name Validation

The function validates that all tools have unique names:

Server Name Validation

Server name must be a non-empty string:

Error Handling

Creation Errors

Runtime Tool Errors

Tool errors are caught and returned to the AI:
Better approach - handle errors explicitly:

Server Capabilities

The MCP server automatically advertises its capabilities based on provided tools:

Usage in Queries

Direct Usage

Reuse Across Queries

Mixed with External Servers

Best Practices

2. Use Descriptive Names

3. Specify Versions

4. Keep Servers Focused

5. Initialize Once, Reuse

See Also