Hardcode Go default empty response
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
|
||||
"github.com/local-mcp/local-mcp-go/internal/config"
|
||||
"github.com/local-mcp/local-mcp-go/internal/events"
|
||||
"github.com/local-mcp/local-mcp-go/internal/models"
|
||||
"github.com/local-mcp/local-mcp-go/internal/store"
|
||||
@@ -25,9 +26,6 @@ const (
|
||||
// multiple keepalive progress updates.
|
||||
defaultWaitSeconds = 50
|
||||
|
||||
// defaultEmptyResponse is returned when the queue is empty after waiting.
|
||||
defaultEmptyResponse = "call this tool `get_user_request` again to fetch latest user input..."
|
||||
|
||||
// keepaliveInterval controls how often a log notification is sent to the
|
||||
// client while waiting. Reduced to 5s (from 20s) for more frequent progress updates.
|
||||
// This keeps transport-level TCP/HTTP read timeouts from firing.
|
||||
@@ -38,9 +36,9 @@ const (
|
||||
|
||||
// Handler wraps the MCP server and holds references to the stores it needs.
|
||||
type Handler struct {
|
||||
MCP *server.MCPServer
|
||||
instStore *store.InstructionStore
|
||||
settStore *store.SettingsStore
|
||||
MCP *server.MCPServer
|
||||
instStore *store.InstructionStore
|
||||
settStore *store.SettingsStore
|
||||
agentStore *store.AgentStore
|
||||
broker *events.Broker
|
||||
}
|
||||
@@ -53,7 +51,7 @@ func New(
|
||||
broker *events.Broker,
|
||||
) *Handler {
|
||||
h := &Handler{
|
||||
MCP: server.NewMCPServer("local-mcp", "1.0.0"),
|
||||
MCP: server.NewMCPServer("local-mcp", "1.0.0"),
|
||||
instStore: instStore,
|
||||
settStore: settStore,
|
||||
agentStore: agentStore,
|
||||
@@ -69,8 +67,6 @@ If no instruction is available the tool will wait up to wait_seconds
|
||||
|
||||
Args:
|
||||
agent_id: An identifier for this agent instance (used to track connectivity).
|
||||
default_response_override: Override the server-default empty response text
|
||||
for this single call.
|
||||
|
||||
Returns:
|
||||
A dict with keys: status, result_type, instruction, response,
|
||||
@@ -79,10 +75,6 @@ Returns:
|
||||
mcp.Description("Identifier for this agent instance"),
|
||||
mcp.DefaultString("unknown"),
|
||||
),
|
||||
mcp.WithString("default_response_override",
|
||||
mcp.Description("Override the server-default empty response for this call"),
|
||||
mcp.DefaultString(""),
|
||||
),
|
||||
),
|
||||
h.handleGetUserRequest,
|
||||
)
|
||||
@@ -92,7 +84,6 @@ Returns:
|
||||
|
||||
func (h *Handler) handleGetUserRequest(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
agentID := req.GetString("agent_id", "unknown")
|
||||
defaultOverride := req.GetString("default_response_override", "")
|
||||
|
||||
// Wait time is hardcoded to stay safely under the 60s client timeout
|
||||
actualWait := defaultWaitSeconds
|
||||
@@ -161,7 +152,7 @@ func (h *Handler) handleGetUserRequest(ctx context.Context, req mcp.CallToolRequ
|
||||
case <-ctx.Done():
|
||||
// Client disconnected.
|
||||
slog.Debug("get_user_request: context cancelled", "agent", agentID)
|
||||
return emptyResult(defaultOverride, 0), nil
|
||||
return emptyResult(0), nil
|
||||
case <-wakeup.Chan():
|
||||
// Instruction may have arrived — loop back to check.
|
||||
case <-time.After(sleep):
|
||||
@@ -221,7 +212,7 @@ func (h *Handler) handleGetUserRequest(ctx context.Context, req mcp.CallToolRequ
|
||||
}
|
||||
|
||||
slog.Info("get_user_request: empty", "agent", agentID, "waited", waited, "gen", myGen)
|
||||
return emptyResult(defaultOverride, waited), nil
|
||||
return emptyResult(waited), nil
|
||||
}
|
||||
|
||||
func (h *Handler) deliverInstruction(ctx context.Context, item *models.Instruction, agentID string, waited int) (*mcp.CallToolResult, error) {
|
||||
@@ -230,7 +221,7 @@ func (h *Handler) deliverInstruction(ctx context.Context, item *models.Instructi
|
||||
|
||||
// Broadcast consumed event + status update.
|
||||
h.broker.Broadcast("instruction.consumed", map[string]any{
|
||||
"item": item,
|
||||
"item": item,
|
||||
"consumed_by_agent_id": agentID,
|
||||
})
|
||||
h.broker.Broadcast("status.changed", map[string]any{"queue": counts})
|
||||
@@ -238,8 +229,8 @@ func (h *Handler) deliverInstruction(ctx context.Context, item *models.Instructi
|
||||
slog.Info("get_user_request: delivered", "id", item.ID, "agent", agentID, "waited", waited)
|
||||
|
||||
result := map[string]any{
|
||||
"status": "ok",
|
||||
"result_type": "instruction",
|
||||
"status": "ok",
|
||||
"result_type": "instruction",
|
||||
"instruction": map[string]any{
|
||||
"id": item.ID,
|
||||
"content": item.Content,
|
||||
@@ -252,12 +243,8 @@ func (h *Handler) deliverInstruction(ctx context.Context, item *models.Instructi
|
||||
return mcp.NewToolResultText(jsonMarshalStr(result)), nil
|
||||
}
|
||||
|
||||
func emptyResult(override string, waited int) *mcp.CallToolResult {
|
||||
resp := override
|
||||
if resp == "" {
|
||||
resp = defaultEmptyResponse
|
||||
}
|
||||
|
||||
func emptyResult(waited int) *mcp.CallToolResult {
|
||||
resp := config.DefaultEmptyResponse
|
||||
resultType := "empty"
|
||||
if resp != "" {
|
||||
resultType = "default_response"
|
||||
@@ -278,12 +265,3 @@ func jsonMarshalStr(v any) string {
|
||||
b, _ := json.Marshal(v)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user