@devries-cameron20 / composio Mirror · read-only / commits / ec55dd13d
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 09:45 UTC

feat: forward user_id on tool proxy execute (#4772)

## Summary Proxy execute is getting the same `user_id` 2FA check that trigger upsert/patch got (#3576). This adds `user_id` to the SDK proxy calls so callers can send it: - **TS:** `composio.tools.proxyExecute({ ..., connectedAccountId, userId })` sends `user_id`. - **Python:** `composio.tools.proxy(..., connected_account_id=..., user_id=...)` sends `user_id`. On projects with 2FA enabled, the backend checks `user_id` against the connected account. For orgs created on or after 2026-10-12 it also refuses calls that don't send it. Without this change, those orgs can't use proxy execute from the SDK. ## Notes - **Mergeable now.** It doesn't wait on a client regen the way #3576 did. The current backend drops unknown body fields, so sending `user_id` before the backend change deploys is a no-op. - **TS:** the field goes into the existing `proxyBody` cast. - **Python:** the generated `composio-client` doesn't yet have `user_id` on `tools.proxy`, so it goes through `extra_body`. A TODO marks where to switch to the native param once the client is regenerated. - **Changeset:** `@composio/core` minor. ## Tests - TS `tools.test.ts`: `userId` is forwarded as `user_id`. - Python `test_tools_proxy.py`: checks the HTTP request body. `user_id` is sent when passed and left out otherwise. - Ran: `pnpm --filter @composio/core typecheck`, `oxlint`, the vitest `proxyExecute` suite, `nox -s chk`, and pytest for `test_tools_proxy.py` and `test_no_retry_writes.py`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Anshu Garg [zen] <anshu@composio.dev> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

composio-zen[bot] committed Oct 9, 2026 at 18:41 UTC ec55dd13dbfa67a3886352e58676f84180c2c79a
6 files changed +88 -1
.changeset/proxy-execute-user-id.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': minor
3 +---
4 +
5 +Add `userId` to `tools.proxyExecute()`. It is sent as `user_id`, which projects with 2FA enabled check against the connected account and may require. Python's `tools.proxy()` takes the same value as `user_id`.
python/composio/core/models/tools.py
+9 -1
@@ -882,8 +882,13 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
882 custom_connection_data: t.Optional[
883 tool_proxy_params.CustomConnectionData
884 ] = None,
885 + user_id: t.Optional[str] = None,
886 ) -> tool_proxy_response.ToolProxyResponse:
886 - """Proxy a tool call to the Composio API"""
887 + """Proxy a tool call to the Composio API.
888 +
889 + ``user_id`` is the user the connected account belongs to. Projects with
890 + 2FA enabled check it against the connected account and may require it.
891 + """
892 # Disable retries: a proxied call is a non-idempotent write, and a silent
893 # retry after a read timeout can duplicate the side effect.
894 return self._client.without_retries.tools.proxy(
@@ -897,6 +902,9 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
902 custom_connection_data=custom_connection_data
903 if custom_connection_data is not None
904 else omit,
905 + # TODO: pass `user_id` natively once composio-client is regenerated
906 + # with it on the proxy endpoint.
907 + extra_body={"user_id": user_id} if user_id is not None else None,
908 )
909
910
python/tests/test_tools_proxy.py new
+50
@@ -0,0 +1,50 @@
1 +"""Request body sent by ``Tools.proxy``."""
2 +
3 +import json
4 +import typing as t
5 +from unittest.mock import Mock
6 +
7 +import httpx
8 +import pytest
9 +
10 +from composio.client import HttpClient
11 +from composio.core.models.base import allow_tracking
12 +from composio.core.models.tools import Tools
13 +
14 +
15 +@pytest.fixture(autouse=True)
16 +def disable_telemetry():
17 + token = allow_tracking.set(False)
18 + yield
19 + allow_tracking.reset(token)
20 +
21 +
22 +def _proxy_body(**kwargs: t.Any) -> t.Dict[str, t.Any]:
23 + requests: t.List[httpx.Request] = []
24 +
25 + def handler(request: httpx.Request) -> httpx.Response:
26 + requests.append(request)
27 + return httpx.Response(200, json={"status": 200, "data": {}})
28 +
29 + client = HttpClient(
30 + provider="test",
31 + api_key="sk-test",
32 + base_url="https://backend.invalid",
33 + http_client=httpx.Client(transport=httpx.MockTransport(handler)),
34 + )
35 + Tools(client=client, provider=Mock()).proxy(
36 + endpoint="/any", method="GET", connected_account_id="ca_123", **kwargs
37 + )
38 + assert len(requests) == 1
39 + return json.loads(requests[0].content)
40 +
41 +
42 +def test_proxy_forwards_user_id() -> None:
43 + body = _proxy_body(user_id="user-123")
44 +
45 + assert body["connected_account_id"] == "ca_123"
46 + assert body["user_id"] == "user-123"
47 +
48 +
49 +def test_proxy_omits_user_id_when_not_passed() -> None:
50 + assert "user_id" not in _proxy_body()
ts/packages/core/src/models/Tools.ts
+2
@@ -1336,6 +1336,7 @@ export class Tools<
1336 * @param {string} body.endpoint - Path relative to the toolkit's base URL, or an absolute URL
1337 * @param {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'} body.method - HTTP method
1338 * @param {string} [body.connectedAccountId] - The connected account to authenticate as
1339 + * @param {string} [body.userId] - The user the connected account belongs to. Projects with 2FA enabled check it against the connected account and may require it
1340 * @param {unknown} [body.body] - JSON request body
1341 * @param {Array<{ in: 'query' | 'header'; name: string; value: string | number }>} [body.parameters] - Extra query parameters or headers
1342 * @returns {Promise<ToolProxyResponse>} The upstream status, headers, and parsed body
@@ -1383,6 +1384,7 @@ export class Tools<
1384 method: toolProxyParams.data.method,
1385 body: toolProxyParams.data.body,
1386 connected_account_id: toolProxyParams.data.connectedAccountId,
1387 + user_id: toolProxyParams.data.userId,
1388 parameters: parameters,
1389 /**
1390 * @deprecated The `customConnectionData` proxy param is deprecated and will be
ts/packages/core/src/types/tool.types.ts
+5
@@ -426,6 +426,11 @@ export const ToolProxyParamsSchema = z.object({
426 )
427 .optional(),
428 connectedAccountId: z.string().optional(),
429 + /**
430 + * The user the connected account belongs to. Projects with 2FA enabled check it
431 + * against the connected account, and require it for orgs created on or after
432 + */
433 + userId: z.string().optional(),
434 /**
435 * @deprecated
436 */
ts/packages/core/test/tools/tools.test.ts
+17
@@ -1123,6 +1123,23 @@ describe('Tools', () => {
1123 expect(result).toEqual(expectedProxyResponse);
1124 });
1125
1126 + it('should forward userId as user_id', async () => {
1127 + const expectedProxyResponse = { data: { ok: true }, status: 200 };
1128 + mockClient.tools.proxy.mockResolvedValueOnce(expectedProxyResponse);
1129 +
1130 + await context.tools.proxyExecute({
1131 + endpoint: '/api/test',
1132 + method: 'GET',
1133 + connectedAccountId: 'test-account-id',
1134 + userId: 'user-123',
1135 + });
1136 +
1137 + expect(mockClient.tools.proxy).toHaveBeenCalledWith(
1138 + expect.objectContaining({ connected_account_id: 'test-account-id', user_id: 'user-123' }),
1139 + { maxRetries: 0 }
1140 + );
1141 + });
1142 +
1143 it('should handle proxy request with only header parameters', async () => {
1144 const proxyParams = {
1145 endpoint: '/api/headers-only',