diff --git a/src/iotdb_mcp_server/services/query.py b/src/iotdb_mcp_server/services/query.py index 096a36b..ea57d77 100644 --- a/src/iotdb_mcp_server/services/query.py +++ b/src/iotdb_mcp_server/services/query.py @@ -234,7 +234,7 @@ async def select_query( async def export_query( query_sql: str, format: str = "csv", - filename: str = None, + filename: str | None = None, target_id: str | None = None, target: dict[str, object] | None = None, ) -> list[TextContent]: @@ -364,7 +364,7 @@ async def read_query( async def export_table_query( query_sql: str, format: str = "csv", - filename: str = None, + filename: str | None = None, target_id: str | None = None, target: dict[str, object] | None = None, ) -> list[TextContent]: diff --git a/tests/test_tool_schemas.py b/tests/test_tool_schemas.py new file mode 100644 index 0000000..1b1a1ab --- /dev/null +++ b/tests/test_tool_schemas.py @@ -0,0 +1,55 @@ +from __future__ import annotations + +import asyncio +import logging +import sys +import tempfile +import unittest +from pathlib import Path + +from fastmcp import FastMCP + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "src")) + +from iotdb_mcp_server.config import Config # noqa: E402 +from iotdb_mcp_server.services.query import register_query_tools # noqa: E402 + + +class ToolSchemaTest(unittest.TestCase): + def test_none_defaults_accept_null(self) -> None: + """A parameter that defaults to None must allow null in its schema. + + Otherwise the schema advertises "default": null on a non-null type, + and a client that sends that value explicitly is rejected before the + tool runs. + """ + with tempfile.TemporaryDirectory() as directory: + config = Config( + host="127.0.0.1", + port=6667, + user="root", + password="", + database="test", + sql_dialect="table", + timezone="+00:00", + export_path=directory, + ) + mcp = FastMCP("test") + register_query_tools(mcp, config, logging.getLogger(__name__)) + tools = asyncio.run(mcp.list_tools()) + + bad = [] + for tool in tools: + for name, prop in tool.parameters.get("properties", {}).items(): + if "default" in prop and prop["default"] is None: + types = [prop.get("type")] + [ + branch.get("type") for branch in prop.get("anyOf", []) + ] + if "null" not in types: + bad.append(f"{tool.name}.{name}") + self.assertEqual(bad, []) + + +if __name__ == "__main__": + unittest.main()