From b577ca6305c004fde05d0dc4d1d69de9f74b6053 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 12:24:44 +0000 Subject: [PATCH 1/2] test(models): pin the MCP server's input rule keywords through every adapter The MCP server now advertises each connector input's validation rules as JSON Schema keywords (minLength/maxLength, format, pattern, minimum/maximum, also on array items). The adapters already hand the served schema over verbatim; this builds a tool the way fetch_tools() does and pins that to_openai_function, to_langchain and to_pydantic_ai_tool each keep those keywords. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- tests/test_models.py | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index db28134..5f4b631 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,4 @@ -from collections.abc import Sequence +from collections.abc import Callable, Sequence from typing import Any import pytest @@ -7,7 +7,8 @@ from langchain_core.tools import BaseTool as LangChainBaseTool from pydantic import ValidationError -from stackone_ai.tools import StackOneMcpTool, StackOneTool, Tools +from stackone_ai.tools import McpToolDefinition, StackOneMcpTool, StackOneTool, Tools +from stackone_ai.toolset import StackOneToolSet from stackone_ai.types import ( ExecuteConfig, StackOneAPIError, @@ -736,6 +737,55 @@ def test_preserves_field_named_nullable(self): assert props["nullable"]["type"] == "object" +# The keywords the MCP server advertises from a connector's input `rules`, as `tools/list` serves them. +RULE_KEYWORD_PROPERTIES: dict[str, Any] = { + "name": {"type": "string", "minLength": 2, "maxLength": 50}, + "email": {"type": "string", "format": "email"}, + "id": {"type": "string", "format": "uuid"}, + "start_date": {"type": "string", "format": "date"}, + "updated_after": {"type": "string", "format": "date-time"}, + "language": {"type": "string", "pattern": "^[a-z]{2}$"}, + "website": {"type": "string", "pattern": r"^https?:\/\/[^\s/?#]+(?:[/?#]\S*)?$"}, + "callback": {"type": "string", "pattern": r"^[a-zA-Z][a-zA-Z0-9+.-]*:\S+$"}, + "expires_in": {"type": "number", "minimum": 86400, "maximum": 31536000}, + "tags": {"type": "array", "items": {"type": "string", "minLength": 1, "maxLength": 10}}, +} + + +def _rule_keywords_tool() -> StackOneTool: + """A tool built the way fetch_tools() builds one from a served inputSchema.""" + toolset = StackOneToolSet(api_key="test-key", account_id="acc-1") + input_schema = { + "type": "object", + "properties": RULE_KEYWORD_PROPERTIES, + "required": ["name", "expires_in"], + } + return toolset._create_tool( + McpToolDefinition("netbird_create_setup_key", "", input_schema), + "acc-1", + "https://api.stackone.com/mcp", + ) + + +class TestServedRuleKeywords: + """Every framework adapter hands the model the input rules the server advertises.""" + + @pytest.mark.parametrize( + "schema_of", + [ + pytest.param( + lambda tool: tool.to_openai_function()["function"]["parameters"], id="to_openai_function" + ), + pytest.param(lambda tool: tool.to_langchain().args_schema, id="to_langchain"), + pytest.param( + lambda tool: tool.to_pydantic_ai_tool().function_schema.json_schema, id="to_pydantic_ai_tool" + ), + ], + ) + def test_adapter_keeps_every_rule_keyword(self, schema_of: Callable[[StackOneTool], Any]) -> None: + assert schema_of(_rule_keywords_tool())["properties"] == RULE_KEYWORD_PROPERTIES + + class TestExecuteOpenAIToolCalls: """Tools.execute_openai_tool_calls: model tool calls in, `tool` messages out.""" From 68bec74205c7720b2b68e75c4d8490a7e2dd34f7 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Thu, 19 Nov 2026 12:27:19 +0000 Subject: [PATCH 2/2] test(models): compare the whole served schema, on a copy, via tool_def Review of the first commit: - compare the adapters' whole parameters object, so required and type are pinned too; - build the tool from a deep copy, so an adapter that edited the served schema in place could not also edit the expectation and pass; - read pydantic-ai's public tool_def.parameters_json_schema, what it sends the model. Co-Authored-By: Claude Opus 5.5 --- tests/test_models.py | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 5f4b631..5781b97 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,3 +1,4 @@ +import copy from collections.abc import Callable, Sequence from typing import Any @@ -738,37 +739,34 @@ def test_preserves_field_named_nullable(self): # The keywords the MCP server advertises from a connector's input `rules`, as `tools/list` serves them. -RULE_KEYWORD_PROPERTIES: dict[str, Any] = { - "name": {"type": "string", "minLength": 2, "maxLength": 50}, - "email": {"type": "string", "format": "email"}, - "id": {"type": "string", "format": "uuid"}, - "start_date": {"type": "string", "format": "date"}, - "updated_after": {"type": "string", "format": "date-time"}, - "language": {"type": "string", "pattern": "^[a-z]{2}$"}, - "website": {"type": "string", "pattern": r"^https?:\/\/[^\s/?#]+(?:[/?#]\S*)?$"}, - "callback": {"type": "string", "pattern": r"^[a-zA-Z][a-zA-Z0-9+.-]*:\S+$"}, - "expires_in": {"type": "number", "minimum": 86400, "maximum": 31536000}, - "tags": {"type": "array", "items": {"type": "string", "minLength": 1, "maxLength": 10}}, +RULE_KEYWORDS_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "name": {"type": "string", "minLength": 2, "maxLength": 50}, + "email": {"type": "string", "format": "email"}, + "id": {"type": "string", "format": "uuid"}, + "start_date": {"type": "string", "format": "date"}, + "updated_after": {"type": "string", "format": "date-time"}, + "language": {"type": "string", "pattern": "^[a-z]{2}$"}, + "website": {"type": "string", "pattern": r"^https?:\/\/[^\s/?#]+(?:[/?#]\S*)?$"}, + "callback": {"type": "string", "pattern": r"^[a-zA-Z][a-zA-Z0-9+.-]*:\S+$"}, + "expires_in": {"type": "number", "minimum": 86400, "maximum": 31536000}, + "tags": {"type": "array", "items": {"type": "string", "minLength": 1, "maxLength": 10}}, + }, + "required": ["name", "expires_in"], } def _rule_keywords_tool() -> StackOneTool: """A tool built the way fetch_tools() builds one from a served inputSchema.""" toolset = StackOneToolSet(api_key="test-key", account_id="acc-1") - input_schema = { - "type": "object", - "properties": RULE_KEYWORD_PROPERTIES, - "required": ["name", "expires_in"], - } - return toolset._create_tool( - McpToolDefinition("netbird_create_setup_key", "", input_schema), - "acc-1", - "https://api.stackone.com/mcp", - ) + # A copy, so an adapter that edited the served schema in place could not also edit the expectation + served = McpToolDefinition("netbird_create_setup_key", "", copy.deepcopy(RULE_KEYWORDS_SCHEMA)) + return toolset._create_tool(served, "acc-1", "https://api.stackone.com/mcp") class TestServedRuleKeywords: - """Every framework adapter hands the model the input rules the server advertises.""" + """Every framework adapter hands over the input rules the server advertises, unchanged.""" @pytest.mark.parametrize( "schema_of", @@ -778,12 +776,13 @@ class TestServedRuleKeywords: ), pytest.param(lambda tool: tool.to_langchain().args_schema, id="to_langchain"), pytest.param( - lambda tool: tool.to_pydantic_ai_tool().function_schema.json_schema, id="to_pydantic_ai_tool" + lambda tool: tool.to_pydantic_ai_tool().tool_def.parameters_json_schema, + id="to_pydantic_ai_tool", ), ], ) - def test_adapter_keeps_every_rule_keyword(self, schema_of: Callable[[StackOneTool], Any]) -> None: - assert schema_of(_rule_keywords_tool())["properties"] == RULE_KEYWORD_PROPERTIES + def test_adapter_hands_over_the_served_schema(self, schema_of: Callable[[StackOneTool], Any]) -> None: + assert schema_of(_rule_keywords_tool()) == RULE_KEYWORDS_SCHEMA class TestExecuteOpenAIToolCalls: