McpToolRegistrationService Class
Provides MCP tool registration services for Agent Framework agents.
This service handles registration and management of MCP (Model Context Protocol) tool servers with Agent Framework agents.
Constructor
McpToolRegistrationService()
Parameters
| Name | Description |
|---|---|
|
logger
|
Default value: None
|
Methods
| __init__ |
Initialize the MCP Tool Registration Service for Agent Framework. |
| __new__ | |
| add_tool_servers_to_agent |
Add MCP tool servers to a RawAgent (mirrors .NET implementation). |
| cleanup |
Clean up any resources used by the service. |
| send_chat_history_from_store |
Send chat history from a HistoryProvider to the MCP platform. This is a convenience method that extracts messages from the store and delegates to send_chat_history_messages(). |
| send_chat_history_messages |
Send chat history messages to the MCP platform for real-time threat protection. This is the primary implementation method that handles message conversion and delegation to the core tooling service. Note Even if chat_messages is empty or all messages are filtered during conversion, the request will still be sent to the MCP platform. This ensures the user message from turn_context.activity.text is registered correctly for real-time threat protection. |
__init__
__new__
__new__(**kwargs)
add_tool_servers_to_agent
Add MCP tool servers to a RawAgent (mirrors .NET implementation).
async add_tool_servers_to_agent(chat_client: OpenAIChatClient, agent_instructions: str, initial_tools: List[object], auth: Authorization, auth_handler_name: str, turn_context: TurnContext, auth_token: str | None = None) -> RawAgent
Parameters
| Name | Description |
|---|---|
|
chat_client
Required
|
<xref:OpenAIChatClient>
The chat client instance (OpenAIChatClient supports both OpenAI and Azure OpenAI) |
|
agent_instructions
Required
|
Instructions for the agent behavior |
|
initial_tools
Required
|
List of initial tools to add to the agent |
|
auth
Required
|
<xref:Authorization>
Authorization context for token exchange |
|
auth_handler_name
Required
|
Name of the authorization handler. |
|
turn_context
Required
|
<xref:TurnContext>
Turn context for the operation |
|
auth_token
|
Optional bearer token for authentication Default value: None
|
Returns
| Type | Description |
|---|---|
|
<xref:RawAgent>
|
RawAgent instance with MCP tools registered. |
Exceptions
| Type | Description |
|---|---|
|
If agent creation fails. |
cleanup
Clean up any resources used by the service.
async cleanup()
send_chat_history_from_store
Send chat history from a HistoryProvider to the MCP platform.
This is a convenience method that extracts messages from the store and delegates to send_chat_history_messages().
async send_chat_history_from_store(chat_message_store: HistoryProvider, turn_context: TurnContext, tool_options: ToolOptions | None = None) -> OperationResult
Parameters
| Name | Description |
|---|---|
|
chat_message_store
Required
|
<xref:agent_framework._sessions.HistoryProvider>
HistoryProvider containing the conversation history. |
|
turn_context
Required
|
TurnContext from the Agents SDK containing conversation info. |
|
tool_options
|
Optional configuration for the request. Default value: None
|
Returns
| Type | Description |
|---|---|
|
OperationResult indicating success or failure of the operation. |
Exceptions
| Type | Description |
|---|---|
|
If chat_message_store or turn_context is None. |
Examples
>>> service = McpToolRegistrationService()
>>> result = await service.send_chat_history_from_store(
... thread.chat_message_store, turn_context
... )
send_chat_history_messages
Send chat history messages to the MCP platform for real-time threat protection.
This is the primary implementation method that handles message conversion and delegation to the core tooling service.
Note
Even if chat_messages is empty or all messages are filtered during
conversion, the request will still be sent to the MCP platform. This
ensures the user message from turn_context.activity.text is registered
correctly for real-time threat protection.
async send_chat_history_messages(chat_messages: Sequence[Message], turn_context: TurnContext, tool_options: ToolOptions | None = None) -> OperationResult
Parameters
| Name | Description |
|---|---|
|
chat_messages
Required
|
Sequence[<xref:agent_framework._types.Message>]
Sequence of Agent Framework Message objects to send. Can be empty - the request will still be sent to register the user message from turn_context.activity.text. |
|
turn_context
Required
|
TurnContext from the Agents SDK containing conversation info. |
|
tool_options
|
Optional configuration for the request. Defaults to AgentFramework-specific options if not provided. Default value: None
|
Returns
| Type | Description |
|---|---|
|
OperationResult indicating success or failure of the operation. |
Exceptions
| Type | Description |
|---|---|
|
If chat_messages or turn_context is None. |
Examples
>>> service = McpToolRegistrationService()
>>> messages = [Message(role="user", text="Hello")]
>>> result = await service.send_chat_history_messages(messages, turn_context)
>>> if result.succeeded:
... print("Chat history sent successfully")