PromptInvocationContext class

傳遞給 MCP 提示程式處理器的結構化上下文物件。

提供對被喚出提示字元名稱、參數(所有值皆為字串)、可選的工作階段 ID 及可選傳輸元資料的類型存取。

範例

app.mcpPrompt('codeReview', {
    promptName: 'code_review',
    promptArguments: [
        { name: 'code', description: 'The code to review', required: true },
        { name: 'language', description: 'Programming language' }
    ],
    handler: async (ctx: PromptInvocationContext) => {
        const code = ctx.arguments.code ?? '';
        const language = ctx.arguments.language ?? 'typescript';
        return `Review this ${language} code:\n${code}`;
    }
});

建構函式

PromptInvocationContext(unknown)

從主機提供的原始觸發資料建立一個 PromptInvocationContext 。 接受解析過的物件或 JSON 字串。

屬性

arguments

提示參數字典(所有值皆為字串)。

name

被喚起的提示名稱。

sessionId

呼叫時可選的會話 ID。

transport

可選的傳輸元資料。

建構函式詳細資料

PromptInvocationContext(unknown)

從主機提供的原始觸發資料建立一個 PromptInvocationContext 。 接受解析過的物件或 JSON 字串。

new PromptInvocationContext(data: unknown)

參數

data

unknown

屬性詳細資料

arguments

提示參數字典(所有值皆為字串)。

arguments: Record<string, string>

屬性值

Record<string, string>

name

被喚起的提示名稱。

name: string

屬性值

string

sessionId

呼叫時可選的會話 ID。

sessionId: string | undefined

屬性值

string | undefined

transport

可選的傳輸元資料。

transport: Record<string, unknown> | undefined

屬性值

Record<string, unknown> | undefined