@backblaze-labs/b2-mcp
    Preparing search index...

    Function createPreparedMcpServerFactory

    • Create the per-request MCP server factory used by the MCP HTTP handler.

      Parameters

      • preparedRequestScope: AsyncLocalStorage<PreparedMcpRequest>

        AsyncLocalStorage carrying resolved credentials and capabilities for the current request.

      • createServerForRequest: (
            config: B2Config,
            capabilities?: string[] | null,
            options?: CreateServerOptions,
        ) => McpServer

        Server factory to invoke for each request.

          • (
                config: B2Config,
                capabilities?: string[] | null,
                options?: CreateServerOptions,
            ): McpServer
          • Build the MCP server and register the B2 tool surface.

            Registration is capability-aware: when capabilities is a non-null array, only tools the key can use are registered (per src/utils/tool-capabilities), and Partner tools register only with a distinct master key. null/undefined registers the full surface (operator override and legacy unit tests); an empty array is a fail-closed capability set, not "unknown".

            Credential model: B2_APPLICATION_KEY_ID / B2_APPLICATION_KEY is the application key that drives the B2 native API, S3, and key management. Only the Partner API tools use a master key (B2_MASTER_KEY_ID / B2_MASTER_KEY, optional); a single non-master key covers everything else. B2's S3 endpoint rejects master keys, which is why the application key is the primary credential.

            Parameters

            • config: B2Config

              Resolved B2 credentials and runtime policy.

            • Optionalcapabilities: string[] | null

              Capabilities returned by B2 authorize, null for the full-surface operator override, or an empty array to fail closed.

            • options: CreateServerOptions = {}

              Optional caller-scoped controls such as verified OAuth scopes.

            Returns McpServer

            The configured MCP server instance.

            const config = loadConfig();
            const capabilities = await fetchCapabilities(config);
            const server = createServer(config, capabilities);

      Returns (ctx: McpRequestContext) => McpServer

      MCP SDK server factory bound to request-local prepared state.

      Error when called outside a prepared request scope.