universal-mcp 0.1.24rc7__tar.gz → 0.1.24rc9__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 (96) hide show
  1. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/.gitignore +1 -0
  2. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/PKG-INFO +1 -1
  3. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/pyproject.toml +1 -1
  4. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agentr/__init__.py +1 -2
  5. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agentr/client.py +56 -24
  6. universal_mcp-0.1.24rc9/src/universal_mcp/agentr/registry.py +182 -0
  7. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/__init__.py +1 -1
  8. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/auto.py +2 -3
  9. universal_mcp-0.1.24rc9/src/universal_mcp/agents/autoagent/__init__.py +31 -0
  10. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/autoagent/__main__.py +2 -2
  11. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/autoagent/context.py +1 -0
  12. universal_mcp-0.1.24rc9/src/universal_mcp/agents/autoagent/graph.py +161 -0
  13. universal_mcp-0.1.24rc9/src/universal_mcp/agents/autoagent/prompts.py +9 -0
  14. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/autoagent/state.py +1 -0
  15. universal_mcp-0.1.24rc9/src/universal_mcp/agents/autoagent/studio.py +25 -0
  16. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/base.py +12 -10
  17. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/llm.py +3 -1
  18. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/react.py +25 -7
  19. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/simple.py +11 -11
  20. universal_mcp-0.1.24rc9/src/universal_mcp/tools/registry.py +83 -0
  21. universal_mcp-0.1.24rc7/src/universal_mcp/agentr/agentr.py +0 -37
  22. universal_mcp-0.1.24rc7/src/universal_mcp/agentr/registry.py +0 -87
  23. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/__init__.py +0 -35
  24. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/graph.py +0 -119
  25. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/prompts.py +0 -5
  26. universal_mcp-0.1.24rc7/src/universal_mcp/agents/autoagent/studio.py +0 -25
  27. universal_mcp-0.1.24rc7/src/universal_mcp/tools/registry.py +0 -51
  28. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/LICENSE +0 -0
  29. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/README.md +0 -0
  30. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/__init__.py +0 -0
  31. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/conftest.py +0 -0
  32. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_api_generator.py +0 -0
  33. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_api_integration.py +0 -0
  34. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_applications.py +0 -0
  35. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_localserver.py +0 -0
  36. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_stores.py +0 -0
  37. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_tool.py +0 -0
  38. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_tool_manager.py +0 -0
  39. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/tests/test_zenquotes.py +0 -0
  40. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/__init__.py +0 -0
  41. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agentr/README.md +0 -0
  42. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agentr/integration.py +0 -0
  43. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agentr/server.py +0 -0
  44. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/autoagent/utils.py +0 -0
  45. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/cli.py +0 -0
  46. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/codeact/__init__.py +0 -0
  47. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/codeact/sandbox.py +0 -0
  48. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/codeact/test.py +0 -0
  49. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/codeact/utils.py +0 -0
  50. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/hil.py +0 -0
  51. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/tools.py +0 -0
  52. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/agents/utils.py +0 -0
  53. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/analytics.py +0 -0
  54. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/applications/__init__.py +0 -0
  55. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/applications/application.py +0 -0
  56. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/applications/sample/app.py +0 -0
  57. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/cli.py +0 -0
  58. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/client/oauth.py +0 -0
  59. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/client/token_store.py +0 -0
  60. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/client/transport.py +0 -0
  61. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/config.py +0 -0
  62. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/exceptions.py +0 -0
  63. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/integrations/__init__.py +0 -0
  64. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/integrations/integration.py +0 -0
  65. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/logger.py +0 -0
  66. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/py.typed +0 -0
  67. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/servers/__init__.py +0 -0
  68. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/servers/server.py +0 -0
  69. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/stores/__init__.py +0 -0
  70. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/stores/store.py +0 -0
  71. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/__init__.py +0 -0
  72. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/adapters.py +0 -0
  73. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/docstring_parser.py +0 -0
  74. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/func_metadata.py +0 -0
  75. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/manager.py +0 -0
  76. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/tools/tools.py +0 -0
  77. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/types.py +0 -0
  78. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/__init__.py +0 -0
  79. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/common.py +0 -0
  80. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/installation.py +0 -0
  81. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/__inti__.py +0 -0
  82. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/api_generator.py +0 -0
  83. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/api_splitter.py +0 -0
  84. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/cli.py +0 -0
  85. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/docgen.py +0 -0
  86. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/filters.py +0 -0
  87. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/openapi.py +0 -0
  88. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/postprocessor.py +0 -0
  89. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/preprocessor.py +0 -0
  90. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/readme.py +0 -0
  91. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/openapi/test_generator.py +0 -0
  92. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/prompts.py +0 -0
  93. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/singleton.py +0 -0
  94. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/templates/README.md.j2 +0 -0
  95. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/templates/api_client.py.j2 +0 -0
  96. {universal_mcp-0.1.24rc7 → universal_mcp-0.1.24rc9}/src/universal_mcp/utils/testing.py +0 -0
@@ -57,3 +57,4 @@ site/
57
57
  # langgraph temporary files
58
58
  .langgraph_api/
59
59
  langgraph.json
60
+ agentr-1-6c4ebd5cc914.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: universal-mcp
3
- Version: 0.1.24rc7
3
+ Version: 0.1.24rc9
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-rc9"
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.
@@ -49,6 +73,7 @@ class AgentrClient:
49
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)
@@ -68,12 +93,12 @@ class AgentrClient:
68
93
  Raises:
69
94
  HTTPError: If the API request fails.
70
95
  """
71
- response = self.client.post("/connections/authorize", json={"app_id": app_id})
96
+ response = self.client.post("/connections/authorize/", json={"app_id": app_id})
72
97
  response.raise_for_status()
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,7 +111,7 @@ 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:
@@ -96,7 +121,7 @@ class AgentrClient:
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:
@@ -106,7 +131,7 @@ class AgentrClient:
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:
@@ -118,11 +143,11 @@ class AgentrClient:
118
143
  Raises:
119
144
  httpx.HTTPError: If the API request fails.
120
145
  """
121
- response = self.client.get(f"/apps/{app_id}")
146
+ response = self.client.get(f"/apps/{app_id}/")
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:
@@ -147,11 +175,11 @@ class AgentrClient:
147
175
  Raises:
148
176
  httpx.HTTPError: If the API request fails.
149
177
  """
150
- response = self.client.get(f"/tools/{tool_id}")
178
+ response = self.client.get(f"/tools/{tool_id}/")
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:
@@ -165,13 +193,17 @@ class AgentrClient:
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)
@@ -18,6 +18,7 @@ class Context:
18
18
 
19
19
  model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
20
20
  default="anthropic/claude-4-sonnet-20250514",
21
+ # default="vertex/gemini-2.5-flash",
21
22
  metadata={
22
23
  "description": "The name of the language model to use for the agent's main interactions. "
23
24
  "Should be in the form: provider/model-name."
@@ -0,0 +1,161 @@
1
+ import json
2
+ from datetime import UTC, datetime
3
+ from typing import cast
4
+
5
+ from langchain_core.messages import AIMessage, ToolMessage
6
+ from langchain_core.tools import tool
7
+ from langgraph.graph import END, START, StateGraph
8
+ from langgraph.runtime import Runtime
9
+
10
+ from universal_mcp.agents.autoagent.context import Context
11
+ from universal_mcp.agents.autoagent.prompts import SYSTEM_PROMPT
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
16
+
17
+
18
+ async def build_graph(tool_registry: ToolRegistry, instructions: str = ""):
19
+ @tool()
20
+ async def search_tools(query: str, app_ids: list[str] | None = None) -> list[str]:
21
+ """Retrieve tools using a search query and a list of app ids. Use multiple times if you require tools for different queries."""
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
+
31
+ @tool()
32
+ async def ask_user(question: str) -> str:
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."""
34
+ full_question = question
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
+
42
+
43
+ async def call_model(
44
+ state: State,
45
+ runtime: Runtime[Context],
46
+ ):
47
+ system_prompt = runtime.context.system_prompt if runtime.context.system_prompt else SYSTEM_PROMPT
48
+ app_ids = await tool_registry.list_all_apps()
49
+ connections = tool_registry.client.list_my_connections()
50
+ connection_ids = set([connection["app_id"] for connection in connections])
51
+ connected_apps = [app['id'] for app in app_ids if app["id"] in connection_ids]
52
+ unconnected_apps = [app['id'] for app in app_ids if app["id"] not in connection_ids]
53
+ app_id_descriptions = "These are the apps connected to the user's account:\n" + "\n".join([f"{app}" for app in connected_apps])
54
+ if unconnected_apps:
55
+ app_id_descriptions += "\n\nOther (not connected) apps: " + "\n".join([f"{app}" for app in unconnected_apps])
56
+ print(app_id_descriptions)
57
+ system_prompt = system_prompt.format(system_time=datetime.now(tz=UTC).isoformat(), app_ids=app_id_descriptions)
58
+
59
+ messages = [{"role": "system", "content": system_prompt + "\n" + instructions}, *state["messages"]]
60
+ model = load_chat_model(runtime.context.model)
61
+ # Load tools from tool registry
62
+ loaded_tools = await tool_registry.export_tools(tools=state["selected_tool_ids"], format=ToolFormat.LANGCHAIN)
63
+ model_with_tools = model.bind_tools([search_tools, ask_user, load_tools, *loaded_tools], tool_choice="auto")
64
+ response_raw = model_with_tools.invoke(messages)
65
+ token_usage = state.get("token_usage", {})
66
+ for key in ["input_tokens", "output_tokens", "total_tokens"]:
67
+ if key in token_usage:
68
+ token_usage[key] += response_raw.usage_metadata[key]
69
+ else:
70
+ token_usage[key] = response_raw.usage_metadata[key]
71
+ response = cast(AIMessage, response_raw)
72
+ return {"messages": [response], "token_usage": token_usage}
73
+
74
+ # Define the conditional edge that determines whether to continue or not
75
+ def should_continue(state: State):
76
+ messages = state["messages"]
77
+ last_message = messages[-1]
78
+ # If there is no function call, then we finish
79
+ if not last_message.tool_calls:
80
+ return END
81
+ else:
82
+ return "tools"
83
+
84
+ def tool_router(state: State):
85
+ last_message = state["messages"][-1]
86
+ if isinstance(last_message, ToolMessage):
87
+ return "agent"
88
+ else:
89
+ return END
90
+
91
+ async def tool_node(state: State):
92
+ outputs = []
93
+ tool_ids = state["selected_tool_ids"]
94
+ for tool_call in state["messages"][-1].tool_calls:
95
+ if tool_call["name"] == ask_user.name:
96
+ outputs.append(
97
+ ToolMessage(
98
+ content=json.dumps(
99
+ "The user has been asked the question, and the run will wait for the user's response."
100
+ ),
101
+ name=tool_call["name"],
102
+ tool_call_id=tool_call["id"],
103
+ )
104
+ )
105
+ ai_message = AIMessage(content=tool_call["args"]["question"])
106
+ outputs.append(ai_message)
107
+ elif tool_call["name"] == search_tools.name:
108
+ tools = await search_tools.ainvoke(tool_call["args"])
109
+ outputs.append(
110
+ ToolMessage(
111
+ content=json.dumps(tools)+"\n\nUse the load_tools tool to load the tools you want to use.",
112
+ name=tool_call["name"],
113
+ tool_call_id=tool_call["id"],
114
+ )
115
+ )
116
+
117
+ elif tool_call["name"] == load_tools.name:
118
+ tool_ids = await load_tools.ainvoke(tool_call["args"])
119
+ print(tool_ids)
120
+ outputs.append(
121
+ ToolMessage(
122
+ content=json.dumps(tool_ids),
123
+ name=tool_call["name"],
124
+ tool_call_id=tool_call["id"],
125
+ )
126
+ )
127
+ else:
128
+ await tool_registry.export_tools([tool_call["name"]], ToolFormat.LANGCHAIN)
129
+ try:
130
+ tool_result = await tool_registry.call_tool(tool_call["name"], tool_call["args"])
131
+ outputs.append(
132
+ ToolMessage(
133
+ content=json.dumps(tool_result),
134
+ name=tool_call["name"],
135
+ tool_call_id=tool_call["id"],
136
+ )
137
+ )
138
+ except Exception as e:
139
+ outputs.append(
140
+ ToolMessage(
141
+ content=json.dumps("Error: "+str(e)),
142
+ name=tool_call["name"],
143
+ tool_call_id=tool_call["id"],
144
+ )
145
+ )
146
+ return {"messages": outputs, "selected_tool_ids": tool_ids}
147
+
148
+
149
+
150
+
151
+
152
+ builder = StateGraph(State, context_schema=Context)
153
+
154
+ builder.add_node("agent", call_model)
155
+ builder.add_node("tools", tool_node)
156
+
157
+ builder.add_edge(START, "agent")
158
+ builder.add_conditional_edges("agent", should_continue)
159
+ builder.add_conditional_edges("tools", tool_router)
160
+
161
+ return builder
@@ -0,0 +1,9 @@
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
+ These are the list of apps available to you:
7
+ {app_ids}
8
+ Note that when multiple apps seem relevant for a task, you MUST ask the user to choose the app. Prefer connected apps over unconnected apps while breaking a tie. If more than one relevant app (or none of the relevant apps) are connected, you must ask the user to choose the app.
9
+ """
@@ -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
+