Skip to content

Commit 9646d0b

Browse files
committed
fix mongodb error and some nits
1 parent 0d70e17 commit 9646d0b

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

internal/services/toolkit/tools/xtramcp/loader_v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (loader *XtraMCPLoaderV2) LoadToolsFromBackend(toolRegistry *registry.ToolR
5353

5454
// Register each tool dynamically, passing the session ID
5555
for _, toolSchema := range toolSchemas {
56-
// some tools require secrutiy context injection e.g. user_id to authenticate
56+
// some tools require security context injection e.g. user_id to authenticate
5757
requiresInjection := loader.requiresSecurityInjection(toolSchema)
5858

5959
dynamicTool := NewDynamicToolV2(
@@ -78,7 +78,7 @@ func (loader *XtraMCPLoaderV2) LoadToolsFromBackend(toolRegistry *registry.ToolR
7878
return nil
7979
}
8080

81-
// checks if a tool schema contains parameters that should be inejected instead of LLM-generated
81+
// checks if a tool schema contains parameters that should be injected instead of LLM-generated
8282
func (loader *XtraMCPLoaderV2) requiresSecurityInjection(schema ToolSchemaV2) bool {
8383
properties, ok := schema.InputSchema["properties"].(map[string]interface{})
8484
if !ok {

internal/services/toolkit/tools/xtramcp/schema_filter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ func filterSecurityParameters(schema map[string]interface{}) map[string]interfac
2525
}
2626

2727
// creates a deep copy of the schema using JSON marshal/unmarshal
28+
// Uses JSON round-trip because map[string]interface{} contains nested structures
29+
// This ensures modifications to the copy don't affect the original schema.
2830
func deepCopySchema(schema map[string]interface{}) map[string]interface{} {
2931
// Use JSON marshal/unmarshal for deep copy
3032
jsonBytes, err := json.Marshal(schema)
3133
if err != nil {
32-
// If marshaling fails, return original schema
34+
// Extremely unlikely with valid JSON schemas (MCP schemas are JSON-compatible)
35+
// // If marshaling fails, return original schema
3336
return schema
3437
}
3538

3639
var copy map[string]interface{}
3740
err = json.Unmarshal(jsonBytes, &copy)
3841
if err != nil {
39-
// If unmarshaling fails, return original schema
42+
// Should never happen if marshal succeeded
4043
return schema
4144
}
4245

@@ -52,7 +55,7 @@ func filterRequiredArray(required []interface{}, toRemove []string) []interface{
5255
removeMap[r] = true
5356
}
5457

55-
// filter our security params
58+
// filter out security params
5659
for _, item := range required {
5760
if str, ok := item.(string); ok {
5861
if !removeMap[str] {

internal/services/toolkit/tools/xtramcp/tool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910
"net/http"
@@ -139,7 +140,7 @@ func (t *DynamicTool) injectSecurityContext(ctx context.Context, argsMap map[str
139140
// 2. Validate user owns the project
140141
_, err := t.projectService.GetProject(ctx, actor.ID, projectId)
141142
if err != nil {
142-
if err == mongo.ErrNoDocuments {
143+
if errors.Is(err, mongo.ErrNoDocuments) {
143144
return fmt.Errorf("authorization failed: project not found or access denied")
144145
}
145146
return fmt.Errorf("authorization check failed: %w", err)

internal/services/toolkit/tools/xtramcp/tool_v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910
"net/http"
@@ -140,7 +141,7 @@ func (t *DynamicToolV2) injectSecurityContext(ctx context.Context, argsMap map[s
140141
// 2. Validate user owns the project
141142
_, err := t.projectService.GetProject(ctx, actor.ID, projectId)
142143
if err != nil {
143-
if err == mongo.ErrNoDocuments {
144+
if errors.Is(err, mongo.ErrNoDocuments) {
144145
return fmt.Errorf("authorization failed: project not found or access denied")
145146
}
146147
return fmt.Errorf("authorization check failed: %w", err)

0 commit comments

Comments
 (0)