Class

Builder

Builder(nameopt, versionopt, toolsopt)

Constructor

# new Builder(nameopt, versionopt, toolsopt)

Collects MCP configuration including a semantic version, a name, and a registry of tools, offering chainable methods and a final build step to produce a ready-to-use ModelContextProtocol.

Fluent builder for creating a configured ModelContextProtocol instance.

sequenceDiagram participant Dev as Developer participant B as Builder participant MCP as ModelContextProtocol Dev->>B: setName("Example") B-->>Dev: Builder Dev->>B: setVersion("1.0.0") B-->>Dev: Builder Dev->>B: addTool(tool) B-->>Dev: Builder Dev->>B: build() B->>MCP: new ModelContextProtocol(FastMCP) B-->>Dev: ModelContextProtocol
Parameters:
Name Type Attributes Description
name string <optional>

The name of the MCP instance to build.

version string <optional>

The semantic version of the MCP instance.

tools Record.<string, Tool.<any, any>> <optional>

A map of tool configurations indexed by tool name.

View Source mcp/ModelContextProtocol.ts, line 49

Example
// Build a new MCP with a single tool
const mcp = ModelContextProtocol.builder
  .setName("Example")
  .setVersion("1.0.0")
  .addTool({ name: "do", description: "", parameters: z.any(), execute: async () => "ok" })
  .build();

Methods

# addTool(config) → {this}

Adds a tool configuration by its unique name to the internal registry, throwing if a tool with the same name already exists.

Registers a new tool in the builder.

Parameters:
Name Type Description
config Tool.<Auth, any>

The tool configuration object, including a unique name and an execute handler.

View Source mcp/ModelContextProtocol.ts, line 221

The current builder instance for chaining.

this

# build() → {ModelContextProtocol.<Auth>}

Validates required fields (name and version), constructs a FastMCP instance, registers all configured tools, and returns a ModelContextProtocol wrapping the MCP.

Finalizes the configuration and produces a ModelContextProtocol instance.

View Source mcp/ModelContextProtocol.ts, line 229

A fully initialized ModelContextProtocol instance.

ModelContextProtocol.<Auth>

# setName(value) → {this}

Assigns a human-readable identifier to the builder configuration and enables method chaining.

Sets the MCP instance name.

Parameters:
Name Type Description
value string

The name to assign to the MCP instance.

View Source mcp/ModelContextProtocol.ts, line 204

The current builder instance for chaining.

this

# setVersion(value) → {this}

Parses the provided value against semantic versioning and stores the normalized version; enables method chaining.

Sets and validates the semantic version for the MCP instance.

Parameters:
Name Type Description
value string

The semantic version string (e.g., "1.2.3").

View Source mcp/ModelContextProtocol.ts, line 212

The current builder instance for chaining.

this