universal-mcp 0.1.24rc7__tar.gz → 0.1.24rc8__tar.gz

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.
Files changed (95) hide show
  1. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/PKG-INFO +1 -1
  2. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/pyproject.toml +1 -1
  3. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agentr/__init__.py +1 -2
  4. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agentr/client.py +57 -25
  5. universal_mcp-0.1.24rc8/src/universal_mcp/agentr/registry.py +182 -0
  6. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/__init__.py +1 -1
  7. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/auto.py +2 -3
  8. universal_mcp-0.1.24rc8/src/universal_mcp/agents/autoagent/__init__.py +31 -0
  9. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/autoagent/__main__.py +2 -2
  10. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/autoagent/graph.py +68 -39
  11. universal_mcp-0.1.24rc8/src/universal_mcp/agents/autoagent/prompts.py +8 -0
  12. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/autoagent/state.py +1 -0
  13. universal_mcp-0.1.24rc8/src/universal_mcp/agents/autoagent/studio.py +25 -0
  14. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/base.py +12 -10
  15. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/react.py +25 -7
  16. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/simple.py +11 -11
  17. universal_mcp-0.1.24rc8/src/universal_mcp/tools/registry.py +83 -0
  18. universal_mcp-0.1.24rc7/src/universal_mcp/agentr/agentr.py +0 -37
  19. universal_mcp-0.1.24rc7/src/universal_mcp/agentr/registry.py +0 -87
  20. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/__init__.py +0 -35
  21. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/prompts.py +0 -5
  22. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/studio.py +0 -25
  23. universal_mcp-0.1.24rc7/src/universal_mcp/tools/registry.py +0 -51
  24. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/.gitignore +0 -0
  25. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/LICENSE +0 -0
  26. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/README.md +0 -0
  27. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/__init__.py +0 -0
  28. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/conftest.py +0 -0
  29. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_api_generator.py +0 -0
  30. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_api_integration.py +0 -0
  31. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_applications.py +0 -0
  32. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_localserver.py +0 -0
  33. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_stores.py +0 -0
  34. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_tool.py +0 -0
  35. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_tool_manager.py +0 -0
  36. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/tests/test_zenquotes.py +0 -0
  37. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/__init__.py +0 -0
  38. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agentr/README.md +0 -0
  39. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agentr/integration.py +0 -0
  40. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agentr/server.py +0 -0
  41. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/autoagent/context.py +0 -0
  42. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/autoagent/utils.py +0 -0
  43. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/cli.py +0 -0
  44. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/codeact/__init__.py +0 -0
  45. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/codeact/sandbox.py +0 -0
  46. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/codeact/test.py +0 -0
  47. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/codeact/utils.py +0 -0
  48. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/hil.py +0 -0
  49. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/llm.py +0 -0
  50. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/tools.py +0 -0
  51. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/agents/utils.py +0 -0
  52. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/analytics.py +0 -0
  53. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/applications/__init__.py +0 -0
  54. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/applications/application.py +0 -0
  55. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/applications/sample/app.py +0 -0
  56. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/cli.py +0 -0
  57. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/client/oauth.py +0 -0
  58. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/client/token_store.py +0 -0
  59. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/client/transport.py +0 -0
  60. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/config.py +0 -0
  61. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/exceptions.py +0 -0
  62. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/integrations/__init__.py +0 -0
  63. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/integrations/integration.py +0 -0
  64. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/logger.py +0 -0
  65. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/py.typed +0 -0
  66. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/servers/__init__.py +0 -0
  67. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/servers/server.py +0 -0
  68. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/stores/__init__.py +0 -0
  69. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/stores/store.py +0 -0
  70. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/__init__.py +0 -0
  71. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/adapters.py +0 -0
  72. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/docstring_parser.py +0 -0
  73. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/func_metadata.py +0 -0
  74. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/manager.py +0 -0
  75. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/tools/tools.py +0 -0
  76. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/types.py +0 -0
  77. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/__init__.py +0 -0
  78. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/common.py +0 -0
  79. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/installation.py +0 -0
  80. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/__inti__.py +0 -0
  81. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/api_generator.py +0 -0
  82. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/api_splitter.py +0 -0
  83. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/cli.py +0 -0
  84. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/docgen.py +0 -0
  85. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/filters.py +0 -0
  86. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/openapi.py +0 -0
  87. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/postprocessor.py +0 -0
  88. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/preprocessor.py +0 -0
  89. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/readme.py +0 -0
  90. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/openapi/test_generator.py +0 -0
  91. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/prompts.py +0 -0
  92. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/singleton.py +0 -0
  93. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/templates/README.md.j2 +0 -0
  94. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/templates/api_client.py.j2 +0 -0
  95. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc8}/src/universal_mcp/utils/testing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal-mcp
3
- Version: 0.1.24rc7
3
+ Version: 0.1.24rc8
4
4
  Summary: Universal MCP acts as a middle ware for your API applications. It can store your credentials, authorize, enable disable apps on the fly and much more.
5
5
  Author-email: Manoj Bajaj <manojbajaj95@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "universal-mcp"
7
- version = "0.1.24-rc7"
7
+ version = "0.1.24-rc8"
8
8
  description = "Universal MCP acts as a middle ware for your API applications. It can store your credentials, authorize, enable disable apps on the fly and much more."
9
9
  readme = "README.md"
10
10
  authors = [
@@ -1,6 +1,5 @@
1
- from .agentr import Agentr
2
1
  from .client import AgentrClient
3
2
  from .integration import AgentrIntegration
4
3
  from .registry import AgentrRegistry
5
4
 
6
- __all__ = ["Agentr", "AgentrClient", "AgentrRegistry", "AgentrIntegration"]
5
+ __all__ = ["AgentrClient", "AgentrRegistry", "AgentrIntegration"]
@@ -16,21 +16,45 @@ class AgentrClient:
16
16
  Args:
17
17
  api_key (str, optional): AgentR API key. If not provided, will look for AGENTR_API_KEY env var.
18
18
  base_url (str, optional): Base URL for AgentR API. Defaults to https://api.agentr.dev.
19
+ auth_token (str, optional): Auth token for AgentR API. If not provided, will look for AGENTR_AUTH_TOKEN env var.
19
20
  """
20
21
 
21
- def __init__(self, api_key: str | None = None, base_url: str | None = None):
22
+ def __init__(
23
+ self, api_key: str | None = None, base_url: str | None = None, auth_token: str | None = None, **kwargs
24
+ ):
22
25
  base_url = base_url or os.getenv("AGENTR_BASE_URL", "https://api.agentr.dev")
23
26
  self.base_url = f"{base_url.rstrip('/')}/v1"
24
- self.api_key = api_key or os.getenv("AGENTR_API_KEY")
25
- if not self.api_key:
26
- raise ValueError("No API key provided and AGENTR_API_KEY not found in environment variables")
27
- self.client = httpx.Client(
28
- base_url=self.base_url,
29
- headers={"X-API-KEY": self.api_key},
30
- timeout=30,
31
- follow_redirects=True,
32
- verify=False,
33
- )
27
+ api_key = api_key or os.getenv("AGENTR_API_KEY")
28
+ if api_key:
29
+ self.client = httpx.Client(
30
+ base_url=self.base_url,
31
+ headers={"X-API-KEY": api_key, "accept": "application/json"},
32
+ timeout=30,
33
+ follow_redirects=True,
34
+ verify=False,
35
+ )
36
+ me_data = self.me()
37
+ logger.debug(f"Client initialized with user: {me_data['email']}")
38
+ elif auth_token:
39
+ logger.debug("Initializing client with auth token")
40
+ self.client = httpx.Client(
41
+ base_url=self.base_url,
42
+ headers={"Authorization": f"Bearer {auth_token}", "accept": "application/json"},
43
+ timeout=30,
44
+ follow_redirects=True,
45
+ verify=False,
46
+ )
47
+ me_data = self.me()
48
+ logger.debug(f"Client initialized with user: {me_data['email']}")
49
+ else:
50
+ raise ValueError("No API key or auth token provided")
51
+
52
+ def me(self):
53
+ response = self.client.get("/users/me")
54
+ logger.debug(f"Me response: {response.status_code}")
55
+ response.raise_for_status()
56
+ data = response.json()
57
+ return data
34
58
 
35
59
  def get_credentials(self, app_id: str) -> dict[str, Any]:
36
60
  """Get credentials for an integration from the AgentR API.
@@ -46,9 +70,10 @@ class AgentrClient:
46
70
  HTTPError: For other API errors.
47
71
  """
48
72
  response = self.client.get(
49
- "/credentials/",
73
+ "/credentials",
50
74
  params={"app_id": app_id},
51
75
  )
76
+ logger.debug(f"Credentials response: {response.status_code}")
52
77
  if response.status_code == 404:
53
78
  logger.warning(f"No credentials found for app '{app_id}'. Requesting authorization...")
54
79
  action_url = self.get_authorization_url(app_id)
@@ -73,7 +98,7 @@ class AgentrClient:
73
98
  url = response.json().get("authorize_url")
74
99
  return f"Please ask the user to visit the following url to authorize the application: {url}. Render the url in proper markdown format with a clickable link."
75
100
 
76
- def list_all_apps(self) -> list[dict[str, Any]]:
101
+ def list_all_apps(self):
77
102
  """Fetch available apps from AgentR API.
78
103
 
79
104
  Returns:
@@ -86,27 +111,27 @@ class AgentrClient:
86
111
  response.raise_for_status()
87
112
  return response.json().get("items", [])
88
113
 
89
- def list_my_apps(self) -> list[dict[str, Any]]:
114
+ def list_my_apps(self):
90
115
  """Fetch user apps from AgentR API.
91
116
 
92
117
  Returns:
93
118
  List[Dict[str, Any]]: A list of user app data dictionaries.
94
119
  """
95
- response = self.client.get("/apps/me/")
120
+ response = self.client.get("/apps/me")
96
121
  response.raise_for_status()
97
122
  return response.json().get("items", [])
98
123
 
99
- def list_my_connections(self) -> list[dict[str, Any]]:
124
+ def list_my_connections(self):
100
125
  """Fetch user connections from AgentR API.
101
126
 
102
127
  Returns:
103
128
  List[Dict[str, Any]]: A list of user connection data dictionaries.
104
129
  """
105
- response = self.client.get("/connections/")
130
+ response = self.client.get("/connections")
106
131
  response.raise_for_status()
107
132
  return response.json().get("items", [])
108
133
 
109
- def get_app_details(self, app_id: str) -> dict[str, Any]:
134
+ def get_app_details(self, app_id: str):
110
135
  """Fetch a specific app from AgentR API.
111
136
 
112
137
  Args:
@@ -122,7 +147,7 @@ class AgentrClient:
122
147
  response.raise_for_status()
123
148
  return response.json()
124
149
 
125
- def list_all_tools(self) -> list[dict[str, Any]]:
150
+ def list_all_tools(self, app_id: str | None = None):
126
151
  """List all available tools from the AgentR API.
127
152
 
128
153
  Note: In the backend, tools are globally listed and not tied to a
@@ -131,11 +156,14 @@ class AgentrClient:
131
156
  Returns:
132
157
  List[Dict[str, Any]]: A list of tool configurations.
133
158
  """
134
- response = self.client.get("/tools/")
159
+ params = {}
160
+ if app_id:
161
+ params["app_id"] = app_id
162
+ response = self.client.get("/tools", params=params)
135
163
  response.raise_for_status()
136
164
  return response.json().get("items", [])
137
165
 
138
- def get_tool_details(self, tool_id: str) -> dict[str, Any]:
166
+ def get_tool_details(self, tool_id: str):
139
167
  """Fetch a specific tool configuration from the AgentR API.
140
168
 
141
169
  Args:
@@ -151,7 +179,7 @@ class AgentrClient:
151
179
  response.raise_for_status()
152
180
  return response.json()
153
181
 
154
- def search_all_apps(self, query: str, limit: int = 2) -> list[dict[str, Any]]:
182
+ def search_all_apps(self, query: str, limit: int = 2):
155
183
  """Search for apps from the AgentR API.
156
184
 
157
185
  Args:
@@ -161,17 +189,21 @@ class AgentrClient:
161
189
  Returns:
162
190
  List[Dict[str, Any]]: A list of app data dictionaries.
163
191
  """
164
- response = self.client.get("/apps/", params={"search": query, "limit": limit})
192
+ response = self.client.get("/apps", params={"search": query, "limit": limit})
165
193
  response.raise_for_status()
166
194
  return response.json().get("items", [])
167
195
 
168
- def search_all_tools(self, query: str, limit: int = 2) -> list[dict[str, Any]]:
196
+ def search_all_tools(self, query: str, limit: int = 2, app_id: str | None = None):
169
197
  """Search for tools from the AgentR API.
170
198
 
171
199
  Args:
172
200
  query (str): The query to search for.
173
201
  limit (int, optional): The number of tools to return. Defaults to 2.
202
+ app_id (str, optional): The ID of the app to search tools for.
174
203
  """
175
- response = self.client.get("/tools/", params={"search": query, "limit": limit})
204
+ params = {"search": query, "limit": limit}
205
+ if app_id:
206
+ params["app_id"] = app_id
207
+ response = self.client.get("/tools", params=params)
176
208
  response.raise_for_status()
177
209
  return response.json().get("items", [])
@@ -0,0 +1,182 @@
1
+ from typing import Any
2
+
3
+ from loguru import logger
4
+
5
+ from universal_mcp.agentr.client import AgentrClient
6
+ from universal_mcp.applications import app_from_slug
7
+ from universal_mcp.tools.manager import ToolManager, _get_app_and_tool_name
8
+ from universal_mcp.tools.registry import ToolRegistry
9
+ from universal_mcp.types import ToolConfig, ToolFormat
10
+
11
+ from .integration import AgentrIntegration
12
+
13
+
14
+ class AgentrRegistry(ToolRegistry):
15
+ """Platform manager implementation for AgentR platform."""
16
+
17
+ def __init__(self, client: AgentrClient | None = None, **kwargs):
18
+ """Initialize the AgentR platform manager."""
19
+
20
+ self.client = client or AgentrClient(**kwargs)
21
+ self.tool_manager = ToolManager()
22
+ logger.debug("AgentrRegistry initialized successfully")
23
+
24
+ async def list_all_apps(self) -> list[dict[str, Any]]:
25
+ """Get list of available apps from AgentR.
26
+
27
+ Returns:
28
+ List of app dictionaries with id, name, description, and available fields
29
+ """
30
+ if self.client is None:
31
+ raise ValueError("Client is not initialized")
32
+ try:
33
+ all_apps = self.client.list_all_apps()
34
+ return all_apps
35
+ except Exception as e:
36
+ logger.error(f"Error fetching apps from AgentR: {e}")
37
+ return []
38
+
39
+ async def get_app_details(self, app_id: str) -> dict[str, Any]:
40
+ """Get detailed information about a specific app from AgentR.
41
+
42
+ Args:
43
+ app_id: The ID of the app to get details for
44
+
45
+ Returns:
46
+ Dictionary containing app details
47
+ """
48
+ try:
49
+ app_info = self.client.get_app_details(app_id)
50
+ return app_info
51
+ except Exception as e:
52
+ logger.error(f"Error getting details for app {app_id}: {e}")
53
+ return {}
54
+
55
+ async def search_apps(
56
+ self,
57
+ query: str,
58
+ limit: int = 10,
59
+ ) -> list[dict[str, Any]]:
60
+ """Search for apps by a query.
61
+
62
+ Args:
63
+ query: The query to search for
64
+ limit: The number of apps to return
65
+
66
+ Returns:
67
+ List of app dictionaries matching the query
68
+ """
69
+ try:
70
+ apps = self.client.search_all_apps(query, limit)
71
+ return apps
72
+ except Exception as e:
73
+ logger.error(f"Error searching apps from AgentR: {e}")
74
+ return []
75
+
76
+ async def list_tools(
77
+ self,
78
+ app_id: str,
79
+ ) -> list[dict[str, Any]]:
80
+ """List all tools available on the platform, filter by app_id.
81
+
82
+ Args:
83
+ app_id: The ID of the app to list tools for
84
+
85
+ Returns:
86
+ List of tool dictionaries for the specified app
87
+ """
88
+ try:
89
+ all_tools = self.client.list_all_tools(app_id=app_id)
90
+ return all_tools
91
+ except Exception as e:
92
+ logger.error(f"Error listing tools for app {app_id}: {e}")
93
+ return []
94
+
95
+ async def search_tools(
96
+ self,
97
+ query: str,
98
+ limit: int = 2,
99
+ app_id: str | None = None,
100
+ ) -> list[dict[str, Any]]:
101
+ """Search for tools by a query.
102
+
103
+ Args:
104
+ query: The query to search for
105
+ limit: The number of tools to return
106
+ app_id: The ID of the app to list tools for
107
+ Returns:
108
+ List of tool dictionaries matching the query
109
+ """
110
+ try:
111
+ tools = self.client.search_all_tools(query, limit, app_id)
112
+ return tools
113
+ except Exception as e:
114
+ logger.error(f"Error searching tools from AgentR: {e}")
115
+ return []
116
+
117
+ async def export_tools(
118
+ self,
119
+ tools: list[str] | ToolConfig,
120
+ format: ToolFormat,
121
+ ) -> str:
122
+ """Export given tools to required format.
123
+
124
+ Args:
125
+ tools: List of tool identifiers to export
126
+ format: The format to export tools to (native, mcp, langchain, openai)
127
+
128
+ Returns:
129
+ String representation of tools in the specified format
130
+ """
131
+ try:
132
+ # Clear tools from tool manager before loading new tools
133
+ self.tool_manager.clear_tools()
134
+ if isinstance(tools, ToolConfig):
135
+ print("Loading tools from tool config")
136
+ self._load_tools_from_tool_config(tools, self.tool_manager)
137
+ else:
138
+ print("Loading tools from list")
139
+ self._load_agentr_tools_from_list(tools, self.tool_manager)
140
+ loaded_tools = self.tool_manager.list_tools(format=format)
141
+ logger.info(f"Exporting {len(loaded_tools)} tools to {format} format")
142
+ return loaded_tools
143
+ except Exception as e:
144
+ logger.error(f"Error exporting tools: {e}")
145
+ return ""
146
+
147
+ def _load_tools(self, app_name: str, tool_names: list[str], tool_manager: ToolManager) -> None:
148
+ """Helper method to load and register tools for an app."""
149
+ app = app_from_slug(app_name)
150
+ integration = AgentrIntegration(name=app_name, client=self.client)
151
+ app_instance = app(integration=integration)
152
+ tool_manager.register_tools_from_app(app_instance, tool_names=tool_names)
153
+
154
+ def _load_agentr_tools_from_list(self, tools: list[str], tool_manager: ToolManager) -> None:
155
+ """Load tools from AgentR and register them as tools.
156
+
157
+ Args:
158
+ tools: The list of tools to load (prefixed with app name)
159
+ tool_manager: The tool manager to register tools with
160
+ """
161
+ logger.info(f"Loading all tools: {tools}")
162
+ tools_by_app = {}
163
+ for tool_name in tools:
164
+ app_name, _ = _get_app_and_tool_name(tool_name)
165
+ tools_by_app.setdefault(app_name, []).append(tool_name)
166
+
167
+ for app_name, tool_names in tools_by_app.items():
168
+ self._load_tools(app_name, tool_names, tool_manager)
169
+
170
+ def _load_tools_from_tool_config(self, tool_config: ToolConfig, tool_manager: ToolManager) -> None:
171
+ """Load tools from ToolConfig and register them as tools.
172
+
173
+ Args:
174
+ tool_config: The tool configuration containing app names and tools
175
+ tool_manager: The tool manager to register tools with
176
+ """
177
+ for app_name, tool_data in tool_config.agentrServers.items():
178
+ self._load_tools(app_name, tool_data.tools, tool_manager)
179
+
180
+ async def call_tool(self, tool_name: str, tool_args: dict[str, Any]) -> dict[str, Any]:
181
+ """Call a tool with the given name and arguments."""
182
+ return await self.tool_manager.call_tool(tool_name, tool_args)
@@ -1,4 +1,4 @@
1
- from universal_mcp.agents.auto import AutoAgent
1
+ from universal_mcp.agents.autoagent import AutoAgent
2
2
  from universal_mcp.agents.base import BaseAgent
3
3
  from universal_mcp.agents.react import ReactAgent
4
4
  from universal_mcp.agents.simple import SimpleAgent
@@ -12,13 +12,12 @@ from pydantic import BaseModel
12
12
  from typing_extensions import TypedDict
13
13
 
14
14
  from universal_mcp.agentr.registry import AgentrRegistry
15
+ from universal_mcp.agents.base import BaseAgent
16
+ from universal_mcp.agents.llm import load_chat_model
15
17
  from universal_mcp.tools import ToolManager
16
18
  from universal_mcp.tools.adapters import ToolFormat
17
19
  from universal_mcp.tools.registry import ToolRegistry
18
20
 
19
- from universal_mcp.agents.base import BaseAgent
20
- from universal_mcp.agents.llm import load_chat_model
21
-
22
21
  # Auto Agent
23
22
  # Working
24
23
  # 1. For every message, and given list of tools, figure out if external tools are needed
@@ -0,0 +1,31 @@
1
+ from langgraph.checkpoint.base import BaseCheckpointSaver
2
+
3
+ from universal_mcp.agentr.registry import AgentrRegistry
4
+ from universal_mcp.agents.autoagent.graph import build_graph
5
+ from universal_mcp.agents.base import BaseAgent
6
+ from universal_mcp.tools.registry import ToolRegistry
7
+
8
+
9
+ class AutoAgent(BaseAgent):
10
+ def __init__(
11
+ self,
12
+ name: str,
13
+ instructions: str,
14
+ model: str,
15
+ memory: BaseCheckpointSaver | None = None,
16
+ registry: ToolRegistry | None = None,
17
+ **kwargs,
18
+ ):
19
+ super().__init__(name, instructions, model, memory, **kwargs)
20
+ self.tool_registry = registry or AgentrRegistry()
21
+
22
+ async def _build_graph(self):
23
+ builder = await build_graph(self.tool_registry, self.instructions)
24
+ return builder.compile(checkpointer=self.memory)
25
+
26
+ @property
27
+ def graph(self):
28
+ return self._graph
29
+
30
+
31
+ __all__ = ["AutoAgent"]
@@ -8,10 +8,10 @@ async def main():
8
8
  agent = AutoAgent(
9
9
  name="autoagent",
10
10
  instructions="You are a helpful assistant that can use tools to help the user.",
11
- model="azure/gpt-4o",
11
+ model="anthropic/claude-4-sonnet-20250514",
12
12
  tool_registry=AgentrRegistry(),
13
13
  )
14
- result = await agent.run(
14
+ result = await agent.invoke(
15
15
  user_input="Send an email to Manoj from my google mail account, manoj@agentr.dev, with the subject 'Hello from auto agent' and the body 'testing'"
16
16
  )
17
17
  print(result)
@@ -7,49 +7,65 @@ from langchain_core.tools import tool
7
7
  from langgraph.graph import END, START, StateGraph
8
8
  from langgraph.runtime import Runtime
9
9
 
10
- from universal_mcp.agents.llm import load_chat_model
11
- from universal_mcp.tools.manager import ToolManager
12
- from universal_mcp.tools.registry import ToolRegistry
13
- from universal_mcp.types import ToolFormat
14
-
15
10
  from universal_mcp.agents.autoagent.context import Context
16
11
  from universal_mcp.agents.autoagent.prompts import SYSTEM_PROMPT
17
12
  from universal_mcp.agents.autoagent.state import State
13
+ from universal_mcp.agents.llm import load_chat_model
14
+ from universal_mcp.tools.registry import ToolRegistry
15
+ from universal_mcp.types import ToolFormat
18
16
 
19
17
 
20
- def create_agent(tool_registry: ToolRegistry, tool_manager: ToolManager, instructions: str = ""):
18
+ async def build_graph(tool_registry: ToolRegistry, instructions: str = ""):
21
19
  @tool()
22
- def retrieve_tools(query: str) -> list[str]:
23
- """Retrieve tools using a search query. Use multiple times if you require tools for different tasks."""
24
- tools = tool_registry.search_tools(query)
25
- my_connections = tool_registry.client.list_my_connections()
26
- connected_apps = set(connection["app_id"] for connection in my_connections)
27
- filtered_tools = [tool for tool in tools if tool["app_id"] in connected_apps]
28
- if len(filtered_tools) == 0:
29
- return tools
30
- return filtered_tools
31
-
20
+ async def search_tools(query: str, app_ids: list[str] | None = None) -> list[str]:
21
+ """Retrieve tools using a search query and app id. Use multiple times if you require tools for different tasks."""
22
+ tools_list = []
23
+ if app_ids is not None:
24
+ for app_id in app_ids:
25
+ tools_list.extend(await tool_registry.search_tools(query, limit=10, app_id=app_id))
26
+ else:
27
+ tools_list = await tool_registry.search_tools(query, limit=10)
28
+ tools_list = [f"{tool['id']}: {tool['description']}" for tool in tools_list]
29
+ return tools_list
30
+
32
31
  @tool()
33
- def ask_user(question: str) -> str:
32
+ async def ask_user(question: str) -> str:
34
33
  """Ask the user a question. Use this tool to ask the user for any missing information for performing a task, or when you have multiple apps to choose from for performing a task."""
35
34
  full_question = question
36
35
  return f"ASKING_USER: {full_question}"
36
+
37
+ @tool()
38
+ async def load_tools(tools: list[str]) -> list[str]:
39
+ """Choose the tools you want to use by passing their tool ids. Loads the tools for the chosen tools and returns the tool ids."""
40
+ return tools
41
+
37
42
 
38
- def call_model(
43
+ async def call_model(
39
44
  state: State,
40
45
  runtime: Runtime[Context],
41
46
  ):
42
47
  system_prompt = runtime.context.system_prompt if runtime.context.system_prompt else SYSTEM_PROMPT
43
- system_prompt = system_prompt.format(system_time=datetime.now(tz=UTC).isoformat())
44
-
48
+ app_ids = await tool_registry.list_all_apps()
49
+ app_id_descriptions = "\n".join([f"{app['id']}: {app['description']}" for app in app_ids])
50
+ print(app_id_descriptions)
51
+ system_prompt = system_prompt.format(system_time=datetime.now(tz=UTC).isoformat(), app_ids=app_id_descriptions)
52
+
45
53
  messages = [{"role": "system", "content": system_prompt + "\n" + instructions}, *state["messages"]]
46
54
  model = load_chat_model(runtime.context.model)
47
55
  # Load tools from tool registry
48
- tool_registry.load_tools(tools=state["selected_tool_ids"], tool_manager=tool_manager)
49
- loaded_tools = tool_manager.list_tools(format=ToolFormat.LANGCHAIN)
50
- model_with_tools = model.bind_tools([retrieve_tools, ask_user, *loaded_tools], tool_choice="auto")
51
- response = cast(AIMessage, model_with_tools.invoke(messages))
52
- return {"messages": [response]}
56
+ loaded_tools = await tool_registry.export_tools(tools=state["selected_tool_ids"], format=ToolFormat.LANGCHAIN)
57
+ model_with_tools = model.bind_tools([search_tools, ask_user, load_tools, *loaded_tools], tool_choice="auto")
58
+ response_raw = model_with_tools.invoke(messages)
59
+ token_usage = state.get("token_usage", {})
60
+ for key in ["input_tokens", "output_tokens", "total_tokens"]:
61
+ if key in token_usage:
62
+ token_usage[key] += response_raw.usage_metadata[key]
63
+ else:
64
+ token_usage[key] = response_raw.usage_metadata[key]
65
+ print(response_raw.usage_metadata)
66
+ print(token_usage)
67
+ response = cast(AIMessage, response_raw)
68
+ return {"messages": [response], "token_usage": token_usage}
53
69
 
54
70
  # Define the conditional edge that determines whether to continue or not
55
71
  def should_continue(state: State):
@@ -58,10 +74,9 @@ def create_agent(tool_registry: ToolRegistry, tool_manager: ToolManager, instruc
58
74
  # If there is no function call, then we finish
59
75
  if not last_message.tool_calls:
60
76
  return END
61
- # Otherwise if there is, we continue
62
77
  else:
63
78
  return "tools"
64
-
79
+
65
80
  def tool_router(state: State):
66
81
  last_message = state["messages"][-1]
67
82
  if isinstance(last_message, ToolMessage):
@@ -69,35 +84,45 @@ def create_agent(tool_registry: ToolRegistry, tool_manager: ToolManager, instruc
69
84
  else:
70
85
  return END
71
86
 
72
-
73
87
  async def tool_node(state: State):
74
88
  outputs = []
75
89
  tool_ids = state["selected_tool_ids"]
76
90
  for tool_call in state["messages"][-1].tool_calls:
77
- if tool_call["name"] == retrieve_tools.name:
78
- tool_result = retrieve_tools.invoke(tool_call["args"])
79
- tool_ids = [tool["id"] for tool in tool_result]
91
+ if tool_call["name"] == ask_user.name:
80
92
  outputs.append(
81
93
  ToolMessage(
82
- content=json.dumps(tool_result),
94
+ content=json.dumps(
95
+ "The user has been asked the question, and the run will wait for the user's response."
96
+ ),
83
97
  name=tool_call["name"],
84
98
  tool_call_id=tool_call["id"],
85
99
  )
86
100
  )
87
- elif tool_call["name"] == ask_user.name:
101
+ ai_message = AIMessage(content=tool_call["args"]["question"])
102
+ outputs.append(ai_message)
103
+ elif tool_call["name"] == search_tools.name:
104
+ tools = await search_tools.ainvoke(tool_call["args"])
88
105
  outputs.append(
89
106
  ToolMessage(
90
- content=json.dumps("The user has been asked the question, and the run will wait for the user's response."),
107
+ content=json.dumps(tools)+"\n\nUse the load_tools tool to load the tools you want to use.",
108
+ name=tool_call["name"],
109
+ tool_call_id=tool_call["id"],
110
+ )
111
+ )
112
+
113
+ elif tool_call["name"] == load_tools.name:
114
+ tool_ids = await load_tools.ainvoke(tool_call["args"])
115
+ print(tool_ids)
116
+ outputs.append(
117
+ ToolMessage(
118
+ content=json.dumps(tool_ids),
91
119
  name=tool_call["name"],
92
120
  tool_call_id=tool_call["id"],
93
121
  )
94
122
  )
95
- ai_message = AIMessage(content=tool_call["args"]["question"])
96
- outputs.append(ai_message)
97
123
  else:
98
- tool_manager.clear_tools()
99
- tool_registry.load_tools([tool_call["name"]], tool_manager=tool_manager)
100
- tool_result = await tool_manager.call_tool(tool_call["name"], tool_call["args"])
124
+ await tool_registry.export_tools([tool_call["name"]], ToolFormat.LANGCHAIN)
125
+ tool_result = await tool_registry.call_tool(tool_call["name"], tool_call["args"])
101
126
  outputs.append(
102
127
  ToolMessage(
103
128
  content=json.dumps(tool_result),
@@ -107,6 +132,10 @@ def create_agent(tool_registry: ToolRegistry, tool_manager: ToolManager, instruc
107
132
  )
108
133
  return {"messages": outputs, "selected_tool_ids": tool_ids}
109
134
 
135
+
136
+
137
+
138
+
110
139
  builder = StateGraph(State, context_schema=Context)
111
140
 
112
141
  builder.add_node("agent", call_model)
@@ -0,0 +1,8 @@
1
+ """Default prompts used by the agent."""
2
+
3
+ SYSTEM_PROMPT = """You are a helpful AI assistant. When you lack tools for any task you should use the `search_tools` function to unlock relevant tools. Whenever you need to ask the user for any information, or choose between multiple different applications, you can ask the user using the `ask_user` function.
4
+
5
+ System time: {system_time}
6
+ App IDs: {app_ids}
7
+ Note that when multiple apps seem relevant for a task, you should ask the user to choose the app.
8
+ """
@@ -25,3 +25,4 @@ def _enqueue(left: list, right: list) -> list:
25
25
 
26
26
  class State(AgentState):
27
27
  selected_tool_ids: Annotated[list[str], _enqueue]
28
+ token_usage: dict[str, int]
@@ -0,0 +1,25 @@
1
+ import asyncio
2
+
3
+ from universal_mcp.agentr.registry import AgentrRegistry
4
+ from universal_mcp.agents.autoagent import build_graph
5
+ from universal_mcp.tools import ToolManager
6
+
7
+ tool_registry = AgentrRegistry()
8
+ tool_manager = ToolManager()
9
+
10
+
11
+
12
+ async def main():
13
+ instructions = """
14
+ You are a helpful assistant that can use tools to help the user. If a task requires multiple steps, you should perform separate different searches for different actions. Prefer completing one action before searching for another.
15
+ """
16
+ graph = await build_graph(tool_registry, instructions=instructions)
17
+ return graph
18
+
19
+ graph = asyncio.run(main())
20
+
21
+
22
+
23
+
24
+
25
+