diff --git a/tests/test_models.py b/tests/test_models.py index db28134..5781b97 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,5 @@ -from collections.abc import Sequence +import copy +from collections.abc import Callable, Sequence from typing import Any import pytest @@ -7,7 +8,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 +738,53 @@ 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_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") + # 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 over the input rules the server advertises, unchanged.""" + + @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().tool_def.parameters_json_schema, + id="to_pydantic_ai_tool", + ), + ], + ) + 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: """Tools.execute_openai_tool_calls: model tool calls in, `tool` messages out."""