mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-22 16:24:24 +01:00
Add strict mode to pyright (#315)
* Add strict mode to pyright * Apply UP rule * fix readme * More correct * Leave wrong Context for now * Add strict mode to pyright * Apply UP rule * fix readme * fix * ignore
This commit is contained in:
committed by
GitHub
parent
5a54d82459
commit
ae77772ea8
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -8,7 +9,7 @@ from mcp.cli.claude import update_claude_config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_config_dir(tmp_path):
|
||||
def temp_config_dir(tmp_path: Path):
|
||||
"""Create a temporary Claude config directory."""
|
||||
config_dir = tmp_path / "Claude"
|
||||
config_dir.mkdir()
|
||||
@@ -16,23 +17,20 @@ def temp_config_dir(tmp_path):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_path(temp_config_dir):
|
||||
def mock_config_path(temp_config_dir: Path):
|
||||
"""Mock get_claude_config_path to return our temporary directory."""
|
||||
with patch("mcp.cli.claude.get_claude_config_path", return_value=temp_config_dir):
|
||||
yield temp_config_dir
|
||||
|
||||
|
||||
def test_command_execution(mock_config_path):
|
||||
def test_command_execution(mock_config_path: Path):
|
||||
"""Test that the generated command can actually be executed."""
|
||||
# Setup
|
||||
server_name = "test_server"
|
||||
file_spec = "test_server.py:app"
|
||||
|
||||
# Update config
|
||||
success = update_claude_config(
|
||||
file_spec=file_spec,
|
||||
server_name=server_name,
|
||||
)
|
||||
success = update_claude_config(file_spec=file_spec, server_name=server_name)
|
||||
assert success
|
||||
|
||||
# Read the generated config
|
||||
|
||||
@@ -7,11 +7,7 @@ from mcp.shared.context import RequestContext
|
||||
from mcp.shared.memory import (
|
||||
create_connected_server_and_client_session as create_session,
|
||||
)
|
||||
from mcp.types import (
|
||||
ListRootsResult,
|
||||
Root,
|
||||
TextContent,
|
||||
)
|
||||
from mcp.types import ListRootsResult, Root, TextContent
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@@ -39,7 +35,7 @@ async def test_list_roots_callback():
|
||||
return callback_return
|
||||
|
||||
@server.tool("test_list_roots")
|
||||
async def test_list_roots(context: Context, message: str):
|
||||
async def test_list_roots(context: Context, message: str): # type: ignore[reportUnknownMemberType]
|
||||
roots = await context.session.list_roots()
|
||||
assert roots == callback_return
|
||||
return True
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import List, Literal
|
||||
from typing import Literal
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
@@ -14,7 +14,7 @@ from mcp.types import (
|
||||
|
||||
class LoggingCollector:
|
||||
def __init__(self):
|
||||
self.log_messages: List[LoggingMessageNotificationParams] = []
|
||||
self.log_messages: list[LoggingMessageNotificationParams] = []
|
||||
|
||||
async def __call__(self, params: LoggingMessageNotificationParams) -> None:
|
||||
self.log_messages.append(params)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Test to reproduce issue #88: Random error thrown on response."""
|
||||
|
||||
from collections.abc import Sequence
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import base64
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from pydantic import AnyUrl
|
||||
@@ -114,7 +114,7 @@ def image_tool_fn(path: str) -> Image:
|
||||
return Image(path)
|
||||
|
||||
|
||||
def mixed_content_tool_fn() -> list[Union[TextContent, ImageContent]]:
|
||||
def mixed_content_tool_fn() -> list[TextContent | ImageContent]:
|
||||
return [
|
||||
TextContent(type="text", text="Hello"),
|
||||
ImageContent(type="image", data="abc", mimeType="image/png"),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
@@ -296,7 +295,7 @@ class TestContextHandling:
|
||||
"""Test that context is optional when calling tools."""
|
||||
from mcp.server.fastmcp import Context
|
||||
|
||||
def tool_with_context(x: int, ctx: Optional[Context] = None) -> str:
|
||||
def tool_with_context(x: int, ctx: Context | None = None) -> str:
|
||||
return str(x)
|
||||
|
||||
manager = ToolManager()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for lifespan functionality in both low-level and FastMCP servers."""
|
||||
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import AsyncIterator
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import AsyncGenerator
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import multiprocessing
|
||||
import socket
|
||||
import time
|
||||
from typing import AsyncGenerator, Generator
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
|
||||
import anyio
|
||||
import httpx
|
||||
@@ -139,7 +139,7 @@ def server(server_port: int) -> Generator[None, None, None]:
|
||||
attempt += 1
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"Server failed to start after {} attempts".format(max_attempts)
|
||||
f"Server failed to start after {max_attempts} attempts"
|
||||
)
|
||||
|
||||
yield
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import multiprocessing
|
||||
import socket
|
||||
import time
|
||||
from typing import AsyncGenerator, Generator
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
|
||||
import anyio
|
||||
import pytest
|
||||
@@ -135,7 +135,7 @@ def server(server_port: int) -> Generator[None, None, None]:
|
||||
attempt += 1
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"Server failed to start after {} attempts".format(max_attempts)
|
||||
f"Server failed to start after {max_attempts} attempts"
|
||||
)
|
||||
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user