Skip to content

Commit d43a042

Browse files
authored
Merge pull request #2 from codeforanchorage/boston/security-hardening-and-aws-docs
Log-group tagging, CKAN civic-AI caveats, and JSON-RPC error-code fix
2 parents e9479ca + 6fd1ccf commit d43a042

6 files changed

Lines changed: 3511 additions & 443 deletions

File tree

core/mcp_server.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
logger = logging.getLogger(__name__)
1818

1919

20+
class MethodNotFoundError(Exception):
21+
"""Raised when a JSON-RPC request names a method the server does not implement.
22+
23+
Mapped to JSON-RPC error code -32601 ("Method not found") rather than the
24+
generic -32603 ("Internal error"), so well-behaved clients can tell an
25+
unknown method apart from a genuine server-side failure.
26+
"""
27+
28+
2029
class MCPServer:
2130
"""MCP Server that handles JSON-RPC requests and routes to Plugin Manager."""
2231

@@ -86,7 +95,7 @@ async def handle_request(self, request: Dict[str, Any]) -> Optional[Dict[str, An
8695
},
8796
)
8897
return None
89-
raise ValueError(f"Unknown method: {method}")
98+
raise MethodNotFoundError(f"Unknown method: {method}")
9099

91100
# Don't send response for notifications
92101
if is_notification:
@@ -122,14 +131,24 @@ async def handle_request(self, request: Dict[str, Any]) -> Optional[Dict[str, An
122131

123132
except Exception as e:
124133
duration_ms = (time.perf_counter() - start_time) * 1000
125-
error_response = {
126-
"jsonrpc": "2.0",
127-
"id": request_id,
128-
"error": {
134+
# Unknown methods are a client error (-32601 Method not found), not a
135+
# server fault (-32603 Internal error). Everything else is -32603.
136+
if isinstance(e, MethodNotFoundError):
137+
error = {
138+
"code": -32601,
139+
"message": "Method not found",
140+
"data": str(e),
141+
}
142+
else:
143+
error = {
129144
"code": -32603,
130145
"message": "Internal error",
131146
"data": str(e),
132-
},
147+
}
148+
error_response = {
149+
"jsonrpc": "2.0",
150+
"id": request_id,
151+
"error": error,
133152
}
134153

135154
# Log JSON-RPC error response

0 commit comments

Comments
 (0)