@devries-cameron20 / composio Mirror · read-only / commits / d4d306073
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, 12:15 UTC

fix(sdk): save tool-only MCP updates and connection-management intent (#4512)

This PR: - closes [PLEN-3890](https://linear.app/composio/issue/PLEN-3890/fix-mcp-lifecycle-update-configuration-defects) - fixes `composio.mcp.update()` dropping parts of the requested configuration: tool-only updates (`allowedTools` without `toolkits`) sent no tools field at all, and updates with toolkits sent the create-time `custom_tools` alias, which the update endpoint never reads - inverts `manuallyManageConnections` into `managed_auth_via_composio` on update, so `manuallyManageConnections: true` no longer stores "Composio manages auth" (create and generate already inverted it) - builds the update body sparsely: each provided field is sent independently, omitted fields are left out entirely instead of being sent as `undefined` - keeps the auth config of a `{ toolkit, authConfigId }` toolkit entry in `create()` and `update()` instead of discarding it via an `else if` (Python already extracted both) - sends `allowed_tools` instead of the deprecated `custom_tools` alias from `create()` too, in both SDKs; Python previously raised `TypeError` (masked as `ValidationError`) for the removed `custom_tools` kwarg against the pinned `composio-client` 1.43.0 - adds regression coverage for both SDKs and a changeset for `@composio/core` ## Context Found by the September SDK + Composio client hackathon (Area 5, MCP lifecycle), where the two worst frictions were "successful SDK updates that do not save the requested configuration" and reversed manual connection management. The hackathon's third Area 5 finding — PATCH accepting nonexistent tool slugs — is an Apollo-side defect, fixed separately in ComposioHQ/platform#13015. `MCP.ts` and the Python `mcp.py` are identical between `next` and `main`, so this merges cleanly to the beta channel afterwards.

Alberto Schiabel committed Sep 21, 2026 at 21:37 UTC d4d306073c1ad1ab36b87db70d67a8b420bfe156
5 files changed +263 -22
.changeset/mcp-update-sparse-patch-fields.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Fix `composio.mcp.update()` silently dropping parts of the requested configuration. Tool-only updates (`allowedTools` without `toolkits`) sent no tools field at all, updates with toolkits sent the deprecated create-time `custom_tools` alias that the update endpoint ignores instead of `allowed_tools`, and `manuallyManageConnections` was forwarded as-is instead of being inverted into `managed_auth_via_composio` (so `manuallyManageConnections: true` stored the opposite configuration). `create()` and `update()` now also keep the auth config of a `{ toolkit, authConfigId }` toolkit entry instead of discarding it, and `create()` sends `allowed_tools` rather than the deprecated `custom_tools` alias, matching the Python SDK.
python/composio/core/models/mcp.py
+6 -3
@@ -214,14 +214,15 @@ class MCP(Resource):
214 auth_config_ids.append(toolkit_config["auth_config_id"])
215
216 # Use the allowed_tools parameter instead of individual toolkit configs
217 - custom_tools = none_to_omit(allowed_tools)
217 + # (`custom_tools` is the deprecated create-time alias)
218 + allowed_tools_param = none_to_omit(allowed_tools)
219
220 # Use the custom MCP create endpoint
221 response = self._client.mcp.custom.create(
222 name=name,
223 toolkits=toolkit_names,
224 auth_config_ids=auth_config_ids,
224 - custom_tools=custom_tools,
225 + allowed_tools=allowed_tools_param,
226 managed_auth_via_composio=not manually_manage_connections,
227 )
228
@@ -395,7 +396,9 @@ class MCP(Resource):
396 update_params["auth_config_ids"] = auth_config_ids
397
398 if allowed_tools is not None:
398 - update_params["custom_tools"] = allowed_tools
399 + # The update endpoint only reads `allowed_tools`; the create-time
400 + # `custom_tools` alias is deprecated and ignored on PATCH.
401 + update_params["allowed_tools"] = allowed_tools
402
403 if manually_manage_connections is not None:
404 update_params[
python/tests/test_mcp.py new
+113
@@ -0,0 +1,113 @@
1 +"""Unit tests for the MCP model's request construction.
2 +
3 +Regression coverage for the hackathon Area 5 (MCP lifecycle) findings:
4 +
5 +- Tool-only updates must reach the API through ``allowed_tools`` — the update
6 + endpoint never reads the create-time ``custom_tools`` alias, and tools must
7 + not be gated behind ``toolkits``.
8 +- ``manually_manage_connections`` must invert into
9 + ``managed_auth_via_composio`` on update, matching create/generate.
10 +- ``create`` uses the non-deprecated ``allowed_tools`` field.
11 +"""
12 +
13 +from unittest.mock import Mock
14 +
15 +import pytest
16 +
17 +from composio.core.models.mcp import MCP
18 +
19 +
20 +def _mock_update_response():
21 + response = Mock()
22 + response.id = "mcp_123"
23 + response.name = "test-server"
24 + response.allowed_tools = ["GITHUB_CREATE_ISSUE"]
25 + response.auth_config_ids = ["ac_456"]
26 + return response
27 +
28 +
29 +@pytest.fixture
30 +def mcp():
31 + client = Mock()
32 + client.mcp.update = Mock(return_value=_mock_update_response())
33 + client.mcp.custom.create = Mock(return_value=_mock_update_response())
34 + return MCP(client)
35 +
36 +
37 +def test_update_sends_tool_only_updates_via_allowed_tools(mcp):
38 + """A tool-only update (no toolkits) must send `allowed_tools`."""
39 + mcp.update("mcp_123", allowed_tools=["GITHUB_CREATE_ISSUE"])
40 +
41 + mcp._client.mcp.update.assert_called_once_with(
42 + "mcp_123",
43 + allowed_tools=["GITHUB_CREATE_ISSUE"],
44 + )
45 +
46 +
47 +def test_update_does_not_send_custom_tools_alias(mcp):
48 + """`custom_tools` is not part of the update contract and is dropped
49 + server-side; the SDK must never send it."""
50 + mcp.update(
51 + "mcp_123",
52 + toolkits=["github"],
53 + allowed_tools=["GITHUB_CREATE_ISSUE"],
54 + )
55 +
56 + call_kwargs = mcp._client.mcp.update.call_args.kwargs
57 + assert "custom_tools" not in call_kwargs
58 + assert call_kwargs["allowed_tools"] == ["GITHUB_CREATE_ISSUE"]
59 + assert call_kwargs["toolkits"] == ["github"]
60 + assert call_kwargs["auth_config_ids"] == []
61 +
62 +
63 +def test_update_inverts_manually_manage_connections(mcp):
64 + """`manually_manage_connections=True` must store
65 + `managed_auth_via_composio=False`, consistent with create/generate."""
66 + mcp.update("mcp_123", manually_manage_connections=True)
67 + assert mcp._client.mcp.update.call_args.kwargs["managed_auth_via_composio"] is False
68 +
69 + mcp.update("mcp_123", manually_manage_connections=False)
70 + assert mcp._client.mcp.update.call_args.kwargs["managed_auth_via_composio"] is True
71 +
72 +
73 +def test_update_omits_unset_fields(mcp):
74 + """A sparse update must only send the fields the caller provided."""
75 + mcp.update("mcp_123", name="renamed")
76 +
77 + mcp._client.mcp.update.assert_called_once_with("mcp_123", name="renamed")
78 +
79 +
80 +def test_update_extracts_toolkit_and_auth_config_from_combo_entry(mcp):
81 + """A `{toolkit, auth_config_id}` entry contributes to both lists,
82 + matching the documented behavior."""
83 + mcp.update(
84 + "mcp_123",
85 + toolkits=[{"toolkit": "github", "auth_config_id": "ac_456"}],
86 + )
87 +
88 + call_kwargs = mcp._client.mcp.update.call_args.kwargs
89 + assert call_kwargs["toolkits"] == ["github"]
90 + assert call_kwargs["auth_config_ids"] == ["ac_456"]
91 +
92 +
93 +def test_create_sends_allowed_tools_not_custom_tools(mcp):
94 + """Create should use the non-deprecated `allowed_tools` field."""
95 + mcp.create("test-server", toolkits=["github"], allowed_tools=["TOOL_A"])
96 +
97 + call_kwargs = mcp._client.mcp.custom.create.call_args.kwargs
98 + assert "custom_tools" not in call_kwargs
99 + assert call_kwargs["allowed_tools"] == ["TOOL_A"]
100 +
101 +
102 +def test_create_inverts_manually_manage_connections(mcp):
103 + mcp.create("test-server", toolkits=["github"], manually_manage_connections=True)
104 + assert (
105 + mcp._client.mcp.custom.create.call_args.kwargs["managed_auth_via_composio"]
106 + is False
107 + )
108 +
109 + mcp.create("test-server", toolkits=["github"], manually_manage_connections=False)
110 + assert (
111 + mcp._client.mcp.custom.create.call_args.kwargs["managed_auth_via_composio"]
112 + is True
113 + )
ts/packages/core/src/models/MCP.ts
+29 -15
@@ -99,16 +99,19 @@ export class MCP {
99
100 const toolkits: string[] = [];
101 const auth_config_ids: string[] = [];
102 - const custom_tools: string[] = config.data.allowedTools ?? [];
102 + const allowed_tools: string[] = config.data.allowedTools ?? [];
103
104 // extract all the toolkits, authconfigs, and allowed tools to separate slugs
105 config.data.toolkits.forEach(toolkit => {
106 if (typeof toolkit === 'string') {
107 toolkits.push(toolkit);
108 - } else if (toolkit.toolkit) {
109 - toolkits.push(toolkit.toolkit);
110 - } else if (toolkit.authConfigId) {
111 - auth_config_ids.push(toolkit.authConfigId);
108 + } else {
109 + if (toolkit.toolkit) {
110 + toolkits.push(toolkit.toolkit);
111 + }
112 + if (toolkit.authConfigId) {
113 + auth_config_ids.push(toolkit.authConfigId);
114 + }
115 }
116 });
117
@@ -116,7 +119,7 @@ export class MCP {
119 name,
120 toolkits,
121 auth_config_ids,
119 - custom_tools,
122 + allowed_tools,
123 // if manually manage account is set to true, disable composio account management tools
124 managed_auth_via_composio: config.data.manuallyManageConnections ? false : true,
125 };
@@ -380,28 +383,39 @@ export class MCP {
383
384 const toolkits: string[] = [];
385 const auth_config_ids: string[] = [];
383 - const custom_tools: string[] | undefined = params.allowedTools ?? undefined;
386
387 // extract all the toolkits, authconfigs, and allowed tools to separate slugs
388 params.toolkits?.forEach(toolkit => {
389 if (typeof toolkit === 'string') {
390 toolkits.push(toolkit);
389 - } else if (toolkit.toolkit) {
390 - toolkits.push(toolkit.toolkit);
391 - } else if (toolkit.authConfigId) {
392 - auth_config_ids.push(toolkit.authConfigId);
391 + } else {
392 + if (toolkit.toolkit) {
393 + toolkits.push(toolkit.toolkit);
394 + }
395 + if (toolkit.authConfigId) {
396 + auth_config_ids.push(toolkit.authConfigId);
397 + }
398 }
399 });
400 +
401 + // Build a sparse PATCH body: only fields the caller provided are sent, so omitted
402 + // fields keep their current server-side values. `allowed_tools` is sent whenever it
403 + // is provided, independently of `toolkits` (tool-only updates are valid), and must
404 + // use the API field `allowed_tools` — the update endpoint does not read the
405 + // deprecated create-only alias `custom_tools`. `manuallyManageConnections` is
406 + // inverted into `managed_auth_via_composio`, matching create() and generate().
407 const updateBody = {
396 - ...{ name: params.name ?? undefined },
397 - ...(params.toolkits
408 + ...(params.name !== undefined ? { name: params.name } : {}),
409 + ...(params.toolkits !== undefined
410 ? {
399 - custom_tools: custom_tools,
411 toolkits: toolkits,
412 auth_config_ids: auth_config_ids,
413 }
414 : {}),
404 - ...{ managed_auth_via_composio: params.manuallyManageConnections ?? undefined },
415 + ...(params.allowedTools !== undefined ? { allowed_tools: params.allowedTools } : {}),
416 + ...(params.manuallyManageConnections !== undefined
417 + ? { managed_auth_via_composio: !params.manuallyManageConnections }
418 + : {}),
419 };
420 const response = await withCancellation(
421 () => this.client.mcp.update(serverId, updateBody, requestOptions),
ts/packages/core/test/models/mcp.test.ts
+110 -4
@@ -80,7 +80,7 @@ describe('MCP', () => {
80 name: 'test-server',
81 toolkits: ['gmail'],
82 auth_config_ids: [],
83 - custom_tools: [],
83 + allowed_tools: [],
84 managed_auth_via_composio: true,
85 },
86 undefined
@@ -111,8 +111,8 @@ describe('MCP', () => {
111 {
112 name: 'test-server',
113 toolkits: ['gmail'],
114 - auth_config_ids: [],
115 - custom_tools: [],
114 + auth_config_ids: ['auth_456'],
115 + allowed_tools: [],
116 managed_auth_via_composio: true,
117 },
118 undefined
@@ -280,7 +280,6 @@ describe('MCP', () => {
280 'mcp_123',
281 {
282 name: 'updated-server',
283 - custom_tools: undefined,
283 toolkits: ['slack'],
284 auth_config_ids: [],
285 },
@@ -288,6 +287,113 @@ describe('MCP', () => {
287 );
288 });
289
290 + it('should send tool-only updates through allowed_tools without toolkits', async () => {
291 + const mockResponse = {
292 + id: 'mcp_123',
293 + name: 'test-server',
294 + allowed_tools: ['GITHUB_CREATE_ISSUE'],
295 + auth_config_ids: ['auth_456'],
296 + commands: {
297 + claude: 'cmd',
298 + cursor: 'cmd',
299 + windsurf: 'cmd',
300 + },
301 + mcp_url: 'https://mcp.example.com',
302 + toolkit_icons: {},
303 + server_instance_count: 1,
304 + toolkits: ['github'],
305 + };
306 +
307 + mockClient.mcp.update.mockResolvedValueOnce(mockResponse);
308 +
309 + await mcp.update('mcp_123', { allowedTools: ['GITHUB_CREATE_ISSUE'] });
310 +
311 + expect(mockClient.mcp.update).toHaveBeenCalledWith(
312 + 'mcp_123',
313 + { allowed_tools: ['GITHUB_CREATE_ISSUE'] },
314 + undefined
315 + );
316 + });
317 +
318 + it('should send allowed_tools alongside toolkits when both are provided', async () => {
319 + const mockResponse = {
320 + id: 'mcp_123',
321 + name: 'test-server',
322 + allowed_tools: ['GITHUB_CREATE_ISSUE'],
323 + auth_config_ids: ['auth_456'],
324 + commands: {
325 + claude: 'cmd',
326 + cursor: 'cmd',
327 + windsurf: 'cmd',
328 + },
329 + mcp_url: 'https://mcp.example.com',
330 + toolkit_icons: {},
331 + server_instance_count: 1,
332 + toolkits: ['github'],
333 + };
334 +
335 + mockClient.mcp.update.mockResolvedValueOnce(mockResponse);
336 +
337 + await mcp.update('mcp_123', {
338 + toolkits: [{ toolkit: 'github', authConfigId: 'auth_456' }],
339 + allowedTools: ['GITHUB_CREATE_ISSUE'],
340 + });
341 +
342 + expect(mockClient.mcp.update).toHaveBeenCalledWith(
343 + 'mcp_123',
344 + {
345 + toolkits: ['github'],
346 + auth_config_ids: ['auth_456'],
347 + allowed_tools: ['GITHUB_CREATE_ISSUE'],
348 + },
349 + undefined
350 + );
351 + });
352 +
353 + it('should invert manuallyManageConnections into managed_auth_via_composio', async () => {
354 + const mockResponse = {
355 + id: 'mcp_123',
356 + name: 'test-server',
357 + allowed_tools: [],
358 + auth_config_ids: [],
359 + commands: {
360 + claude: 'cmd',
361 + cursor: 'cmd',
362 + windsurf: 'cmd',
363 + },
364 + mcp_url: 'https://mcp.example.com',
365 + toolkit_icons: {},
366 + server_instance_count: 1,
367 + toolkits: [],
368 + };
369 +
370 + mockClient.mcp.update.mockResolvedValue(mockResponse);
371 +
372 + // manuallyManageConnections: true means Composio does NOT manage auth
373 + await mcp.update('mcp_123', { manuallyManageConnections: true });
374 + expect(mockClient.mcp.update).toHaveBeenLastCalledWith(
375 + 'mcp_123',
376 + { managed_auth_via_composio: false },
377 + undefined
378 + );
379 +
380 + // manuallyManageConnections: false means Composio DOES manage auth
381 + await mcp.update('mcp_123', { manuallyManageConnections: false });
382 + expect(mockClient.mcp.update).toHaveBeenLastCalledWith(
383 + 'mcp_123',
384 + { managed_auth_via_composio: true },
385 + undefined
386 + );
387 +
388 + // Omitting the flag must not send the field at all (sparse PATCH)
389 + await mcp.update('mcp_123', { name: 'same-name' });
390 + expect(mockClient.mcp.update).toHaveBeenLastCalledWith(
391 + 'mcp_123',
392 + { name: 'same-name' },
393 + undefined
394 + );
395 + });
396 +
397 it('should validate update parameters', async () => {
398 await expect(mcp.update('mcp_123', { toolkits: 'invalid' as unknown })).rejects.toThrow(
399 ValidationError