PromptInvocationContext class
Structured context object passed to MCP prompt handlers.
Provides typed access to the invoked prompt's name, arguments (all values are strings), optional session id, and optional transport metadata.
Example
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}`;
}
});
Constructors
| Prompt |
Build a |
Properties
| arguments | Dictionary of prompt arguments (all values are strings). |
| name | The name of the prompt being invoked. |
| session |
Optional session ID for the invocation. |
| transport | Optional transport metadata. |
Constructor Details
PromptInvocationContext(unknown)
Build a PromptInvocationContext from raw host-supplied trigger data.
Accepts either a parsed object or a JSON string.
new PromptInvocationContext(data: unknown)
Parameters
- data
-
unknown
Property Details
arguments
Dictionary of prompt arguments (all values are strings).
arguments: Record<string, string>
Property Value
Record<string, string>
name
The name of the prompt being invoked.
name: string
Property Value
string
sessionId
Optional session ID for the invocation.
sessionId: string | undefined
Property Value
string | undefined
transport
Optional transport metadata.
transport: Record<string, unknown> | undefined
Property Value
Record<string, unknown> | undefined