microsoft-agents-a365-tooling-extensions-agentframework 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- microsoft_agents_a365/tooling/extensions/agentframework/__init__.py +27 -0
- microsoft_agents_a365/tooling/extensions/agentframework/services/__init__.py +14 -0
- microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py +158 -0
- microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/METADATA +68 -0
- microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/RECORD +7 -0
- microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/WHEEL +5 -0
- microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Agent 365 Tooling Agent Framework Extensions
|
|
5
|
+
|
|
6
|
+
Agent Framework specific tools and services for AI agent development.
|
|
7
|
+
Provides Agent Framework-specific implementations and utilities for
|
|
8
|
+
building agents with Microsoft Agent Framework capabilities.
|
|
9
|
+
|
|
10
|
+
Main Service:
|
|
11
|
+
- McpToolRegistrationService: Add MCP tool servers to Agent Framework agents
|
|
12
|
+
|
|
13
|
+
This module includes implementations for:
|
|
14
|
+
- Agent Framework agent creation with MCP (Model Context Protocol) server support
|
|
15
|
+
- MCP tool registration service for dynamically adding MCP servers to agents
|
|
16
|
+
- Azure OpenAI and OpenAI chat client integration
|
|
17
|
+
- Authentication and authorization patterns for MCP server discovery
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
__version__ = "1.0.0"
|
|
21
|
+
|
|
22
|
+
# Import services from the services module
|
|
23
|
+
from .services import McpToolRegistrationService
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"McpToolRegistrationService",
|
|
27
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Services module for Agent Framework tooling.
|
|
5
|
+
|
|
6
|
+
This package contains service implementations for MCP tool registration
|
|
7
|
+
and management within the Agent Framework.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .mcp_tool_registration_service import McpToolRegistrationService
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"McpToolRegistrationService",
|
|
14
|
+
]
|
microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
from typing import Optional, List, Any, Union
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from agent_framework import ChatAgent, MCPStreamableHTTPTool
|
|
7
|
+
from agent_framework.azure import AzureOpenAIChatClient
|
|
8
|
+
from agent_framework.openai import OpenAIChatClient
|
|
9
|
+
|
|
10
|
+
from microsoft_agents.hosting.core import Authorization, TurnContext
|
|
11
|
+
|
|
12
|
+
from microsoft_agents_a365.runtime.utility import Utility
|
|
13
|
+
from microsoft_agents_a365.tooling.services.mcp_tool_server_configuration_service import (
|
|
14
|
+
McpToolServerConfigurationService,
|
|
15
|
+
)
|
|
16
|
+
from microsoft_agents_a365.tooling.utils.constants import Constants
|
|
17
|
+
|
|
18
|
+
from microsoft_agents_a365.tooling.utils.utility import (
|
|
19
|
+
get_mcp_platform_authentication_scope,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class McpToolRegistrationService:
|
|
24
|
+
"""
|
|
25
|
+
Provides MCP tool registration services for Agent Framework agents.
|
|
26
|
+
|
|
27
|
+
This service handles registration and management of MCP (Model Context Protocol)
|
|
28
|
+
tool servers with Agent Framework agents.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, logger: Optional[logging.Logger] = None):
|
|
32
|
+
"""
|
|
33
|
+
Initialize the MCP Tool Registration Service for Agent Framework.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
logger: Logger instance for logging operations.
|
|
37
|
+
"""
|
|
38
|
+
self._logger = logger or logging.getLogger(self.__class__.__name__)
|
|
39
|
+
self._mcp_server_configuration_service = McpToolServerConfigurationService(
|
|
40
|
+
logger=self._logger
|
|
41
|
+
)
|
|
42
|
+
self._connected_servers = []
|
|
43
|
+
|
|
44
|
+
async def add_tool_servers_to_agent(
|
|
45
|
+
self,
|
|
46
|
+
chat_client: Union[OpenAIChatClient, AzureOpenAIChatClient],
|
|
47
|
+
agent_instructions: str,
|
|
48
|
+
initial_tools: List[Any],
|
|
49
|
+
auth: Authorization,
|
|
50
|
+
auth_handler_name: str,
|
|
51
|
+
turn_context: TurnContext,
|
|
52
|
+
auth_token: Optional[str] = None,
|
|
53
|
+
) -> Optional[ChatAgent]:
|
|
54
|
+
"""
|
|
55
|
+
Add MCP tool servers to a chat agent (mirrors .NET implementation).
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
chat_client: The chat client instance (Union[OpenAIChatClient, AzureOpenAIChatClient])
|
|
59
|
+
agent_instructions: Instructions for the agent behavior
|
|
60
|
+
initial_tools: List of initial tools to add to the agent
|
|
61
|
+
auth: Authorization context for token exchange
|
|
62
|
+
auth_handler_name: Name of the authorization handler.
|
|
63
|
+
turn_context: Turn context for the operation
|
|
64
|
+
auth_token: Optional bearer token for authentication
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
ChatAgent instance with MCP tools registered, or None if creation failed
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
# Exchange token if not provided
|
|
71
|
+
if not auth_token:
|
|
72
|
+
scopes = get_mcp_platform_authentication_scope()
|
|
73
|
+
authToken = await auth.exchange_token(turn_context, scopes, auth_handler_name)
|
|
74
|
+
auth_token = authToken.token
|
|
75
|
+
|
|
76
|
+
agentic_app_id = Utility.resolve_agent_identity(turn_context, auth_token)
|
|
77
|
+
|
|
78
|
+
self._logger.info(f"Listing MCP tool servers for agent {agentic_app_id}")
|
|
79
|
+
|
|
80
|
+
# Get MCP server configurations
|
|
81
|
+
server_configs = await self._mcp_server_configuration_service.list_tool_servers(
|
|
82
|
+
agentic_app_id=agentic_app_id,
|
|
83
|
+
auth_token=auth_token,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
self._logger.info(f"Loaded {len(server_configs)} MCP server configurations")
|
|
87
|
+
|
|
88
|
+
# Create the agent with all tools (initial + MCP tools)
|
|
89
|
+
all_tools = list(initial_tools)
|
|
90
|
+
|
|
91
|
+
# Add servers as MCPStreamableHTTPTool instances
|
|
92
|
+
for config in server_configs:
|
|
93
|
+
try:
|
|
94
|
+
server_url = getattr(config, "server_url", None) or getattr(
|
|
95
|
+
config, "mcp_server_unique_name", None
|
|
96
|
+
)
|
|
97
|
+
if not server_url:
|
|
98
|
+
self._logger.warning(f"MCP server config missing server_url: {config}")
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
# Prepare auth headers
|
|
102
|
+
headers = {}
|
|
103
|
+
if auth_token:
|
|
104
|
+
headers[Constants.Headers.AUTHORIZATION] = (
|
|
105
|
+
f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
server_name = getattr(config, "mcp_server_name", "Unknown")
|
|
109
|
+
|
|
110
|
+
# Create and configure MCPStreamableHTTPTool
|
|
111
|
+
mcp_tools = MCPStreamableHTTPTool(
|
|
112
|
+
name=server_name,
|
|
113
|
+
url=server_url,
|
|
114
|
+
headers=headers,
|
|
115
|
+
description=f"MCP tools from {server_name}",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Let Agent Framework handle the connection automatically
|
|
119
|
+
self._logger.info(f"Created MCP plugin for '{server_name}' at {server_url}")
|
|
120
|
+
|
|
121
|
+
all_tools.append(mcp_tools)
|
|
122
|
+
self._connected_servers.append(mcp_tools)
|
|
123
|
+
|
|
124
|
+
self._logger.info(f"Added MCP plugin '{server_name}' to agent tools")
|
|
125
|
+
|
|
126
|
+
except Exception as tool_ex:
|
|
127
|
+
server_name = getattr(config, "mcp_server_name", "Unknown")
|
|
128
|
+
self._logger.warning(
|
|
129
|
+
f"Failed to create MCP plugin for {server_name}: {tool_ex}"
|
|
130
|
+
)
|
|
131
|
+
continue
|
|
132
|
+
|
|
133
|
+
# Create the ChatAgent
|
|
134
|
+
agent = ChatAgent(
|
|
135
|
+
chat_client=chat_client,
|
|
136
|
+
tools=all_tools,
|
|
137
|
+
instructions=agent_instructions,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
self._logger.info(f"Agent created with {len(all_tools)} total tools")
|
|
141
|
+
return agent
|
|
142
|
+
|
|
143
|
+
except Exception as ex:
|
|
144
|
+
self._logger.error(f"Failed to add tool servers to agent: {ex}")
|
|
145
|
+
raise
|
|
146
|
+
|
|
147
|
+
async def cleanup(self):
|
|
148
|
+
"""Clean up any resources used by the service."""
|
|
149
|
+
try:
|
|
150
|
+
for plugin in self._connected_servers:
|
|
151
|
+
try:
|
|
152
|
+
if hasattr(plugin, "close"):
|
|
153
|
+
await plugin.close()
|
|
154
|
+
except Exception as cleanup_ex:
|
|
155
|
+
self._logger.debug(f"Error during cleanup: {cleanup_ex}")
|
|
156
|
+
self._connected_servers.clear()
|
|
157
|
+
except Exception as ex:
|
|
158
|
+
self._logger.debug(f"Error during service cleanup: {ex}")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-a365-tooling-extensions-agentframework
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agent Framework integration tools for Agent 365 AI agent tooling
|
|
5
|
+
Author-email: Microsoft <support@microsoft.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/microsoft/Agent365-python
|
|
8
|
+
Project-URL: Repository, https://github.com/microsoft/Agent365-python
|
|
9
|
+
Project-URL: Issues, https://github.com/microsoft/Agent365-python/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/microsoft/Agent365-python/tree/main/libraries/microsoft-agents-a365-tooling-extensions-agentframework
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Requires-Dist: microsoft-agents-a365-tooling>=0.0.0
|
|
22
|
+
Requires-Dist: microsoft-agents-hosting-core<0.6.0,>=0.4.0
|
|
23
|
+
Requires-Dist: agent-framework-azure-ai>=1.0.0b251114
|
|
24
|
+
Requires-Dist: azure-identity>=1.12.0
|
|
25
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
30
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
35
|
+
|
|
36
|
+
# microsoft-agents-a365-tooling-extensions-agentframework
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/microsoft-agents-a365-tooling-extensions-agentframework)
|
|
39
|
+
[](https://pypi.org/project/microsoft-agents-a365-tooling-extensions-agentframework)
|
|
40
|
+
|
|
41
|
+
Agent Framework specific tools and services for AI agent development. Provides MCP (Model Context Protocol) tool registration service for dynamically adding MCP servers to Agent Framework agents.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install microsoft-agents-a365-tooling-extensions-agentframework
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
For usage examples and detailed documentation, see the [Tooling documentation](https://learn.microsoft.com/microsoft-agent-365/developer/tooling?tabs=python) on Microsoft Learn.
|
|
52
|
+
|
|
53
|
+
## Support
|
|
54
|
+
|
|
55
|
+
For issues, questions, or feedback:
|
|
56
|
+
|
|
57
|
+
- File issues in the [GitHub Issues](https://github.com/microsoft/Agent365-python/issues) section
|
|
58
|
+
- See the [main documentation](../../../README.md) for more information
|
|
59
|
+
|
|
60
|
+
## Trademarks
|
|
61
|
+
|
|
62
|
+
*Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.*
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
67
|
+
|
|
68
|
+
Licensed under the MIT License - see the [LICENSE](../../../LICENSE.md) file for details.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
microsoft_agents_a365/tooling/extensions/agentframework/__init__.py,sha256=IPaHio1uop6iVK6KYeI5ERhTm3uPQRO6__21SYQqpQ4,880
|
|
2
|
+
microsoft_agents_a365/tooling/extensions/agentframework/services/__init__.py,sha256=TcxL8IstydK8bZ2H3hFVKRvO67VYDqY7JOTBEA9ylXc,338
|
|
3
|
+
microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py,sha256=Ic_yrUMQZs-Vc5IcSKMMdZCX1oZVJZw1EkDzyX14Q2c,6237
|
|
4
|
+
microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/METADATA,sha256=N95eYNQEubpQgB2CzQ7EX6uQLnr4W08_gE9jdwnQdaU,3493
|
|
5
|
+
microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/top_level.txt,sha256=G3c2_4sy5_EM_BWO67SbK2tKj4G8XFn-QXRbh8g9Lgk,22
|
|
7
|
+
microsoft_agents_a365_tooling_extensions_agentframework-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
microsoft_agents_a365
|