MCPcopy
hub / github.com/BuilderIO/agent-native / dispatch

Function dispatch

packages/core/src/tools/routes.ts:80–235  ·  view source on GitHub ↗
(
  event: H3Event,
  method: string,
  parts: string[],
  userEmail: string,
)

Source from the content-addressed store, hash-verified

78}
79
80async function dispatch(
81 event: H3Event,
82 method: string,
83 parts: string[],
84 userEmail: string,
85): Promise<unknown> {
86 // POST /sql/query — read-only SQL for tool iframes
87 if (
88 method === "POST" &&
89 parts.length === 2 &&
90 parts[0] === "sql" &&
91 parts[1] === "query"
92 ) {
93 return handleSqlQuery(event);
94 }
95
96 // POST /sql/exec — write SQL for tool iframes
97 if (
98 method === "POST" &&
99 parts.length === 2 &&
100 parts[0] === "sql" &&
101 parts[1] === "exec"
102 ) {
103 return handleSqlExec(event);
104 }
105
106 // GET /data/:toolId/:collection — list items in a collection
107 if (method === "GET" && parts.length === 3 && parts[0] === "data") {
108 return handleToolDataList(event, parts[1], parts[2], userEmail);
109 }
110
111 // POST /data/:toolId/:collection — create/upsert an item
112 if (method === "POST" && parts.length === 3 && parts[0] === "data") {
113 return handleToolDataUpsert(event, parts[1], parts[2], userEmail);
114 }
115
116 // DELETE /data/:toolId/:collection/:itemId — delete an item
117 if (method === "DELETE" && parts.length === 4 && parts[0] === "data") {
118 return handleToolDataDelete(event, parts[1], parts[2], parts[3], userEmail);
119 }
120
121 // POST /proxy
122 if (method === "POST" && parts.length === 1 && parts[0] === "proxy") {
123 return handleProxy(event, userEmail);
124 }
125
126 // GET / — list
127 if (method === "GET" && parts.length === 0) {
128 return listTools();
129 }
130
131 // POST / — create
132 if (method === "POST" && parts.length === 0) {
133 const body = await readBody(event);
134 if (!body.name) {
135 setResponseStatus(event, 400);
136 return { error: "name is required" };
137 }

Callers 1

createToolsHandlerFunction · 0.70

Calls 15

handleSqlQueryFunction · 0.85
handleSqlExecFunction · 0.85
handleToolDataListFunction · 0.85
handleToolDataUpsertFunction · 0.85
handleToolDataDeleteFunction · 0.85
handleProxyFunction · 0.85
listToolsFunction · 0.85
readBodyFunction · 0.85
createToolFunction · 0.85
recordChangeFunction · 0.85
resolveAccessFunction · 0.85
getThemeVarsFunction · 0.85

Tested by

no test coverage detected