mcp修复
This commit is contained in:
1 parent
801c0af692
commit
3080b17d02
9 files changed
+378
-73
No files matched your search
+11
-18
@@ -23,7 +23,7 @@ import (
|
||||
const (
|
||||
mcpProtocolVersion = "2025-06-18"
|
||||
mcpServerName = "fire-safety-ymd-spatial-readonly"
|
||||
mcpServerVersion = "0.2.0"
|
||||
mcpServerVersion = "0.2.2"
|
||||
maximumMCPBody = int64(1024 * 1024)
|
||||
maximumToolTimeout = 30 * time.Second
|
||||
|
||||
@@ -118,12 +118,6 @@ func (h *MCPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.logResult(requestID, "transport", "unsupported_media_type", started)
|
||||
return
|
||||
}
|
||||
if version := strings.TrimSpace(r.Header.Get("MCP-Protocol-Version")); version != "" && version != mcpProtocolVersion {
|
||||
h.writeRPCError(w, http.StatusBadRequest, nil, -32602, "MCP_PROTOCOL_VERSION_UNSUPPORTED", "Unsupported MCP protocol version.")
|
||||
h.logResult(requestID, "transport", "unsupported_protocol", started)
|
||||
return
|
||||
}
|
||||
|
||||
body, tooLarge, err := readBoundedBody(r.Body, h.maxBodyBytes)
|
||||
if err != nil {
|
||||
h.writeRPCError(w, http.StatusBadRequest, nil, -32700, "MCP_REQUEST_INVALID", "Unable to read MCP request.")
|
||||
@@ -150,11 +144,7 @@ func (h *MCPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch request.Method {
|
||||
case "initialize":
|
||||
if h.handleInitialize(w, request) {
|
||||
h.logResult(requestID, "initialize", "success", started)
|
||||
} else {
|
||||
h.logResult(requestID, "initialize", "unsupported_protocol", started)
|
||||
}
|
||||
h.logResult(requestID, "initialize", h.handleInitialize(w, request), started)
|
||||
case "notifications/initialized":
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
h.logResult(requestID, "notifications/initialized", "accepted", started)
|
||||
@@ -169,13 +159,16 @@ func (h *MCPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MCPHandler) handleInitialize(w http.ResponseWriter, request rpcRequest) bool {
|
||||
func (h *MCPHandler) handleInitialize(w http.ResponseWriter, request rpcRequest) string {
|
||||
var params struct {
|
||||
ProtocolVersion string `json:"protocolVersion"`
|
||||
ProtocolVersion json.RawMessage `json:"protocolVersion"`
|
||||
}
|
||||
if len(request.Params) == 0 || json.Unmarshal(request.Params, ¶ms) != nil || params.ProtocolVersion != mcpProtocolVersion {
|
||||
h.writeRPCError(w, http.StatusOK, request.ID, -32602, "MCP_PROTOCOL_VERSION_UNSUPPORTED", "Client must support MCP protocol version 2025-06-18.")
|
||||
return false
|
||||
result := "compatibility_success"
|
||||
if len(request.Params) != 0 && json.Unmarshal(request.Params, ¶ms) == nil {
|
||||
var protocolVersion string
|
||||
if json.Unmarshal(params.ProtocolVersion, &protocolVersion) == nil && protocolVersion == mcpProtocolVersion {
|
||||
result = "direct_success"
|
||||
}
|
||||
}
|
||||
h.writeRPCResult(w, request.ID, map[string]any{
|
||||
"protocolVersion": mcpProtocolVersion,
|
||||
@@ -189,7 +182,7 @@ func (h *MCPHandler) handleInitialize(w http.ResponseWriter, request rpcRequest)
|
||||
},
|
||||
"instructions": "Read-only planning support. Source records with invalid geometries are excluded, so results may be incomplete. Place-name matches are candidates that require user confirmation before coordinate-based analysis. Treat all records as potentially stale, verify resource availability and field safety, and never present access-line candidates as confirmed routes or responsibility records as live team locations.",
|
||||
})
|
||||
return true
|
||||
return result
|
||||
}
|
||||
|
||||
func (h *MCPHandler) handleToolCall(w http.ResponseWriter, r *http.Request, request rpcRequest, requestID string, started time.Time) {
|
||||
|
||||
Reference in new issue
Block a user