Skip to content

Commit 242a8e1

Browse files
less dataclasses
1 parent 2bd82c5 commit 242a8e1

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

src/mcp_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from .core import MCPServer
66

77
__all__ = ["MCPServer"]
8-
__version__ = "0.1.0"
8+
__version__ = "2.0.0"

src/mcp_utils/core.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77
import uuid
88
from collections.abc import Callable
9-
from dataclasses import dataclass, field
109
from typing import Any, TypeVar
1110

1211
import msgspec
@@ -37,45 +36,43 @@
3736
PAGE_SIZE = 50
3837

3938

40-
@dataclass
4139
class MCPServer:
4240
"""Base MCP Server implementation"""
4341

44-
name: str
45-
version: str
46-
47-
# The response queue is used to store responses
48-
# that are sent to the client via SSE.
49-
response_queue: ResponseQueueProtocol
50-
51-
# When the client send an `initialize` request, it
52-
# sends the highest version it can support. The server
53-
# is expected to respond with the latest version supported
54-
# by the server.
55-
# The client is responsible to disconnect if the version is
56-
# not supported.
57-
# https://spec.modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle/#version-negotiation
58-
protocol_version: str = "2025-06-18"
59-
60-
# server capabilities can be:
61-
# - prompts
62-
# - resources
63-
# - tools
64-
# - logging
65-
# - experimental
66-
_prompts: dict[str, Callable] = field(default_factory=dict)
67-
_prompts_list: dict[str, PromptInfo] = field(default_factory=dict)
68-
_prompt_completions: dict[str, dict[str, Callable]] = field(default_factory=dict)
69-
70-
_resources: dict[str, Callable] = field(default_factory=dict)
71-
_resources_list: dict[str, ResourceInfo] = field(default_factory=dict)
72-
73-
_resource_templates: dict[str, Callable] = field(default_factory=dict)
74-
_resource_template_list: dict[str, ResourceInfo] = field(default_factory=dict)
75-
76-
_tools: dict[str, Callable] = field(default_factory=dict)
77-
_tools_list: dict[str, ToolInfo] = field(default_factory=dict)
78-
_tool_arg_models: dict[str, type] = field(default_factory=dict)
42+
def __init__(
43+
self,
44+
name: str,
45+
version: str,
46+
response_queue: ResponseQueueProtocol,
47+
instructions: str = "",
48+
protocol_version: str = "2025-06-18",
49+
) -> None:
50+
# Basic info
51+
self.name: str = name
52+
self.version: str = version
53+
self.instructions: str = instructions
54+
55+
# The response queue is used to store responses
56+
# that are sent to the client via SSE.
57+
self.response_queue: ResponseQueueProtocol = response_queue
58+
59+
# Protocol version negotiation (see MCP spec)
60+
self.protocol_version: str = protocol_version
61+
62+
# Server capabilities registries
63+
self._prompts: dict[str, Callable] = {}
64+
self._prompts_list: dict[str, PromptInfo] = {}
65+
self._prompt_completions: dict[str, dict[str, Callable]] = {}
66+
67+
self._resources: dict[str, Callable] = {}
68+
self._resources_list: dict[str, ResourceInfo] = {}
69+
70+
self._resource_templates: dict[str, Callable] = {}
71+
self._resource_template_list: dict[str, ResourceInfo] = {}
72+
73+
self._tools: dict[str, Callable] = {}
74+
self._tools_list: dict[str, ToolInfo] = {}
75+
self._tool_arg_models: dict[str, type] = {}
7976

8077
def register_tool(self, name: str, callable: Callable, tool_info: ToolInfo) -> None:
8178
self._tools_list[name] = tool_info
@@ -248,6 +245,7 @@ def get_capabilities(self) -> InitializeResult:
248245
resources={"subscribe": False, "listChanged": False},
249246
tools={"listChanged": False},
250247
),
248+
instructions=self.instructions,
251249
protocolVersion=self.protocol_version,
252250
serverInfo=ServerInfo(name=self.name, version=self.version),
253251
)

src/mcp_utils/schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""msgspec models for MCP (Model Context Protocol) schema."""
22

3-
import logging
43
from collections.abc import Callable
54
from enum import Enum
65
from typing import Any, Literal
@@ -9,8 +8,6 @@
98

109
from .utils import inspect_callable
1110

12-
logger = logging.getLogger("mcp_utils")
13-
1411

1512
def build_json_schema_for_msgspec_struct(struct_type: type[Any]) -> dict[str, Any]:
1613
"""Return a clean JSON Schema dict for a msgspec Struct.
@@ -188,6 +185,7 @@ class InitializeResult(msgspec.Struct):
188185
protocolVersion: str
189186
capabilities: ClientCapabilities
190187
serverInfo: ServerInfo
188+
instructions: str | msgspec.UnsetType = msgspec.UNSET
191189

192190

193191
class ListResourcesRequest(msgspec.Struct):

src/mcp_utils/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""Utility functions for MCP server implementation."""
22

33
from collections.abc import Callable
4-
from dataclasses import dataclass
54
from inspect import Parameter, signature
65
from typing import Any, get_type_hints
76

87
import msgspec
98

109

11-
@dataclass
12-
class CallableMetadata:
10+
class CallableMetadata(msgspec.Struct):
1311
"""Metadata about a callable's signature."""
1412

1513
arg_model: type[Any] # Msgspec Struct for arguments

0 commit comments

Comments
 (0)