@@ -41,74 +41,54 @@ type MCPParams struct {
4141
4242// DynamicTool represents a generic tool that can handle any schema
4343type DynamicTool struct {
44- Name string
45- Description responses.ToolUnionParam
46- toolCallRecordDB * toolCallRecordDB.ToolCallRecordDB
47- projectService * services.ProjectService
48- coolDownTime time.Duration
49- baseURL string
50- client * http.Client
51- schema map [string ]interface {}
52- sessionID string // Reuse the session ID from initialization
44+ Name string
45+ Description responses.ToolUnionParam
46+ toolCallRecordDB * toolCallRecordDB.ToolCallRecordDB
47+ projectService * services.ProjectService
48+ coolDownTime time.Duration
49+ baseURL string
50+ client * http.Client
51+ schema map [string ]interface {}
52+ sessionID string // Reuse the session ID from initialization
53+ requiresInjection bool // Indicates if this tool needs user/project injection
5354}
5455
5556// NewDynamicTool creates a new dynamic tool from a schema
56- func NewDynamicTool (db * db.DB , projectService * services.ProjectService , toolSchema ToolSchema , baseURL string , sessionID string ) * DynamicTool {
57- // Create tool description with the schema
57+ func NewDynamicTool (db * db.DB , projectService * services.ProjectService , toolSchema ToolSchema , baseURL string , sessionID string , requiresInjection bool ) * DynamicTool {
58+ // filter schema if injection is required (hide security context like user_id/project_id from LLM)
59+ schemaForLLM := toolSchema .InputSchema
60+ if requiresInjection {
61+ schemaForLLM = filterSecurityParameters (toolSchema .InputSchema )
62+ }
63+
5864 description := responses.ToolUnionParam {
5965 OfFunction : & responses.FunctionToolParam {
6066 Name : toolSchema .Name ,
6167 Description : param .NewOpt (toolSchema .Description ),
62- Parameters : openai .FunctionParameters (toolSchema . InputSchema ),
68+ Parameters : openai .FunctionParameters (schemaForLLM ), // Use filtered schema
6369 },
6470 }
6571
6672 toolCallRecordDB := toolCallRecordDB .NewToolCallRecordDB (db )
73+ //TODO: consider letting llm client know of output schema too
6774 return & DynamicTool {
68- Name : toolSchema .Name ,
69- Description : description ,
70- toolCallRecordDB : toolCallRecordDB ,
71- projectService : projectService ,
72- coolDownTime : 5 * time .Minute ,
73- baseURL : baseURL ,
74- client : & http.Client {},
75- schema : toolSchema .InputSchema ,
76- sessionID : sessionID , // Store the session ID for reuse
75+ Name : toolSchema .Name ,
76+ Description : description ,
77+ toolCallRecordDB : toolCallRecordDB ,
78+ projectService : projectService ,
79+ coolDownTime : 5 * time .Minute ,
80+ baseURL : baseURL ,
81+ client : & http.Client {},
82+ schema : toolSchema .InputSchema , // Store original schema for validation
83+ sessionID : sessionID , // Store the session ID for reuse
84+ requiresInjection : requiresInjection ,
7785 }
7886}
7987
8088// Call handles the tool execution (generic for any tool)
89+ // DEPRECATED: v1 API is no longer supported. This method should not be called.
8190func (t * DynamicTool ) Call (ctx context.Context , toolCallId string , args json.RawMessage ) (string , string , error ) {
82- // Parse arguments as generic map since we don't know the structure
83- var argsMap map [string ]interface {}
84- err := json .Unmarshal (args , & argsMap )
85- if err != nil {
86- return "" , "" , err
87- }
88-
89- // Create function call record
90- record , err := t .toolCallRecordDB .Create (ctx , toolCallId , t .Name , argsMap )
91- if err != nil {
92- return "" , "" , err
93- }
94-
95- // Execute the tool via MCP
96- respStr , err := t .executeTool (argsMap )
97- if err != nil {
98- err = fmt .Errorf ("failed to execute tool %s: %v" , t .Name , err )
99- t .toolCallRecordDB .OnError (ctx , record , err )
100- return "" , "" , err
101- }
102-
103- rawJson , err := json .Marshal (respStr )
104- if err != nil {
105- err = fmt .Errorf ("failed to marshal tool result: %v" , err )
106- t .toolCallRecordDB .OnError (ctx , record , err )
107- return "" , "" , err
108- }
109- t .toolCallRecordDB .OnSuccess (ctx , record , string (rawJson ))
110-
111- return respStr , "" , nil
91+ return "" , "" , fmt .Errorf ("v1 API is deprecated and no longer supported. Please use v2 API instead" )
11292}
11393
11494// executeTool makes the MCP request (generic for any tool)
0 commit comments