fix(mcp): validate search_graph inputs before Zep API calls#548
Open
vedikatai wants to merge 2 commits into
Open
fix(mcp): validate search_graph inputs before Zep API calls#548vedikatai wants to merge 2 commits into
vedikatai wants to merge 2 commits into
Conversation
Reject empty/whitespace queries, queries over 2000 runes, limit values outside 1-100 when explicitly set, and min_fact_rating outside [0,1]. Mirrors existing fmt.Errorf validation style used in transform package.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds defensive input validation to the Go MCP server
search_graphhandler so malformed or abusive tool arguments are rejected before they reach the Zep API.This closes a validation gap where
SearchGraphInputfields were passed through with no bounds checking, empty-string checks, or max-length enforcement.Security rationale
The MCP server is an untrusted boundary: clients (agents, IDEs, scripts) can send arbitrary tool arguments. Without local validation:
limit(negative or very large) can cause unintended expensive scans or invalid API calls.min_fact_rating(the score threshold field on this tool) can send nonsensical filter values to the API.Failing fast with clear
fmt.Errorfmessages matches existing handler/transform error patterns and keeps bad inputs out of the network path.Changes
SearchGraphInput.Validate()—mcp/zep-mcp-server/internal/handlers/types.goNew method enforces:
queryquery cannot be empty)query> 2000 runesquery exceeds maximum length of 2000 characters)limitoutside 1–100limit must be between 1 and 100);0remains the "use default" sentinelmin_fact_ratingoutside [0.0, 1.0]min_fact_rating must be between 0 and 1);0still means omittedConstants:
searchQueryMaxLen,searchLimitMin/Max,searchMinScoreMin/Max(lines 10–16 intypes.go).Error style mirrors
internal/transform.ValidateRequired(fmt.Errorf("... cannot be empty"), etc.).Handler wiring —
mcp/zep-mcp-server/internal/handlers/search.goHandleSearchGraphnow callsinput.Validate()before applying defaults and buildingzep.GraphSearchQuery(lines 17–19), so explicit out-of-range limits are rejected rather than being overwritten by defaults.Graph handler (
graph.go) checkThere is no
internal/handlers/graph.goin this package. Graph search is implemented only in:search.go—HandleSearchGraph(the tool fixed here)nodes.go,edges.go,episodes.go,node_detail.go,edge_detail.go,episode_detail.go,node_edges.go,episode_mentions.go) which take UUIDs/IDs/limits only and do not accept free-text search queries or score thresholdsSo the validation gap was specific to
search_graph, not a missing parallelgraph.gofile.Tests added
All in existing
mcp/zep-mcp-server/internal/handlers/types_test.govia newTestSearchGraphInputValidate(table-driven, same style asTestGetUserInputValidation):Valid
valid minimal queryvalid query with surrounding whitespacevalid query at max length(2000 chars)valid limit omitted (zero uses handler default)valid limit at minimum boundary(1)valid limit at maximum boundary(100)valid min_fact_rating omitted (zero)valid min_fact_rating at minimum boundary(0.0)valid min_fact_rating at maximum boundary(1.0)valid min_fact_rating mid range(0.5)limit zero is default sentinel not errorInvalid
empty querywhitespace only queryquery exceeds max length(2001 chars)limit below minimum(-1)limit above maximum(101)min_fact_rating below minimum(-0.01)min_fact_rating above maximum(1.01)Verification
All packages pass locally.
Test plan
go test ./...undermcp/zep-mcp-serverpassesmin_fact_ratingboundaries: 0, 1 ok; -0.01, 1.01 rejected