From 6e65b32e6e6a79c17869f041a75629e4cc895a3f Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Thu, 12 Nov 2026 09:50:59 -0800 Subject: [PATCH] feat(agent-vault): read allowedTools on a session's MCP servers An MCP server sent with a session can now be limited to some of its tools (Infisical/infisical#9418). AgentVaultInlineService keeps allowedTools, which from_dict used to drop as an unknown field, and the sessions.create docs say how to send it instead of saying inline MCP servers can't be limited. Co-Authored-By: Claude Opus 5.5 --- infisical_sdk/api_types.py | 3 ++- infisical_sdk/resources/agent_vault.py | 2 +- tests/test_agent_vault.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/infisical_sdk/api_types.py b/infisical_sdk/api_types.py index 4512016..c43d589 100644 --- a/infisical_sdk/api_types.py +++ b/infisical_sdk/api_types.py @@ -567,7 +567,7 @@ class AgentVaultSessionAccessBundle(BaseModel): @dataclass class AgentVaultInlineService(BaseModel): - """A service sent with an Agent Vault session, without its token, password or values. type is http, mcp, postgres, mysql or ssh, and the API returns only that type's fields: hostPattern, allowedMethods, allowedPathPrefixes, customHeaders and substitutions for http; serverUrl, transport, hostPattern and customHeaders for mcp; host, port, database and tls for postgres and mysql; host and port for ssh. Its nested settings, such as credential and tls, are left as the API returns them.""" + """A service sent with an Agent Vault session, without its token, password or values. type is http, mcp, postgres, mysql or ssh, and the API returns only that type's fields: hostPattern, allowedMethods, allowedPathPrefixes, customHeaders and substitutions for http; serverUrl, transport, hostPattern, allowedTools and customHeaders for mcp; host, port, database and tls for postgres and mysql; host and port for ssh. allowedTools is None when an MCP server allows every tool, or when the Infisical version doesn't return it. Its nested settings, such as credential and tls, are left as the API returns them.""" id: str name: str type: str @@ -584,6 +584,7 @@ class AgentVaultInlineService(BaseModel): port: Optional[int] = None database: Optional[str] = None tls: Optional[Dict[str, Any]] = None + allowedTools: Optional[List[str]] = None @dataclass class AgentVaultSession(BaseModel): diff --git a/infisical_sdk/resources/agent_vault.py b/infisical_sdk/resources/agent_vault.py index d7da6b9..612e80a 100644 --- a/infisical_sdk/resources/agent_vault.py +++ b/infisical_sdk/resources/agent_vault.py @@ -346,7 +346,7 @@ def create( label: A short description of what the session is for, such as "nightly deploy". Up to 128 characters, without line breaks, tabs, or invisible characters. on_behalf_of_user_email: The email address of the user to start the session on behalf of. Can't be combined with on_behalf_of_user_id. on_behalf_of_user_id: The ID of the user to start the session on behalf of. Can't be combined with on_behalf_of_user_email. - services: Services the session carries itself, instead of or beside its access bundle's: up to 20 dicts with the API's field names, such as {"type": "http", "hostPattern": "api.github.com", "credential": {"type": "bearer", "value": token}}. Only Agent Vault admins can send them. Each has the same fields as a service in an access bundle, except that its name is optional for HTTP and MCP services (database and SSH services need one), its values can't use variables, it can't use OAuth or member-provided values, and an MCP server can't be limited to some of its tools. To limit an MCP server's tools, add it to an access bundle instead. + services: Services the session carries itself, instead of or beside its access bundle's: up to 20 dicts with the API's field names, such as {"type": "http", "hostPattern": "api.github.com", "credential": {"type": "bearer", "value": token}}. Only Agent Vault admins can send them. Each has the same fields as a service in an access bundle, except that its name is optional for HTTP and MCP services (database and SSH services need one), its values can't use variables, and it can't use OAuth or member-provided values. To limit an MCP server to some of its tools, send their names in allowedTools, which needs an Infisical version that accepts a tool list on a session's services. project_id: The ID of the Agent Vault project to create the session in. Returns: diff --git a/tests/test_agent_vault.py b/tests/test_agent_vault.py index 30dfd64..9d6450b 100644 --- a/tests/test_agent_vault.py +++ b/tests/test_agent_vault.py @@ -483,6 +483,26 @@ def test_sessions_read_an_inline_database_service(api, agent_vault, json_respons assert service.description == "Orders replica" +def test_sessions_send_and_read_an_inline_mcp_servers_tool_list(api, agent_vault, json_response): + mcp_input = { + "type": "mcp", "name": "deepwiki", "serverUrl": "https://mcp.deepwiki.com/mcp", "transport": "streamable-http", + "credential": {"type": "bearer", "value": "mcp-token"}, "allowedTools": ["read_wiki_structure"], + } + mcp = { + "id": INLINE_SERVICE["id"], "name": "deepwiki", "description": None, "type": "mcp", + "serverUrl": "https://mcp.deepwiki.com/mcp", "transport": "streamable-http", "hostPattern": "mcp.deepwiki.com", + "allowedTools": ["read_wiki_structure"], + "credential": {"type": "bearer", "headerName": "Authorization", "headerPrefix": "Bearer"}, "customHeaders": [], + } + api.session.post.return_value = json_response({"session": dict(SESSION, token="token", services=[mcp])}) + created = agent_vault.sessions.create(services=[mcp_input], project_id=PROJECT_ID) + assert api.session.post.call_args.kwargs["json"] == {"services": [mcp_input], "projectId": PROJECT_ID} + assert created.services[0].allowedTools == ["read_wiki_structure"] + + api.session.get.return_value = json_response({"session": dict(SESSION, services=[dict(mcp, allowedTools=None)])}) + assert agent_vault.sessions.get(SESSION["id"]).services[0].allowedTools is None + + def test_access_bundles_list_grantees_reads_a_pending_organization_membership(api, agent_vault, json_response): grantee = dict({key: ON_BEHALF_OF[key] for key in ("type", "id", "username", "email", "firstName", "lastName")}, isOrgMembershipPending=True, grantedAt="2026-10-27T00:00:00.000Z")