MCPcopy
hub / github.com/dosco/graphjin / handleExecuteSavedQuery

Method handleExecuteSavedQuery

serv/mcp_tools.go:151–200  ·  view source on GitHub ↗

handleExecuteSavedQuery executes a saved query by name

(ctx context.Context, req mcp.CallToolRequest)

Source from the content-addressed store, hash-verified

149
150// handleExecuteSavedQuery executes a saved query by name
151func (ms *mcpServer) handleExecuteSavedQuery(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
152 ctx = ms.effectiveContext(ctx)
153 args := req.GetArguments()
154 name, _ := args["name"].(string)
155 namespace, _ := args["namespace"].(string)
156
157 if name == "" {
158 return mcp.NewToolResultError("query name is required"), nil
159 }
160
161 // Convert variables map to JSON
162 var varsJSON json.RawMessage
163 if vars, ok := args["variables"].(map[string]any); ok && len(vars) > 0 {
164 // Expand cursor IDs to full encrypted cursors
165 expandedVars, err := ms.expandCursorIDs(ctx, vars)
166 if err != nil {
167 return mcp.NewToolResultError(fmt.Sprintf("cursor lookup failed: %v", err)), nil
168 }
169 varsJSON, err = json.Marshal(expandedVars)
170 if err != nil {
171 return mcp.NewToolResultError(fmt.Sprintf("invalid variables: %v", err)), nil
172 }
173 }
174
175 var rc core.RequestConfig
176 if namespace != "" {
177 rc.SetNamespace(namespace)
178 } else {
179 rc.SetNamespace(ms.getNamespace())
180 }
181
182 if err := ms.service.checkGraphJinInitialized(); err != nil {
183 return mcp.NewToolResultError(err.Error()), nil
184 }
185
186 ctx = ms.service.applyIdentityContext(ctx)
187 res, err := ms.service.gj.GraphQLByName(ctx, name, varsJSON, &rc)
188
189 result := ExecuteResult{}
190 if err != nil {
191 result.Errors = []ErrorInfo{ms.errorInfo("", err.Error(), "execute_saved_query")}
192 } else {
193 // Replace encrypted cursors with short numeric IDs for LLM-friendly responses
194 result.Data = ms.processCursorsForMCP(ctx, res.Data)
195 for _, e := range res.Errors {
196 result.Errors = append(result.Errors, ms.errorInfoFromCoreError("", e, "execute_saved_query"))
197 }
198 }
199 return ms.toolResultJSON("execute_saved_query", args, result)
200}
201
202// handleExecuteWorkflow executes a named JS workflow from ./workflows.
203func (ms *mcpServer) handleExecuteWorkflow(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {

Calls 12

effectiveContextMethod · 0.95
expandCursorIDsMethod · 0.95
SetNamespaceMethod · 0.95
getNamespaceMethod · 0.95
errorInfoMethod · 0.95
processCursorsForMCPMethod · 0.95
toolResultJSONMethod · 0.95
applyIdentityContextMethod · 0.80
GraphQLByNameMethod · 0.80
ErrorMethod · 0.65