Skip to main content
The main class for building MCP servers with Skybridge.

Import

import { McpServer } from "skybridge/server";

Constructor

const server = new McpServer(
  serverInfo: { name: string; version: string },
  options: McpServerOptions
);

Parameters

ParameterTypeDescription
serverInfo.namestringName of your MCP server
serverInfo.versionstringVersion of your server
optionsMcpServerOptionsConfiguration options

Options

type McpServerOptions = {
  // Additional options as needed
};

Methods

registerWidget

Register an interactive widget with UI. See registerWidget for details.
server.registerWidget(name, resourceConfig, toolConfig, handler);

registerTool

Register a tool without UI (inherited from MCP SDK).
server.registerTool(name, config, handler);

Type Export Pattern

Export the server type for client-side type inference:
const server = new McpServer({ name: "my-app", version: "1.0" }, {})
  .registerWidget("search", {}, { inputSchema: { query: z.string() } }, async ({ query }) => {
    return { structuredContent: { results: [] } };
  });

// Export for generateHelpers
export type AppType = typeof server;

Method Chaining

You must use method chaining for type inference to work. See Type Safety: Method Chaining for details.

Example

import { McpServer } from "skybridge/server";
import { z } from "zod";

const server = new McpServer(
  { name: "hotel-booking", version: "1.0.0" },
  {}
)
  .registerWidget("search-hotels", {
    description: "Search for hotels",
  }, {
    inputSchema: {
      city: z.string().describe("City to search"),
      checkIn: z.string().describe("Check-in date"),
      checkOut: z.string().describe("Check-out date"),
      guests: z.number().optional().default(2),
    },
    outputSchema: {
      hotels: z.array(z.object({
        id: z.string(),
        name: z.string(),
        price: z.number(),
        rating: z.number(),
      })),
    },
  }, async ({ city, checkIn, checkOut, guests }) => {
    const hotels = await searchHotels({ city, checkIn, checkOut, guests });

    return {
      content: [{ type: "text", text: `Found ${hotels.length} hotels in ${city}` }],
      structuredContent: { hotels },
    };
  })
  .registerWidget("hotel-details", {
    description: "Get hotel details",
  }, {
    inputSchema: {
      hotelId: z.string(),
    },
  }, async ({ hotelId }) => {
    const hotel = await getHotel(hotelId);

    return {
      content: [{ type: "text", text: `Showing details for ${hotel.name}` }],
      structuredContent: hotel,
    };
  });

export type AppType = typeof server;
export default server;