MCPcopy
hub / github.com/garrytan/gstack / fetch

Function fetch

browse/test/test-server.ts:15–44  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

13 port,
14 hostname: '127.0.0.1',
15 fetch(req) {
16 const url = new URL(req.url);
17
18 // Echo endpoint — returns request headers as JSON
19 if (url.pathname === '/echo') {
20 const headers: Record<string, string> = {};
21 req.headers.forEach((value, key) => { headers[key] = value; });
22 return new Response(JSON.stringify(headers, null, 2), {
23 headers: { 'Content-Type': 'application/json' },
24 });
25 }
26
27 let filePath = url.pathname === '/' ? '/basic.html' : url.pathname;
28
29 // Remove leading slash
30 filePath = filePath.replace(/^\//, '');
31 const fullPath = path.join(FIXTURES_DIR, filePath);
32
33 if (!fs.existsSync(fullPath)) {
34 return new Response('Not Found', { status: 404 });
35 }
36
37 const content = fs.readFileSync(fullPath, 'utf-8');
38 const ext = path.extname(fullPath);
39 const contentType = ext === '.html' ? 'text/html' : 'text/plain';
40
41 return new Response(content, {
42 headers: { 'Content-Type': contentType },
43 });
44 },
45 });
46
47 const url = `http://127.0.0.1:${server.port}`;

Callers 11

waitForReadyFunction · 0.70
spawnDaemonWithTunnelFunction · 0.70
postCommandFunction · 0.70
apiFunction · 0.70
batchFunction · 0.70
waitForReadyFunction · 0.70
grantTokenFunction · 0.70
fetchDatasetSampleFunction · 0.70
commandMethod · 0.50

Calls

no outgoing calls

Tested by 8

waitForReadyFunction · 0.56
spawnDaemonWithTunnelFunction · 0.56
postCommandFunction · 0.56
apiFunction · 0.56
batchFunction · 0.56
waitForReadyFunction · 0.56
grantTokenFunction · 0.56
fetchDatasetSampleFunction · 0.56