McpToolRegistrationService Class

Provides services related to tools in the Semantic Kernel.

This service handles registration and management of MCP (Model Context Protocol) tool servers with Semantic Kernel agents.

Constructor

McpToolRegistrationService()

Parameters

Name Description
logger
Default value: None

Methods

__init__

Initialize the MCP Tool Registration Service for Semantic Kernel.

__new__
add_tool_servers_to_agent

Adds the A365 MCP Tool Servers to the specified kernel.

cleanup_connections

Clean up all connected MCP plugins.

send_chat_history

Send Semantic Kernel chat history to the MCP platform.

This method extracts messages from a Semantic Kernel ChatHistory object, converts them to ChatHistoryMessage format, and sends them to the MCP platform for real-time threat protection.

send_chat_history_messages

Send Semantic Kernel chat history messages to the MCP platform.

This method accepts a sequence of Semantic Kernel ChatMessageContent objects, converts them to ChatHistoryMessage format, and sends them to the MCP platform for real-time threat protection.

__init__

Initialize the MCP Tool Registration Service for Semantic Kernel.

__init__(logger: Logger | None = None)

Parameters

Name Description
logger

Logger instance for logging operations.

Default value: None

__new__

__new__(**kwargs)

add_tool_servers_to_agent

Adds the A365 MCP Tool Servers to the specified kernel.

async add_tool_servers_to_agent(kernel: Kernel, auth: Authorization, auth_handler_name: str, context: TurnContext, auth_token: str | None = None) -> None

Parameters

Name Description
kernel
Required

The Semantic Kernel instance to which the tools will be added.

auth
Required

Authorization handler for token exchange.

auth_handler_name
Required
str

Name of the authorization handler.

context
Required

Turn context for the current operation.

auth_token
str | None

Authentication token to access the MCP servers.

Default value: None

Returns

Type Description

Exceptions

Type Description

If kernel is None or required parameters are invalid.

If there's an error connecting to or configuring MCP servers.

cleanup_connections

Clean up all connected MCP plugins.

async cleanup_connections() -> None

Returns

Type Description

send_chat_history

Send Semantic Kernel chat history to the MCP platform.

This method extracts messages from a Semantic Kernel ChatHistory object, converts them to ChatHistoryMessage format, and sends them to the MCP platform for real-time threat protection.

async send_chat_history(turn_context: TurnContext, chat_history: ChatHistory, limit: int | None = None, options: ToolOptions | None = None) -> OperationResult

Parameters

Name Description
turn_context
Required

TurnContext from the Agents SDK containing conversation info.

chat_history
Required

Semantic Kernel ChatHistory object containing messages.

limit
int | None

Optional maximum number of messages to send. If specified, sends the most recent N messages. If None, sends all messages.

Default value: None
options

Optional configuration for the request.

Default value: None

Returns

Type Description

OperationResult indicating success or failure.

Exceptions

Type Description

If turn_context or chat_history is None.

Examples


>>> from semantic_kernel.contents import ChatHistory
>>> from microsoft_agents_a365.tooling.extensions.semantickernel import (
...     McpToolRegistrationService
... )
>>>
>>> service = McpToolRegistrationService()
>>> chat_history = ChatHistory()
>>> chat_history.add_user_message("Hello!")
>>> chat_history.add_assistant_message("Hi there!")
>>>
>>> result = await service.send_chat_history(
...     turn_context, chat_history, limit=50
... )
>>> if result.succeeded:
...     print("Chat history sent successfully")

send_chat_history_messages

Send Semantic Kernel chat history messages to the MCP platform.

This method accepts a sequence of Semantic Kernel ChatMessageContent objects, converts them to ChatHistoryMessage format, and sends them to the MCP platform for real-time threat protection.

async send_chat_history_messages(turn_context: TurnContext, messages: Sequence[ChatMessageContent], options: ToolOptions | None = None) -> OperationResult

Parameters

Name Description
turn_context
Required

TurnContext from the Agents SDK containing conversation info.

messages
Required

Sequence of Semantic Kernel ChatMessageContent objects to send.

options

Optional configuration for the request.

Default value: None

Returns

Type Description

OperationResult indicating success or failure.

Exceptions

Type Description

If turn_context or messages is None.

Examples


>>> from semantic_kernel.contents import ChatMessageContent, AuthorRole
>>> from microsoft_agents_a365.tooling.extensions.semantickernel import (
...     McpToolRegistrationService
... )
>>>
>>> service = McpToolRegistrationService()
>>> messages = [
...     ChatMessageContent(role=AuthorRole.USER, content="Hello!"),
...     ChatMessageContent(role=AuthorRole.ASSISTANT, content="Hi there!"),
... ]
>>>
>>> result = await service.send_chat_history_messages(
...     turn_context, messages
... )
>>> if result.succeeded:
...     print("Chat history sent successfully")