McpToolRegistrationService class
Discover MCP servers and list tools formatted for the OpenAI Agents SDK. Uses listToolServers to fetch server configs.
Constructors
| Mcp |
Construct a McpToolRegistrationService. |
Methods
| add |
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. |
| send |
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 Example
|
| send |
Sends a list of OpenAI messages to the MCP platform for real-time threat protection. This method converts the provided AgentInputItem messages to Example
|
Constructor Details
McpToolRegistrationService(IConfigurationProvider<OpenAIToolingConfiguration>)
Construct a McpToolRegistrationService.
new McpToolRegistrationService(configProvider?: IConfigurationProvider<OpenAIToolingConfiguration>)
Parameters
- configProvider
Optional configuration provider. Defaults to defaultOpenAIToolingConfigurationProvider if not specified.
Method Details
addToolServersToAgent(Agent, 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, authorization: Authorization, authHandlerName: string, turnContext: TurnContext, authToken: string): Promise<Agent<unknown, "text">>
Parameters
- agent
-
Agent
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.