create

Result<McpServer, String> create(

  1. Implementation serverInfo, {
  2. ServerOptions? options,
})

Create McpServer.

Returns Success with the server or Error with message on failure.

Implementation

static Result<McpServer, String> create(
  Implementation serverInfo, {
  ServerOptions? options,
}) {
  try {
    final sdkModule = requireModule(
      '@modelcontextprotocol/sdk/server/mcp.js',
    );
    final mcpServerClass = (sdkModule as JSObject)['McpServer'];
    final jsMcpServerClass = mcpServerClass as JSFunction;

final jsServerInfo = _implementationToJs(serverInfo); final jsOptions = options != null ? _serverOptionsToJs(options) : null;

final mcpServer = jsOptions != null ? jsMcpServerClass.callAsConstructor<JSObject>( jsServerInfo, jsOptions, ) : jsMcpServerClass.callAsConstructor<JSObject>(jsServerInfo);

return Success(McpServer._(mcpServer)); } catch (e) { return Error('Failed to create MCP server: $e'); } }