MCP Apps Kit - v0.5.0
    Preparing search index...

    Interface ToolContext

    Context provided by the client during tool invocation

    Contains metadata hints from the host platform (ChatGPT, MCP Apps hosts, etc.). All fields are optional as availability depends on the client.

    handler: async (input, context) => {
    if (context.locale) {
    // Format response in user's preferred language
    }
    if (context.userLocation?.timezone) {
    // Adjust times to user's timezone
    }
    }
    interface ToolContext {
        locale?: string;
        raw?: Record<string, unknown>;
        state?: Map<string, unknown>;
        subject?: string;
        userAgent?: string;
        userLocation?: UserLocation;
        widgetSessionId?: string;
    }
    Index

    Properties

    locale?: string

    User's preferred locale (BCP 47 format). Use for localization and formatting.

    "en-US", "fr-FR", "ja-JP"
    
    raw?: Record<string, unknown>

    Raw _meta object from the client. Access protocol-specific fields not mapped to typed properties.

    state?: Map<string, unknown>

    Shared state map populated by middleware. Middleware can use state.set() to share data with tool handlers.

    // In middleware
    context.state.set("userId", "user-123");

    // In tool handler
    const userId = context.state?.get("userId");
    subject?: string

    User identifier from the request context.

    • With OAuth enabled: Contains the authenticated user's subject (sub claim) from the verified JWT token. This is a verified identity that can be used for authorization and user-specific logic.
    • Without OAuth: May contain an anonymized identifier for rate limiting or session correlation. Do not use for authentication or PII in this case.

    When OAuth is configured, this value is server-validated and overrides any client-provided value. Access full auth details via context.raw?.["mcp-apps-kit/auth"].

    handler: async (input, context) => {
    // With OAuth: verified user identifier
    const userId = context.subject;

    // Access full auth context (scopes, clientId, token, etc.)
    const auth = context.raw?.["mcp-apps-kit/auth"];
    const scopes = auth?.scopes ?? [];

    return { message: `Hello, ${userId}!` };
    }
    userAgent?: string

    Client user agent string. Use for analytics or client-specific formatting. Never rely on this for authentication.

    userLocation?: UserLocation

    Coarse user location. Use for localization, timezone adjustments, or regional content.

    widgetSessionId?: string

    Widget session ID for component correlation. Stable across tool calls within the same widget instance.