-
Notifications
You must be signed in to change notification settings - Fork 68
feat: Verify citations #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39c9c8b
feat: update loader to inject security context
4ndrelim dee7843
feat: implement security context filter checks and injection for spec…
4ndrelim 99b1483
nit
4ndrelim 9dc9048
feat: add context injection for xtramcp tools
4ndrelim 0d70e17
support xtramcp v2 integration
4ndrelim 9646d0b
fix mongodb error and some nits
4ndrelim 418274a
deprecate xtramcp toolcall for v1 api
4ndrelim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package xtramcp | ||
|
|
||
| import "encoding/json" | ||
|
|
||
| // parameters that should be injected server-side | ||
| var securityParameters = []string{"user_id", "project_id"} | ||
|
|
||
| // removes security parameters from schema shown to LLM so LLM does not need to generate / fill | ||
| func filterSecurityParameters(schema map[string]interface{}) map[string]interface{} { | ||
| filtered := deepCopySchema(schema) | ||
|
|
||
| // Remove from properties | ||
| if properties, ok := filtered["properties"].(map[string]interface{}); ok { | ||
| for _, param := range securityParameters { | ||
| delete(properties, param) | ||
| } | ||
| } | ||
|
|
||
| // Remove from required array | ||
| if required, ok := filtered["required"].([]interface{}); ok { | ||
| filtered["required"] = filterRequiredArray(required, securityParameters) | ||
| } | ||
|
|
||
| return filtered | ||
| } | ||
|
|
||
| // creates a deep copy of the schema using JSON marshal/unmarshal | ||
| // Uses JSON round-trip because map[string]interface{} contains nested structures | ||
| // This ensures modifications to the copy don't affect the original schema. | ||
| func deepCopySchema(schema map[string]interface{}) map[string]interface{} { | ||
| // Use JSON marshal/unmarshal for deep copy | ||
| jsonBytes, err := json.Marshal(schema) | ||
| if err != nil { | ||
| // Extremely unlikely with valid JSON schemas (MCP schemas are JSON-compatible) | ||
| // // If marshaling fails, return original schema | ||
| return schema | ||
| } | ||
|
|
||
| var copy map[string]interface{} | ||
| err = json.Unmarshal(jsonBytes, ©) | ||
| if err != nil { | ||
| // Should never happen if marshal succeeded | ||
| return schema | ||
| } | ||
|
|
||
| return copy | ||
| } | ||
|
|
||
| // removes security parameters from the required array | ||
| func filterRequiredArray(required []interface{}, toRemove []string) []interface{} { | ||
| filtered := []interface{}{} | ||
| removeMap := make(map[string]bool) | ||
|
|
||
| for _, r := range toRemove { | ||
| removeMap[r] = true | ||
| } | ||
|
|
||
| // filter out security params | ||
| for _, item := range required { | ||
| if str, ok := item.(string); ok { | ||
| if !removeMap[str] { | ||
| filtered = append(filtered, item) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return filtered | ||
| } |
4ndrelim marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.