MCPcopy Create free account
hub / github.com/arctic-cli/interface / execute

Function execute

packages/arctic/src/tool/codesearch.ts:54–137  ·  view source on GitHub ↗
(params, ctx)

Source from the content-addressed store, hash-verified

52 ),
53 }),
54 async execute(params, ctx) {
55 const cfg = await Config.get()
56 if (cfg.permission?.webfetch === "ask")
57 await Permission.ask({
58 type: "codesearch",
59 sessionID: ctx.sessionID,
60 messageID: ctx.messageID,
61 callID: ctx.callID,
62 title: "Search code for: " + params.query,
63 metadata: {
64 query: params.query,
65 tokensNum: params.tokensNum,
66 },
67 })
68
69 const codeRequest: McpCodeRequest = {
70 jsonrpc: "2.0",
71 id: 1,
72 method: "tools/call",
73 params: {
74 name: "get_code_context_exa",
75 arguments: {
76 query: params.query,
77 tokensNum: params.tokensNum || 5000,
78 },
79 },
80 }
81
82 const controller = new AbortController()
83 const timeoutId = setTimeout(() => controller.abort(), 30000)
84
85 try {
86 const headers: Record<string, string> = {
87 accept: "application/json, text/event-stream",
88 "content-type": "application/json",
89 }
90
91 const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.CONTEXT}`, {
92 method: "POST",
93 headers,
94 body: JSON.stringify(codeRequest),
95 signal: AbortSignal.any([controller.signal, ctx.abort]),
96 })
97
98 clearTimeout(timeoutId)
99
100 if (!response.ok) {
101 const errorText = await response.text()
102 throw new Error(`Code search error (${response.status}): ${errorText}`)
103 }
104
105 const responseText = await response.text()
106
107 // Parse SSE response
108 const lines = responseText.split("\n")
109 for (const line of lines) {
110 if (line.startsWith("data: ")) {
111 const data: McpCodeResponse = JSON.parse(line.substring(6))

Callers

nothing calls this directly

Calls 4

textMethod · 0.65
fetchFunction · 0.50
getMethod · 0.45
abortMethod · 0.45

Tested by

no test coverage detected