mcp-use TypeScript API
    Preparing search index...

    Interface OAuthProviderHost<TUser>

    Server surface handed to a provider's CustomOAuthProviderOptions.setup hook while the server mounts.

    The hook runs once, after the canonical resource is resolved and before the first request is served, so everything registered here participates in the same per-request registry replay as user registrations. Provider-owned tools, resources, resource templates, and prompts go through the same OAuth gate as application items, including a tool's securitySchemes on a mixedAuth server, and their callbacks receive ctx.auth with the provider's user type. The host is only usable while the hook runs.

    interface OAuthProviderHost<TUser> {
        basePath: string;
        mixedAuth: boolean;
        resourceUrl: URL;
        instructions(transform: (current: string | undefined) => string): void;
        listTools(): readonly Readonly<ToolDefinition>[];
        prompt<T extends PromptDefinition>(
            definition: T,
            callback: PromptCallback<InferPromptInput<T>, TUser, true>,
        ): void;
        resource<T extends ResourceDefinition>(
            definition: T,
            callback: ResourceCallback<TUser, true>,
        ): void;
        resourceTemplate<const TUriTemplate extends string>(
            definition: ResourceTemplateDefinition<TUriTemplate>,
            callback: ResourceTemplateCallback<
                string extends TUriTemplate
                    ? Record<TUriTemplate, TemplateVariableValue>
                    : { [K in string]: TemplateVariableValue },
                TUser,
                true,
            >,
        ): void;
        tool<const T extends ToolDefinition>(
            definition: T,
            callback: ToolCallback<
                InferToolInput<T>,
                InferToolOutput<T>,
                TUser,
                ToolOAuthMode<TUser, DefinitionSecuritySchemes<T>>,
            >,
        ): ToolRef<InferToolName<T>, InferToolInput<T>, InferToolOutput<T>>;
        use<
            P extends
                | "mcp:*"
                | "mcp:prompts/get"
                | "mcp:prompts/list"
                | "mcp:resources/list"
                | "mcp:resources/read"
                | "mcp:tools/call"
                | "mcp:tools/list",
        >(
            pattern: P,
            handler: McpMiddlewareFnFor<P>,
        ): void;
    }

    Type Parameters

    • TUser

      The provider's user type, exposed as ctx.auth.user.

    Index
    basePath: string

    MCP endpoint base path, for example /mcp.

    mixedAuth: boolean

    Whether the server was constructed with mixedAuth: true, so signed-out clients can connect, list, and call noauth tools. A provider that needs anonymous discovery can throw from setup when this is false.

    resourceUrl: URL

    Resolved canonical MCP resource URL (the RFC 8707 resource).

    • Rewrites the instructions text advertised to clients. The transform receives the current text, including earlier transforms, and returns the text to advertise instead. The caller's config is not mutated.

      Parameters

      • transform: (current: string | undefined) => string

      Returns void

    • Every tool registered so far, application and provider-owned, in registration order. Providers use it to validate the application's tools, for example to refuse a destructive tool that lacks a required _meta tag, or one whose securitySchemes accepts noauth.

      Returns readonly Readonly<ToolDefinition>[]

    • Registers a provider-owned static resource, like server.resource(). Resources always require sign-in, including on a mixedAuth server.

      Type Parameters

      Parameters

      Returns void

      If a resource with the same name is already registered.

    • Registers MCP middleware using the same mcp: patterns accepted by server.use().

      Type Parameters

      • P extends
            | "mcp:*"
            | "mcp:prompts/get"
            | "mcp:prompts/list"
            | "mcp:resources/list"
            | "mcp:resources/read"
            | "mcp:tools/call"
            | "mcp:tools/list"

      Parameters

      Returns void