diff --git a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py index 30bca722..a06e593b 100644 --- a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py +++ b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py @@ -122,8 +122,10 @@ async def list_tools(self) -> list[Any]: for item in tools_response: if isinstance(item, tuple) and item[0] == "tools": - for tool in item[1]: - tools.append(Tool(tool.name, tool.description, tool.inputSchema)) + tools.extend( + Tool(tool.name, tool.description, tool.inputSchema) + for tool in item[1] + ) return tools @@ -282,10 +284,9 @@ def __init__(self, servers: list[Server], llm_client: LLMClient) -> None: async def cleanup_servers(self) -> None: """Clean up all servers properly.""" - cleanup_tasks = [] - for server in self.servers: - cleanup_tasks.append(asyncio.create_task(server.cleanup())) - + cleanup_tasks = [ + asyncio.create_task(server.cleanup()) for server in self.servers + ] if cleanup_tasks: try: await asyncio.gather(*cleanup_tasks, return_exceptions=True) diff --git a/pyproject.toml b/pyproject.toml index 25514cd6..a8c24249 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,8 +89,8 @@ venv = ".venv" strict = ["src/mcp/**/*.py"] [tool.ruff.lint] -select = ["E", "F", "I", "UP"] -ignore = [] +select = ["C4", "E", "F", "I", "PERF", "UP"] +ignore = ["PERF203"] [tool.ruff] line-length = 88 diff --git a/src/mcp/server/fastmcp/utilities/func_metadata.py b/src/mcp/server/fastmcp/utilities/func_metadata.py index 45332eca..37439132 100644 --- a/src/mcp/server/fastmcp/utilities/func_metadata.py +++ b/src/mcp/server/fastmcp/utilities/func_metadata.py @@ -80,7 +80,7 @@ def pre_parse_json(self, data: dict[str, Any]) -> dict[str, Any]: dicts (JSON objects) as JSON strings, which can be pre-parsed here. """ new_data = data.copy() # Shallow copy - for field_name, _field_info in self.arg_model.model_fields.items(): + for field_name in self.arg_model.model_fields.keys(): if field_name not in data.keys(): continue if isinstance(data[field_name], str): diff --git a/tests/issues/test_342_base64_encoding.py b/tests/issues/test_342_base64_encoding.py index f92b037d..cff8ec54 100644 --- a/tests/issues/test_342_base64_encoding.py +++ b/tests/issues/test_342_base64_encoding.py @@ -42,7 +42,7 @@ async def test_server_base64_encoding_issue(): # Create binary data that will definitely result in + and / characters # when encoded with standard base64 - binary_data = bytes([x for x in range(255)] * 4) + binary_data = bytes(list(range(255)) * 4) # Register a resource handler that returns our test data @server.read_resource() diff --git a/tests/server/fastmcp/prompts/test_base.py b/tests/server/fastmcp/prompts/test_base.py index bb47d6d3..c4af044a 100644 --- a/tests/server/fastmcp/prompts/test_base.py +++ b/tests/server/fastmcp/prompts/test_base.py @@ -38,7 +38,7 @@ async def fn(name: str, age: int = 30) -> str: return f"Hello, {name}! You're {age} years old." prompt = Prompt.from_function(fn) - assert await prompt.render(arguments=dict(name="World")) == [ + assert await prompt.render(arguments={"name": "World"}) == [ UserMessage( content=TextContent( type="text", text="Hello, World! You're 30 years old." @@ -53,7 +53,7 @@ async def fn(name: str, age: int = 30) -> str: prompt = Prompt.from_function(fn) with pytest.raises(ValueError): - await prompt.render(arguments=dict(age=40)) + await prompt.render(arguments={"age": 40}) @pytest.mark.anyio async def test_fn_returns_message(self): diff --git a/tests/server/fastmcp/servers/test_file_server.py b/tests/server/fastmcp/servers/test_file_server.py index c51ecb25..c1f51cab 100644 --- a/tests/server/fastmcp/servers/test_file_server.py +++ b/tests/server/fastmcp/servers/test_file_server.py @@ -115,7 +115,7 @@ async def test_read_resource_file(mcp: FastMCP): @pytest.mark.anyio async def test_delete_file(mcp: FastMCP, test_dir: Path): await mcp.call_tool( - "delete_file", arguments=dict(path=str(test_dir / "example.py")) + "delete_file", arguments={"path": str(test_dir / "example.py")} ) assert not (test_dir / "example.py").exists() @@ -123,7 +123,7 @@ async def test_delete_file(mcp: FastMCP, test_dir: Path): @pytest.mark.anyio async def test_delete_file_and_check_resources(mcp: FastMCP, test_dir: Path): await mcp.call_tool( - "delete_file", arguments=dict(path=str(test_dir / "example.py")) + "delete_file", arguments={"path": str(test_dir / "example.py")} ) res_iter = await mcp.read_resource("file://test_dir/example.py") res_list = list(res_iter)