McpToolRegistrationService class

Discover MCP servers and list tools formatted for the OpenAI Agents SDK. Uses listToolServers to fetch server configs.

Constructors

McpToolRegistrationService(IConfigurationProvider<OpenAIToolingConfiguration>)

Construct a McpToolRegistrationService.

Methods

addToolServersToAgent(Agent<unknown, "text">, Authorization, string, TurnContext, string)

Registers MCP tool servers and updates agent options with discovered tools and server configs. Call this to enable dynamic OpenAI tool access based on the current MCP environment.

sendChatHistoryAsync(TurnContext, OpenAIConversationsSession, number, ToolOptions)

Sends chat history from an OpenAI Session to the MCP platform for real-time threat protection.

This method extracts messages from the provided OpenAI Session using getItems(), converts them to the ChatHistoryMessage format, and sends them to the MCP platform.

Example

const session = new OpenAIConversationsSession(sessionOptions);
const result = await service.sendChatHistoryAsync(turnContext, session, 50);
if (result.succeeded) {
  console.log('Chat history sent successfully');
} else {
  console.error('Failed to send chat history:', result.errors);
}
sendChatHistoryMessagesAsync(TurnContext, AgentInputItem[], ToolOptions)

Sends a list of OpenAI messages to the MCP platform for real-time threat protection.

This method converts the provided AgentInputItem messages to ChatHistoryMessage format and sends them to the MCP platform.

Example

const items = await session.getItems();
const result = await service.sendChatHistoryMessagesAsync(turnContext, items);

Constructor Details

McpToolRegistrationService(IConfigurationProvider<OpenAIToolingConfiguration>)

Construct a McpToolRegistrationService.

new McpToolRegistrationService(configProvider?: IConfigurationProvider<OpenAIToolingConfiguration>)

Parameters

configProvider

IConfigurationProvider<OpenAIToolingConfiguration>

Optional configuration provider. Defaults to defaultOpenAIToolingConfigurationProvider if not specified.

Method Details

addToolServersToAgent(Agent<unknown, "text">, Authorization, string, TurnContext, string)

Registers MCP tool servers and updates agent options with discovered tools and server configs. Call this to enable dynamic OpenAI tool access based on the current MCP environment.

function addToolServersToAgent(agent: Agent<unknown, "text">, authorization: Authorization, authHandlerName: string, turnContext: TurnContext, authToken: string): Promise<Agent<unknown, "text">>

Parameters

agent

Agent<unknown, "text">

The OpenAI Agent instance to which MCP servers will be added.

authorization
Authorization

Authorization object for token exchange.

authHandlerName

string

The name of the auth handler to use for token exchange.

turnContext
TurnContext

The TurnContext of the current request.

authToken

string

Optional bearer token for MCP server access.

Returns

Promise<Agent<unknown, "text">>

The updated Agent instance with registered MCP servers.

sendChatHistoryAsync(TurnContext, OpenAIConversationsSession, number, ToolOptions)

Sends chat history from an OpenAI Session to the MCP platform for real-time threat protection.

This method extracts messages from the provided OpenAI Session using getItems(), converts them to the ChatHistoryMessage format, and sends them to the MCP platform.

Example

const session = new OpenAIConversationsSession(sessionOptions);
const result = await service.sendChatHistoryAsync(turnContext, session, 50);
if (result.succeeded) {
  console.log('Chat history sent successfully');
} else {
  console.error('Failed to send chat history:', result.errors);
}
function sendChatHistoryAsync(turnContext: TurnContext, session: OpenAIConversationsSession, limit?: number, toolOptions?: ToolOptions): Promise<OperationResult>

Parameters

turnContext
TurnContext

The turn context containing conversation information.

session
OpenAIConversationsSession

The OpenAI Session instance to extract messages from.

limit

number

Optional limit on the number of messages to retrieve from the session.

toolOptions
ToolOptions

Optional tool options for customization.

Returns

Promise<OperationResult>

A Promise resolving to an OperationResult indicating success or failure.

sendChatHistoryMessagesAsync(TurnContext, AgentInputItem[], ToolOptions)

Sends a list of OpenAI messages to the MCP platform for real-time threat protection.

This method converts the provided AgentInputItem messages to ChatHistoryMessage format and sends them to the MCP platform.

Example

const items = await session.getItems();
const result = await service.sendChatHistoryMessagesAsync(turnContext, items);
function sendChatHistoryMessagesAsync(turnContext: TurnContext, messages: AgentInputItem[], toolOptions?: ToolOptions): Promise<OperationResult>

Parameters

turnContext
TurnContext

The turn context containing conversation information.

messages

AgentInputItem[]

Array of AgentInputItem messages to send.

toolOptions
ToolOptions

Optional ToolOptions for customization.

Returns

Promise<OperationResult>

A Promise resolving to an OperationResult indicating success or failure.