mcp-use TypeScript API
    Preparing search index...

    Interface RequestClientContext

    Per-request client metadata and capability queries.

    Reads only the current request's metadata — never session state.

    interface RequestClientContext {
        can(capability: string): boolean;
        capabilities(): {};
        extension(
            id: string,
        ):
            | {
                [key: string]: | string
                | number
                | boolean
                | (
                    { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
                )
                | (
                    string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                )[]
                | null;
            }
            | undefined;
        info(): Partial<Implementation>;
        supportsViews(): boolean;
        user(): UserContext | undefined;
    }
    Index
    • Checks whether this request declares a top-level client capability.

      Parameters

      • capability: string

        Capability name such as sampling, elicitation, roots, or extensions.

      Returns boolean

      true when the current request advertises the capability.

      if (ctx.client.can("elicitation")) {
      // Shape the result for an elicitation-capable client.
      }
    • Returns the capabilities declared by the client for this request.

      The returned object is a shallow copy. Requests without the modern metadata envelope return an empty object.

      Returns {}

      const capabilities = ctx.client.capabilities();
      const supportsFormElicitation = capabilities.elicitation?.form !== undefined;
    • Returns one extension settings object declared for this request.

      Parameters

      • id: string

        Namespaced extension identifier, such as io.modelcontextprotocol/ui.

      Returns
          | {
              [key: string]: | string
              | number
              | boolean
              | (
                  { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
              )
              | (
                  string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
              )[]
              | null;
          }
          | undefined

      A shallow copy of the extension settings, or undefined when the current request does not advertise the extension.

      const ui = ctx.client.extension("io.modelcontextprotocol/ui");
      
    • Returns the client implementation metadata declared for this request.

      Valid modern requests include name and version. The partial return type preserves v1 ergonomics for legacy requests without an envelope. The returned object is a shallow copy.

      Returns Partial<Implementation>

      const { name, version } = ctx.client.info();
      
    • Whether this request's client advertises MCP Apps / UI support.

      True when the client declares the io.modelcontextprotocol/ui extension with text/html;profile=mcp-app in mimeTypes. Legacy (non-envelope) requests always return false.

      Returns boolean

      if (ctx.client.supportsViews()) {
      // Return a view-optimized result.
      }
    • Returns normalized OpenAI-specific end-user hints for this request.

      The data comes from ordinary request _meta, not the MCP client-info envelope. It is client-reported and must not be used for authentication or authorization. Each call returns a fresh object, including a fresh location object. Requests without recognized metadata return undefined.

      Returns UserContext | undefined

      const caller = ctx.client.user();
      const locale = caller?.locale ?? "en";