# 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.
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. |
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. |
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.
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. |
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"). |
The current builder instance for chaining.
this