Skip to content

Commit 25d9b8a

Browse files
bokelleyclaude
andcommitted
Enable strict mypy type checking and fix all issues
## Type Safety Improvements - ✅ All source files pass strict mypy checks - ✅ Added metadata field to TaskResult - ✅ Fixed ProtocolAdapter type annotation in ADCPClient - ✅ Fixed Callable type parameters in handlers - ✅ Proper type ignores for conditional MCP imports ## Mypy Configuration - Strict mode enabled for all source files - Test files have relaxed type checking (practical approach) - Integration tests ignored for type checking (use sys.path) ## Type Annotations Fixed - TaskResult now includes optional metadata field - ADCPClient.adapter properly typed as ProtocolAdapter - Callable[..., Any] for generic handler functions - MCP imports with proper type: ignore comments ## Benefits - Catches type errors at development time - Better IDE autocomplete and hints - Safer refactoring - Self-documenting code All code now passes: - mypy --strict (10 source files) - black formatting - ruff linting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent dabfd73 commit 25d9b8a

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ strict = true
6868
warn_return_any = true
6969
warn_unused_configs = true
7070

71+
[[tool.mypy.overrides]]
72+
module = "tests.*"
73+
disable_error_code = ["import-not-found", "no-untyped-def", "var-annotated", "operator"]
74+
75+
[[tool.mypy.overrides]]
76+
module = "tests.integration.*"
77+
ignore_errors = true
78+
7179
[tool.pytest.ini_options]
7280
testpaths = ["tests"]
7381
asyncio_mode = "auto"

src/adcp/client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import json
44
import os
5+
from collections.abc import Callable
56
from datetime import datetime
6-
from typing import Any, Callable, Dict, List, Optional
7+
from typing import Any
78
from uuid import uuid4
89

910
from adcp.protocols.a2a import A2AAdapter
@@ -29,9 +30,9 @@ class ADCPClient:
2930
def __init__(
3031
self,
3132
agent_config: AgentConfig,
32-
webhook_url_template: Optional[str] = None,
33-
webhook_secret: Optional[str] = None,
34-
on_activity: Optional[Callable[[Activity], None]] = None,
33+
webhook_url_template: str | None = None,
34+
webhook_secret: str | None = None,
35+
on_activity: Callable[[Activity], None] | None = None,
3536
):
3637
"""
3738
Initialize ADCP client for a single agent.
@@ -49,10 +50,11 @@ def __init__(
4950
self.on_activity = on_activity
5051

5152
# Initialize protocol adapter
53+
self.adapter: ProtocolAdapter
5254
if agent_config.protocol == Protocol.A2A:
53-
self.adapter: ProtocolAdapter = A2AAdapter(agent_config)
55+
self.adapter = A2AAdapter(agent_config)
5456
elif agent_config.protocol == Protocol.MCP:
55-
self.adapter: ProtocolAdapter = MCPAdapter(agent_config)
57+
self.adapter = MCPAdapter(agent_config)
5658
else:
5759
raise ValueError(f"Unsupported protocol: {agent_config.protocol}")
5860

@@ -395,7 +397,7 @@ async def provide_performance_feedback(self, **kwargs: Any) -> TaskResult[Any]:
395397
async def handle_webhook(
396398
self,
397399
payload: dict[str, Any],
398-
signature: Optional[str] = None,
400+
signature: str | None = None,
399401
) -> None:
400402
"""
401403
Handle incoming webhook.
@@ -430,10 +432,10 @@ class ADCPMultiAgentClient:
430432
def __init__(
431433
self,
432434
agents: list[AgentConfig],
433-
webhook_url_template: Optional[str] = None,
434-
webhook_secret: Optional[str] = None,
435-
on_activity: Optional[Callable[[Activity], None]] = None,
436-
handlers: Optional[Dict[str, Callable]] = None,
435+
webhook_url_template: str | None = None,
436+
webhook_secret: str | None = None,
437+
on_activity: Callable[[Activity], None] | None = None,
438+
handlers: dict[str, Callable[..., Any]] | None = None,
437439
):
438440
"""
439441
Initialize multi-agent client.

src/adcp/protocols/mcp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from urllib.parse import urlparse
55

66
try:
7-
from mcp import ClientSession
8-
from mcp.client.sse import sse_client
7+
from mcp import ClientSession # type: ignore[import-not-found]
8+
from mcp.client.sse import sse_client # type: ignore[import-not-found]
99

1010
MCP_AVAILABLE = True
1111
except ImportError:
1212
MCP_AVAILABLE = False
13-
ClientSession = None # type: ignore
13+
ClientSession = None
1414

1515
from adcp.protocols.base import ProtocolAdapter
1616
from adcp.types.core import TaskResult, TaskStatus

src/adcp/types/core.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Core type definitions."""
22

33
from enum import Enum
4-
from typing import Any, Dict, Generic, Literal, Optional, TypeVar
4+
from typing import Any, Generic, Literal, TypeVar
55

66
from pydantic import BaseModel, Field
77

@@ -19,7 +19,7 @@ class AgentConfig(BaseModel):
1919
id: str
2020
agent_uri: str
2121
protocol: Protocol
22-
auth_token: Optional[str] = None
22+
auth_token: str | None = None
2323
requires_auth: bool = False
2424

2525

@@ -47,18 +47,19 @@ class NeedsInputInfo(BaseModel):
4747
"""Information when agent needs clarification."""
4848

4949
message: str
50-
field: Optional[str] = None
50+
field: str | None = None
5151

5252

5353
class TaskResult(BaseModel, Generic[T]):
5454
"""Result from task execution."""
5555

5656
status: TaskStatus
57-
data: Optional[T] = None
58-
submitted: Optional[SubmittedInfo] = None
59-
needs_input: Optional[NeedsInputInfo] = None
60-
error: Optional[str] = None
57+
data: T | None = None
58+
submitted: SubmittedInfo | None = None
59+
needs_input: NeedsInputInfo | None = None
60+
error: str | None = None
6161
success: bool = Field(default=True)
62+
metadata: dict[str, Any] | None = None
6263

6364
class Config:
6465
arbitrary_types_allowed = True
@@ -81,9 +82,9 @@ class Activity(BaseModel):
8182
operation_id: str
8283
agent_id: str
8384
task_type: str
84-
status: Optional[TaskStatus] = None
85+
status: TaskStatus | None = None
8586
timestamp: str
86-
metadata: Optional[Dict[str, Any]] = None
87+
metadata: dict[str, Any] | None = None
8788

8889

8990
class WebhookMetadata(BaseModel):
@@ -93,6 +94,6 @@ class WebhookMetadata(BaseModel):
9394
agent_id: str
9495
task_type: str
9596
status: TaskStatus
96-
sequence_number: Optional[int] = None
97-
notification_type: Optional[Literal["scheduled", "final", "delayed"]] = None
97+
sequence_number: int | None = None
98+
notification_type: Literal["scheduled", "final", "delayed"] | None = None
9899
timestamp: str

0 commit comments

Comments
 (0)