@node-in-layers/mcp-server
    Preparing search index...

    Interface McpServerMcp

    The public interface returned by create() in mcp.ts and stored in the MCP layer of the Node-in-Layers system context.

    Typical usage:

    const mcpServer = mcp.create(context)
    mcpServer.addTool(myTool)
    await mcpServer.start(systemContext)
    interface McpServerMcp {
        addAdditionalRoute: (route: ExpressRoute) => void;
        addAnnotatedFunction: <
            TIn extends Readonly<{ [s: string]: JsonAble }>,
            TOut extends void | Readonly<{ [s: string]: JsonAble }>,
        >(
            annotatedFunction: NilAnnotatedFunction<TIn, TOut>,
            options?: { description?: string; name?: string },
        ) => void;
        addCrossLayerPropMiddleware: (middleware: CrossLayerPropMiddleware) => void;
        addPreRouteMiddleware: (middleware: ExpressMiddleware) => void;
        addTool: (tool: McpTool) => void;
        getApp: <
            T extends
                Readonly<
                    {
                        "@node-in-layers/mcp-server": {
                            hiddenPaths?: string[];
                            hideComponents?: {
                                allModels?: boolean;
                                domains?: string[];
                                paths?: readonly string[];
                            };
                            logging?: {
                                requestLogGetData?: (req: Request) => Record<string, any>;
                                requestLogLevel?: LogLevelNames;
                                responseLogGetData?: (req: Request) => Record<string, any>;
                                responseLogLevel?: LogLevelNames;
                            };
                            server: {
                                connection: | Without<
                                    Readonly<{ type: ... }>,
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                > & Readonly<
                                    {
                                        headers?: (...)
                                        | (...);
                                        retry?: (...) | (...);
                                        timeout?: (...) | (...);
                                        type: "http";
                                        url: string;
                                    },
                                >
                                | Without<
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                    Readonly<{ type: ... }>,
                                > & Readonly<{ type: "cli" }>;
                            };
                            startHere?: {
                                description?: string;
                                examplesOfUse?: readonly Readonly<
                                    {
                                        description?: ...;
                                        details?: ...;
                                        example?: ...;
                                        name: ...;
                                        tags?: ...;
                                        value?: ...;
                                    },
                                >[];
                                hideDefaultSystemEntries?: boolean;
                                includeDomains?: boolean;
                                includeFeatures?: boolean;
                                name?: string;
                            };
                            stateful?: boolean;
                            systemDescription?: { description?: string; version?: string };
                            version?: string;
                        };
                    },
                > & Readonly<
                    {
                        "@node-in-layers/core": CoreConfig;
                        environment: string;
                        systemName: string;
                    },
                >,
        >(
            systemContext: any,
            options?: Readonly<
                { jsonBodyParser?: { limit?: string; strict?: boolean } },
            >,
        ) => Promise<Express>;
        set: (key: string, value: any) => void;
        start: <
            T extends
                Readonly<
                    {
                        "@node-in-layers/mcp-server": {
                            hiddenPaths?: string[];
                            hideComponents?: {
                                allModels?: boolean;
                                domains?: string[];
                                paths?: readonly string[];
                            };
                            logging?: {
                                requestLogGetData?: (req: Request) => Record<string, any>;
                                requestLogLevel?: LogLevelNames;
                                responseLogGetData?: (req: Request) => Record<string, any>;
                                responseLogLevel?: LogLevelNames;
                            };
                            server: {
                                connection: | Without<
                                    Readonly<{ type: ... }>,
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                > & Readonly<
                                    {
                                        headers?: (...)
                                        | (...);
                                        retry?: (...) | (...);
                                        timeout?: (...) | (...);
                                        type: "http";
                                        url: string;
                                    },
                                >
                                | Without<
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                    Readonly<{ type: ... }>,
                                > & Readonly<{ type: "cli" }>;
                            };
                            startHere?: {
                                description?: string;
                                examplesOfUse?: readonly Readonly<
                                    {
                                        description?: ...;
                                        details?: ...;
                                        example?: ...;
                                        name: ...;
                                        tags?: ...;
                                        value?: ...;
                                    },
                                >[];
                                hideDefaultSystemEntries?: boolean;
                                includeDomains?: boolean;
                                includeFeatures?: boolean;
                                name?: string;
                            };
                            stateful?: boolean;
                            systemDescription?: { description?: string; version?: string };
                            version?: string;
                        };
                    },
                > & Readonly<
                    {
                        "@node-in-layers/core": CoreConfig;
                        environment: string;
                        systemName: string;
                    },
                >,
        >(
            systemContext: any,
            options?: Readonly<
                { jsonBodyParser?: { limit?: string; strict?: boolean } },
            >,
        ) => Promise<void>;
    }
    Index

    Properties

    addAdditionalRoute: (route: ExpressRoute) => void

    Registers an additional Express route alongside the MCP endpoint. Must be called before start() or getApp().

    Type Declaration

    addAnnotatedFunction: <
        TIn extends Readonly<{ [s: string]: JsonAble }>,
        TOut extends void | Readonly<{ [s: string]: JsonAble }>,
    >(
        annotatedFunction: NilAnnotatedFunction<TIn, TOut>,
        options?: { description?: string; name?: string },
    ) => void

    Adds an annotated function as a tool.

    Type Declaration

      • <
            TIn extends Readonly<{ [s: string]: JsonAble }>,
            TOut extends void | Readonly<{ [s: string]: JsonAble }>,
        >(
            annotatedFunction: NilAnnotatedFunction<TIn, TOut>,
            options?: { description?: string; name?: string },
        ): void
      • Type Parameters

        • TIn extends Readonly<{ [s: string]: JsonAble }>
        • TOut extends void | Readonly<{ [s: string]: JsonAble }>

        Parameters

        • annotatedFunction: NilAnnotatedFunction<TIn, TOut>

          The annotated function to add as a tool.

        • Optionaloptions: { description?: string; name?: string }
          • Optionaldescription?: string

            A replacement description for the function.

          • Optionalname?: string

            A replacement name for the function.

        Returns void

        void

    addCrossLayerPropMiddleware: (middleware: CrossLayerPropMiddleware) => void

    Adds a middleware function that will be called before the MCP route, that can extract information that will be placed into the cross layer props.

    NOTE: If you return "logging" cross layer props, it will be merged in appropriately with the normal cross layer props. This can be useful for adding additional IDS.

    Having said that, NON-"logging" properties, are merged together, and can result in overriding values.

    Type Declaration

    addPreRouteMiddleware: (middleware: ExpressMiddleware) => void

    Registers an Express middleware to run before the MCP route handler. Useful for auth, logging, or rate-limiting. Must be called before start() or getApp().

    Type Declaration

    addTool: (tool: McpTool) => void

    Registers a custom McpTool with the server. Call this before start() or getApp().

    Type Declaration

      • (tool: McpTool): void
      • Parameters

        • tool: McpTool

          The tool definition to register.

        Returns void

    getApp: <
        T extends
            Readonly<
                {
                    "@node-in-layers/mcp-server": {
                        hiddenPaths?: string[];
                        hideComponents?: {
                            allModels?: boolean;
                            domains?: string[];
                            paths?: readonly string[];
                        };
                        logging?: {
                            requestLogGetData?: (req: Request) => Record<string, any>;
                            requestLogLevel?: LogLevelNames;
                            responseLogGetData?: (req: Request) => Record<string, any>;
                            responseLogLevel?: LogLevelNames;
                        };
                        server: {
                            connection: | Without<
                                Readonly<{ type: ... }>,
                                Readonly<
                                    {
                                        headers?: ...;
                                        retry?: ...;
                                        timeout?: ...;
                                        type: ...;
                                        url: ...;
                                    },
                                >,
                            > & Readonly<
                                {
                                    headers?: (...)
                                    | (...);
                                    retry?: (...) | (...);
                                    timeout?: (...) | (...);
                                    type: "http";
                                    url: string;
                                },
                            >
                            | Without<
                                Readonly<
                                    {
                                        headers?: ...;
                                        retry?: ...;
                                        timeout?: ...;
                                        type: ...;
                                        url: ...;
                                    },
                                >,
                                Readonly<{ type: ... }>,
                            > & Readonly<{ type: "cli" }>;
                        };
                        startHere?: {
                            description?: string;
                            examplesOfUse?: readonly Readonly<
                                {
                                    description?: ...;
                                    details?: ...;
                                    example?: ...;
                                    name: ...;
                                    tags?: ...;
                                    value?: ...;
                                },
                            >[];
                            hideDefaultSystemEntries?: boolean;
                            includeDomains?: boolean;
                            includeFeatures?: boolean;
                            name?: string;
                        };
                        stateful?: boolean;
                        systemDescription?: { description?: string; version?: string };
                        version?: string;
                    };
                },
            > & Readonly<
                {
                    "@node-in-layers/core": CoreConfig;
                    environment: string;
                    systemName: string;
                },
            >,
    >(
        systemContext: any,
        options?: Readonly<
            { jsonBodyParser?: { limit?: string; strict?: boolean } },
        >,
    ) => Promise<Express>

    Builds and returns the configured Express app without starting the HTTP listener. Useful when you want to integrate the MCP server into an existing Express application or test the app directly.

    Throws if the connection type is not 'http'.

    Type Declaration

      • <
            T extends
                Readonly<
                    {
                        "@node-in-layers/mcp-server": {
                            hiddenPaths?: string[];
                            hideComponents?: {
                                allModels?: boolean;
                                domains?: string[];
                                paths?: readonly string[];
                            };
                            logging?: {
                                requestLogGetData?: (req: Request) => Record<string, any>;
                                requestLogLevel?: LogLevelNames;
                                responseLogGetData?: (req: Request) => Record<string, any>;
                                responseLogLevel?: LogLevelNames;
                            };
                            server: {
                                connection: | Without<
                                    Readonly<{ type: ... }>,
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                > & Readonly<
                                    {
                                        headers?: (...)
                                        | (...);
                                        retry?: (...) | (...);
                                        timeout?: (...) | (...);
                                        type: "http";
                                        url: string;
                                    },
                                >
                                | Without<
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                    Readonly<{ type: ... }>,
                                > & Readonly<{ type: "cli" }>;
                            };
                            startHere?: {
                                description?: string;
                                examplesOfUse?: readonly Readonly<
                                    {
                                        description?: ...;
                                        details?: ...;
                                        example?: ...;
                                        name: ...;
                                        tags?: ...;
                                        value?: ...;
                                    },
                                >[];
                                hideDefaultSystemEntries?: boolean;
                                includeDomains?: boolean;
                                includeFeatures?: boolean;
                                name?: string;
                            };
                            stateful?: boolean;
                            systemDescription?: { description?: string; version?: string };
                            version?: string;
                        };
                    },
                > & Readonly<
                    {
                        "@node-in-layers/core": CoreConfig;
                        environment: string;
                        systemName: string;
                    },
                >,
        >(
            systemContext: any,
            options?: Readonly<
                { jsonBodyParser?: { limit?: string; strict?: boolean } },
            >,
        ): Promise<Express>
      • Type Parameters

        • T extends Readonly<
              {
                  "@node-in-layers/mcp-server": {
                      hiddenPaths?: string[];
                      hideComponents?: {
                          allModels?: boolean;
                          domains?: string[];
                          paths?: readonly string[];
                      };
                      logging?: {
                          requestLogGetData?: (req: Request) => Record<string, any>;
                          requestLogLevel?: LogLevelNames;
                          responseLogGetData?: (req: Request) => Record<string, any>;
                          responseLogLevel?: LogLevelNames;
                      };
                      server: {
                          connection: | Without<
                              Readonly<{ type: ... }>,
                              Readonly<
                                  { headers?: ...; retry?: ...; timeout?: ...; type: ...; url: ... },
                              >,
                          > & Readonly<
                              {
                                  headers?: (...)
                                  | (...);
                                  retry?: (...) | (...);
                                  timeout?: (...) | (...);
                                  type: "http";
                                  url: string;
                              },
                          >
                          | Without<
                              Readonly<
                                  { headers?: ...; retry?: ...; timeout?: ...; type: ...; url: ... },
                              >,
                              Readonly<{ type: ... }>,
                          > & Readonly<{ type: "cli" }>;
                      };
                      startHere?: {
                          description?: string;
                          examplesOfUse?: readonly Readonly<
                              {
                                  description?: ...;
                                  details?: ...;
                                  example?: ...;
                                  name: ...;
                                  tags?: ...;
                                  value?: ...;
                              },
                          >[];
                          hideDefaultSystemEntries?: boolean;
                          includeDomains?: boolean;
                          includeFeatures?: boolean;
                          name?: string;
                      };
                      stateful?: boolean;
                      systemDescription?: { description?: string; version?: string };
                      version?: string;
                  };
              },
          > & Readonly<
              {
                  "@node-in-layers/core": CoreConfig;
                  environment: string;
                  systemName: string;
              },
          >

        Parameters

        • systemContext: any

          The fully-initialised Node-in-Layers system context.

        • Optionaloptions: Readonly<{ jsonBodyParser?: { limit?: string; strict?: boolean } }>

          Optional Express body-parser settings.

        Returns Promise<Express>

    set: (key: string, value: any) => void

    Calls app.set(key, value) on the underlying Express app. Must be called before start() or getApp().

    Type Declaration

      • (key: string, value: any): void
      • Parameters

        • key: string

          Express setting name (e.g. 'trust proxy').

        • value: any

          Value to assign.

        Returns void

    start: <
        T extends
            Readonly<
                {
                    "@node-in-layers/mcp-server": {
                        hiddenPaths?: string[];
                        hideComponents?: {
                            allModels?: boolean;
                            domains?: string[];
                            paths?: readonly string[];
                        };
                        logging?: {
                            requestLogGetData?: (req: Request) => Record<string, any>;
                            requestLogLevel?: LogLevelNames;
                            responseLogGetData?: (req: Request) => Record<string, any>;
                            responseLogLevel?: LogLevelNames;
                        };
                        server: {
                            connection: | Without<
                                Readonly<{ type: ... }>,
                                Readonly<
                                    {
                                        headers?: ...;
                                        retry?: ...;
                                        timeout?: ...;
                                        type: ...;
                                        url: ...;
                                    },
                                >,
                            > & Readonly<
                                {
                                    headers?: (...)
                                    | (...);
                                    retry?: (...) | (...);
                                    timeout?: (...) | (...);
                                    type: "http";
                                    url: string;
                                },
                            >
                            | Without<
                                Readonly<
                                    {
                                        headers?: ...;
                                        retry?: ...;
                                        timeout?: ...;
                                        type: ...;
                                        url: ...;
                                    },
                                >,
                                Readonly<{ type: ... }>,
                            > & Readonly<{ type: "cli" }>;
                        };
                        startHere?: {
                            description?: string;
                            examplesOfUse?: readonly Readonly<
                                {
                                    description?: ...;
                                    details?: ...;
                                    example?: ...;
                                    name: ...;
                                    tags?: ...;
                                    value?: ...;
                                },
                            >[];
                            hideDefaultSystemEntries?: boolean;
                            includeDomains?: boolean;
                            includeFeatures?: boolean;
                            name?: string;
                        };
                        stateful?: boolean;
                        systemDescription?: { description?: string; version?: string };
                        version?: string;
                    };
                },
            > & Readonly<
                {
                    "@node-in-layers/core": CoreConfig;
                    environment: string;
                    systemName: string;
                },
            >,
    >(
        systemContext: any,
        options?: Readonly<
            { jsonBodyParser?: { limit?: string; strict?: boolean } },
        >,
    ) => Promise<void>

    Starts the MCP server. For HTTP connections, binds an Express app to the configured port. For CLI connections, connects the stdio transport.

    Type Declaration

      • <
            T extends
                Readonly<
                    {
                        "@node-in-layers/mcp-server": {
                            hiddenPaths?: string[];
                            hideComponents?: {
                                allModels?: boolean;
                                domains?: string[];
                                paths?: readonly string[];
                            };
                            logging?: {
                                requestLogGetData?: (req: Request) => Record<string, any>;
                                requestLogLevel?: LogLevelNames;
                                responseLogGetData?: (req: Request) => Record<string, any>;
                                responseLogLevel?: LogLevelNames;
                            };
                            server: {
                                connection: | Without<
                                    Readonly<{ type: ... }>,
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                > & Readonly<
                                    {
                                        headers?: (...)
                                        | (...);
                                        retry?: (...) | (...);
                                        timeout?: (...) | (...);
                                        type: "http";
                                        url: string;
                                    },
                                >
                                | Without<
                                    Readonly<
                                        {
                                            headers?: ...;
                                            retry?: ...;
                                            timeout?: ...;
                                            type: ...;
                                            url: ...;
                                        },
                                    >,
                                    Readonly<{ type: ... }>,
                                > & Readonly<{ type: "cli" }>;
                            };
                            startHere?: {
                                description?: string;
                                examplesOfUse?: readonly Readonly<
                                    {
                                        description?: ...;
                                        details?: ...;
                                        example?: ...;
                                        name: ...;
                                        tags?: ...;
                                        value?: ...;
                                    },
                                >[];
                                hideDefaultSystemEntries?: boolean;
                                includeDomains?: boolean;
                                includeFeatures?: boolean;
                                name?: string;
                            };
                            stateful?: boolean;
                            systemDescription?: { description?: string; version?: string };
                            version?: string;
                        };
                    },
                > & Readonly<
                    {
                        "@node-in-layers/core": CoreConfig;
                        environment: string;
                        systemName: string;
                    },
                >,
        >(
            systemContext: any,
            options?: Readonly<
                { jsonBodyParser?: { limit?: string; strict?: boolean } },
            >,
        ): Promise<void>
      • Type Parameters

        • T extends Readonly<
              {
                  "@node-in-layers/mcp-server": {
                      hiddenPaths?: string[];
                      hideComponents?: {
                          allModels?: boolean;
                          domains?: string[];
                          paths?: readonly string[];
                      };
                      logging?: {
                          requestLogGetData?: (req: Request) => Record<string, any>;
                          requestLogLevel?: LogLevelNames;
                          responseLogGetData?: (req: Request) => Record<string, any>;
                          responseLogLevel?: LogLevelNames;
                      };
                      server: {
                          connection: | Without<
                              Readonly<{ type: ... }>,
                              Readonly<
                                  { headers?: ...; retry?: ...; timeout?: ...; type: ...; url: ... },
                              >,
                          > & Readonly<
                              {
                                  headers?: (...)
                                  | (...);
                                  retry?: (...) | (...);
                                  timeout?: (...) | (...);
                                  type: "http";
                                  url: string;
                              },
                          >
                          | Without<
                              Readonly<
                                  { headers?: ...; retry?: ...; timeout?: ...; type: ...; url: ... },
                              >,
                              Readonly<{ type: ... }>,
                          > & Readonly<{ type: "cli" }>;
                      };
                      startHere?: {
                          description?: string;
                          examplesOfUse?: readonly Readonly<
                              {
                                  description?: ...;
                                  details?: ...;
                                  example?: ...;
                                  name: ...;
                                  tags?: ...;
                                  value?: ...;
                              },
                          >[];
                          hideDefaultSystemEntries?: boolean;
                          includeDomains?: boolean;
                          includeFeatures?: boolean;
                          name?: string;
                      };
                      stateful?: boolean;
                      systemDescription?: { description?: string; version?: string };
                      version?: string;
                  };
              },
          > & Readonly<
              {
                  "@node-in-layers/core": CoreConfig;
                  environment: string;
                  systemName: string;
              },
          >

        Parameters

        • systemContext: any

          The fully-initialised Node-in-Layers system context, used to resolve features and models at runtime.

        • Optionaloptions: Readonly<{ jsonBodyParser?: { limit?: string; strict?: boolean } }>

          Optional Express body-parser settings.

        Returns Promise<void>