@azure/functions package

Classes

AppStartContext

Context on a function app during app startup.

AppTerminateContext

Context on a function app during app termination.

Disposable

Represents a type which can release resources, such as event listening or a timer.

HookContext

Base class for all hook context objects

HttpRequest

HTTP request object. Provided to your function when using HTTP Bindings.

HttpResponse

HTTP response class

InvocationContext

Contains metadata and helper methods specific to this invocation

InvocationHookContext

Base class for all invocation hook context objects

LogHookContext

Context on a log

McpAudioContent

An audio content block in an MCP tool response.

McpContentBlock

Abstract base class for MCP tool response content blocks.

The Azure Functions library discriminates content blocks from plain user values using instanceof McpContentBlock, so only instances of the built-in subclasses (McpTextContent, McpImageContent, McpAudioContent, McpResourceLinkContent, McpResourceContent) — or a custom subclass that extends this class — will be treated as content blocks.

Plain object literals like { type: 'text', text: '...' } are not treated as content blocks and will be serialized as JSON text instead.

Extending with custom content block types

If the MCP spec adds a new block type — or your scenario needs a custom one — you can ship your own subclass without any library change. The converter only checks instanceof McpContentBlock and calls JSON.stringify(block), which invokes your toJSON() to produce the wire payload.

Example: adding a hypothetical VideoContent

import { McpContentBlock } from '@azure/functions';

export interface VideoContentInit {
    data: string | Buffer | ArrayBuffer;
    mimeType: string;          // e.g. 'video/mp4'
    durationMs?: number;       // optional field from a hypothetical spec
}

export class VideoContent extends McpContentBlock {
    readonly type = 'video' as const;
    readonly data: string | Buffer | ArrayBuffer;
    readonly mimeType: string;
    readonly durationMs?: number;

    constructor(init: VideoContentInit) {
        super();
        this.data = init.data;
        this.mimeType = init.mimeType;
        this.durationMs = init.durationMs;
    }

    toJSON(): Record<string, unknown> {
        const out: Record<string, unknown> = {
            type: this.type,
            data: toBase64(this.data),
            mimeType: this.mimeType,
        };
        if (this.durationMs !== undefined) out.durationMs = this.durationMs;
        return out;
    }
}

function toBase64(data: string | Buffer | ArrayBuffer): string {
    if (typeof data === 'string') return data;
    if (Buffer.isBuffer(data)) return data.toString('base64');
    return Buffer.from(new Uint8Array(data)).toString('base64');
}

Using a custom block from a tool handler

// Single block
handler: async () => new VideoContent({ data: buf, mimeType: 'video/mp4' })

// Mixed with built-ins + structured content
handler: async () => new McpToolResponse({
    content: [
        new McpTextContent('Detected 3 scenes'),
        new VideoContent({ data: buf, mimeType: 'video/mp4' }),
    ],
    structuredContent: { scenes: 3, confidence: 0.92 },
})

What the library does for you

  • instanceof McpContentBlock treats your subclass identically to built-in blocks.
  • Single-block returns propagate your type string to the outer result; arrays are wrapped as multi_content_result.
  • structuredContent handling, fallback-text synthesis, and nullish passthrough all apply unchanged.

What you must get right in your subclass

  • toJSON() must return the exact wire shape the spec requires for your type.
  • Binary payloads should be base64-encoded in toJSON() (see the toBase64 helper above).
  • Plain object literals are not recognized — you must construct an instance.
McpImageContent

An image content block in an MCP tool response.

McpPromptArgumentBuilder

Fluent builder for declaring MCP prompt arguments in a record-shaped promptArguments map. The key of the map supplies the argument name.

By default arguments are optional; call .isRequired() to mark them required.

Example

promptArguments: {
    function_name: promptArg.describe('The function to document.').isRequired(),
    style: promptArg.describe("Documentation style (e.g., 'concise', 'verbose')."),
}
McpResourceContent

An embedded-resource content block in an MCP tool response.

McpResourceLinkContent

A resource-link content block in an MCP tool response.

McpTextContent

A text content block in an MCP tool response.

McpToolResponse

Full MCP tool response with explicit content blocks and optional structured content. Return an instance of this class from a tool handler when you need full control over both the content array and structuredContent.

return new McpToolResponse({
  content: [
    new McpTextContent('Here is the image'),
    new McpImageContent({ data: base64Data, mimeType: 'image/png' })
  ],
  structuredContent: { imageId: 'logo', format: 'png' }
});
PostInvocationContext

Context on a function after it executes.

PreInvocationContext

Context on a function before it executes.

PromptInvocationContext

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}`;
    }
});

Interfaces

AppStartContextInit

Object passed to AppStartContext constructors. For testing purposes only

AppTerminateContextInit

Object passed to AppTerminateContext constructors. For testing purposes only

ConnectorTriggerFunctionOptions
ConnectorTriggerOptions
Cookie

Http response cookie object to "Set-Cookie"

CosmosDBv3FunctionOptions
CosmosDBv3InputOptions
CosmosDBv3OutputOptions
CosmosDBv3TriggerOptions
CosmosDBv4AllVersionsAndDeletesFunctionOptions
CosmosDBv4ChangeFeedItem

Full-fidelity change feed item payload emitted when changeFeedMode is AllVersionsAndDeletes. Property names follow the wire format emitted by Cosmos DB.

CosmosDBv4ChangeFeedMetadata

Metadata included with each change feed item when using AllVersionsAndDeletes. Property names follow the wire format emitted by Cosmos DB.

CosmosDBv4InputOptions
CosmosDBv4LatestVersionFunctionOptions
CosmosDBv4OutputOptions
CosmosDBv4TriggerOptions
Duration
EffectiveFunctionOptions

The options used when registering the function, as passed to a specific invocation NOTE: This value may differ slightly from the original because it has been validated and defaults may have been explicitly added

EventGridEvent

Link to docs and examples

EventGridFunctionOptions

At this point in time there are no event grid trigger-specific options

EventGridOutputConnectionOptions
EventGridOutputKeyOptions
EventGridPartialEvent

Link to docs and examples This "partial" interface is meant to be used when creating an event yourself and allows some properties to be left out

EventGridTriggerOptions

At this point in time there are no event grid trigger-specific options

EventHubFunctionOptions
EventHubOutputOptions
EventHubTriggerOptions
Exception
ExponentialBackoffRetryOptions
FixedDelayRetryOptions
FunctionInput

Full configuration for the secondary input to a function ("trigger" is the primary input) NOTE: Not all triggers can be used as secondary inputs

FunctionOptions

Configures the inputs, outputs, and handler for an Azure Function

FunctionOutput

Full configuration for the output to a function

FunctionTrigger

Full configuration for the primary input to a function

GenericFunctionOptions

Configures the inputs, outputs, and handler for an Azure Function

GenericInputOptions
GenericOutputOptions
GenericTriggerOptions
HookContextInit

Base interface for objects passed to HookContext constructors. For testing purposes only.

HttpFunctionOptions
HttpOutputOptions

At this point in time there are no http output specific options

HttpRequestBodyInit

For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime

HttpRequestInit

For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime

HttpRequestUser

Object representing logged-in user, either through AppService/Functions authentication, or SWA Authentication

HttpResponseInit
HttpTrigger

Full configuration for the primary input to a function

HttpTriggerOptions
IToolPropertyBuilder

Interface for the fluent API builder for creating MCP Tool properties This acts as a bridge between the implementation and type declarations

InvocationContextExtraInputs

An object used to get secondary inputs

InvocationContextExtraOutputs

An object used to set secondary outputs

InvocationContextInit

For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime

InvocationHookContextInit

Object passed to InvocationHookContext constructors. For testing purposes only

LogHookContextInit

Object passed to LogHookContext constructors. For testing purposes only

McpAudioContentInit

Initializer for McpAudioContent. data is base64-encoded automatically for Buffer/ArrayBuffer values.

McpImageContentInit

Initializer for McpImageContent. data is base64-encoded automatically for Buffer/ArrayBuffer values.

McpPromptArgument

Describes a single argument accepted by an MCP prompt.

McpPromptFunctionOptions

Configuration options for an MCP Prompt function. This includes trigger-specific options and general function options.

McpPromptTriggerOptions

Configuration options for an MCP Prompt trigger. These options define the behavior and metadata for the trigger.

McpPromptTriggerOptionsToRpc

The wire-format options sent to the Functions host for an MCP Prompt trigger. promptArguments is serialized to a JSON string as required by the host binding contract.

McpResourceContentInit

Initializer for McpResourceContent. blob is base64-encoded automatically for Buffer/ArrayBuffer values.

McpResourceFunctionOptions

Configuration options for an MCP Resource function. This includes trigger-specific options and general function options.

McpResourceLinkContentInit

Initializer for McpResourceLinkContent.

McpResourceTriggerOptions

Configuration options for an MCP Resource trigger. These options define the behavior and metadata for the trigger.

McpToolFunctionOptions

Configuration options for an MCP Tool function. This includes trigger-specific options and general function options.

McpToolProperty
McpToolResponseInit

Initializer for McpToolResponse.

McpToolTriggerOptions

Configuration options for an MCP Tool trigger. These options define the behavior and metadata for the trigger.

McpToolTriggerOptionsToRpc

Configuration options for an MCP Tool trigger. These options define the behavior and metadata for the trigger.

MySqlChange
MySqlFunctionOptions
MySqlInputOptions
MySqlOutputOptions
MySqlTriggerOptions
PostInvocationContextInit

Object passed to PostInvocationContext constructors. For testing purposes only

PreInvocationContextInit

Object passed to PreInvocationContext constructors. For testing purposes only

RetryContext
ServiceBusQueueFunctionOptions
ServiceBusQueueOutputOptions
ServiceBusQueueTriggerOptions
ServiceBusTopicFunctionOptions
ServiceBusTopicOutputOptions
ServiceBusTopicTriggerOptions
SetupOptions
SqlChange
SqlFunctionOptions
SqlInputOptions
SqlOutputOptions
SqlTriggerOptions
StorageBlobFunctionOptions
StorageBlobOptions
StorageBlobTriggerOptions
StorageQueueFunctionOptions
StorageQueueOptions
TableInputOptions
TableOutputOptions
Timer

Timer schedule information. Provided to your function when using a timer binding.

TimerFunctionOptions
TimerTriggerOptions
TraceContext

TraceContext information to enable distributed tracing scenarios

WarmupContext
WarmupFunctionOptions
WarmupTriggerOptions
WebPubSubConnectionInputOptions
WebPubSubContextInputOptions
WebPubSubFunctionOptions
WebPubSubOutputOptions
WebPubSubTriggerOptions

Type Aliases

AppStartHandler

Handler for app start hooks

AppTerminateHandler

Handler for app terminate hooks

Arg

Represents a tool property definition (same as McpToolProperty but without propertyName)

Args

Tool properties format - an object mapping property names to their definitions

ConnectorTrigger
ConnectorTriggerHandler
CosmosDBChangeFeedItem
CosmosDBChangeFeedMetadata
CosmosDBFunctionOptions
CosmosDBHandler
CosmosDBInput
CosmosDBInputOptions
CosmosDBOutput
CosmosDBOutputOptions
CosmosDBTrigger
CosmosDBTriggerOptions
CosmosDBv3Handler
CosmosDBv3Input
CosmosDBv3Output
CosmosDBv3Trigger
CosmosDBv4FullFidelityFunctionOptions
CosmosDBv4FunctionOptions
CosmosDBv4Handler
CosmosDBv4Input
CosmosDBv4Output
CosmosDBv4Trigger
EventGridHandler
EventGridOutput
EventGridOutputOptions
EventGridTrigger
EventHubHandler
EventHubOutput
EventHubTrigger
FunctionHandler
FunctionResult

Void if no return output is registered Otherwise, the registered return output

HttpHandler
HttpHeadersInit

Represents the headers types that can be used to initialize HTTP headers. This is a local definition to avoid dependency on lib.dom. Compatible with Node.js native Fetch API header types.

HttpMethod

Possible values for an HTTP request method.

HttpMethodFunctionOptions
HttpOutput
HttpRequestParams

Route parameter keys and values.

HttpRequestUserType

Possible values for an HTTP Request user type

HttpResponseBodyInit

Represents the body types that can be used in an HTTP response. This is a local definition to avoid dependency on lib.dom. Compatible with Node.js native Fetch API body types. Includes Node.js Readable streams and AsyncIterable for HTTP streaming scenarios.

LogCategory
LogHandler
LogHookHandler

Handler for log hooks.

LogLevel
McpPromptArguments

Accepted shapes for declaring prompt arguments.

  • Array form (explicit): an array of McpPromptArgument objects with name, optional description and required.
  • Record/fluent form: an object whose keys are argument names and values are McpPromptArgumentBuilder instances built from promptArg.describe(...).
McpPromptTrigger

Represents an MCP Prompt trigger, combining base function trigger options with MCP Prompt-specific trigger options.

McpPromptTriggerHandler

A handler function for MCP Prompt triggers.

McpResourceTrigger

Represents an MCP Resource trigger, combining base function trigger options with MCP Resource-specific trigger options.

McpResourceTriggerHandler

A handler function for MCP Resource triggers.

McpToolTrigger

Represents an MCP Tool trigger, combining base function trigger options with MCP Tool-specific trigger options.

McpToolTriggerHandler

A handler function for MCP Tool triggers.

MySqlHandler
MySqlInput
MySqlOutput
MySqlTrigger
PostInvocationHandler

Handler for post-invocation hooks

PreInvocationHandler

Handler for pre-invocation hooks.

RetryOptions
ServiceBusQueueHandler
ServiceBusQueueOutput
ServiceBusQueueTrigger
ServiceBusTopicHandler
ServiceBusTopicOutput
ServiceBusTopicTrigger
SqlHandler
SqlInput
SqlOutput
SqlTrigger
StorageBlobHandler
StorageBlobInput
StorageBlobInputOptions
StorageBlobOutput
StorageBlobOutputOptions
StorageBlobTrigger
StorageQueueHandler
StorageQueueOutput
StorageQueueOutputOptions
StorageQueueTrigger
StorageQueueTriggerOptions
TableInput
TableOutput
TimerHandler
TimerTrigger
TriggerMetadata

Metadata related to the input that triggered your function

WarmupHandler
WarmupTrigger
WebPubSubConnectionInput
WebPubSubContextInput
WebPubSubHandler
WebPubSubOutput
WebPubSubTrigger

Enums

CosmosDBv4ChangeFeedMode

Change feed mode for Cosmos DB trigger bindings.

MySqlChangeOperation
SqlChangeOperation

Functions

McpContent<T>(T)

Marks a class or constructor function as an MCP result type that should be serialized as structured content.

When a function returns an instance of a type decorated with this marker, the result will be serialized as both text content (for backwards compatibility) and structured content (for clients that support it).

Without the marker, a plain object is serialized as text-only (JSON stringified). Use McpToolResponse if you need explicit control over structuredContent without a class.

Programmatic usage (works without experimentalDecorators):

class ImageMetadata {
  constructor(public imageId: string, public format: string) {}
}
McpContent(ImageMetadata);  // marks the class

app.mcpTool('GetImage', {
  toolName: 'GetImage',
  description: 'Returns image info',
  handler: async () => new ImageMetadata('logo', 'png')
});

Decorator usage (requires experimentalDecorators: true in tsconfig):

@McpContent
class ImageMetadata { ... }

Supported forms:

  • @McpContent
  • @McpContent()
  • McpContent(MyClass)

See McpToolResponseSee For explicit content blocks + structuredContent See McpTextContentSee For returning single content blocks

McpContent()

Variables

arg

Factory function to create a new tool property builder

Example

const toolProperties = {
  snippetName: arg
    .string()
    .describe("Some Description"),

  optionalField: arg
    .number()
    .describe("Optional number field")
    .optional(),
};
promptArg

Factory for creating MCP prompt argument builders.

Kept separate from the tool-property arg helper because prompt arguments are untyped (only name, optional description, and a required flag).

Function Details

McpContent<T>(T)

Marks a class or constructor function as an MCP result type that should be serialized as structured content.

When a function returns an instance of a type decorated with this marker, the result will be serialized as both text content (for backwards compatibility) and structured content (for clients that support it).

Without the marker, a plain object is serialized as text-only (JSON stringified). Use McpToolResponse if you need explicit control over structuredContent without a class.

Programmatic usage (works without experimentalDecorators):

class ImageMetadata {
  constructor(public imageId: string, public format: string) {}
}
McpContent(ImageMetadata);  // marks the class

app.mcpTool('GetImage', {
  toolName: 'GetImage',
  description: 'Returns image info',
  handler: async () => new ImageMetadata('logo', 'png')
});

Decorator usage (requires experimentalDecorators: true in tsconfig):

@McpContent
class ImageMetadata { ... }

Supported forms:

  • @McpContent
  • @McpContent()
  • McpContent(MyClass)

See McpToolResponseSee For explicit content blocks + structuredContent See McpTextContentSee For returning single content blocks

function McpContent<T>(target: T): T

Parameters

target

T

Optional class or constructor function to mark for structured content.

Returns

T

The target class/function unchanged or a class decorator.

McpContent()

function McpContent(): (target: T) => T

Returns

(target: T) => T

Variable Details

arg

Factory function to create a new tool property builder

Example

const toolProperties = {
  snippetName: arg
    .string()
    .describe("Some Description"),

  optionalField: arg
    .number()
    .describe("Optional number field")
    .optional(),
};
arg: { boolean() => IToolPropertyBuilder, datetime() => IToolPropertyBuilder, double() => IToolPropertyBuilder, integer() => IToolPropertyBuilder, long() => IToolPropertyBuilder, number() => IToolPropertyBuilder, object() => IToolPropertyBuilder, string() => IToolPropertyBuilder }

Type

{ boolean() => IToolPropertyBuilder, datetime() => IToolPropertyBuilder, double() => IToolPropertyBuilder, integer() => IToolPropertyBuilder, long() => IToolPropertyBuilder, number() => IToolPropertyBuilder, object() => IToolPropertyBuilder, string() => IToolPropertyBuilder }

promptArg

Factory for creating MCP prompt argument builders.

Kept separate from the tool-property arg helper because prompt arguments are untyped (only name, optional description, and a required flag).

promptArg: { describe(description: string) => McpPromptArgumentBuilder }

Type

{ describe(description: string) => McpPromptArgumentBuilder }