MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / handler

Function handler

website/api/v1/mcp/messages.ts:29–441  ·  view source on GitHub ↗
(req: any, res: any)

Source from the content-addressed store, hash-verified

27};
28
29export default async function handler(req: any, res: any) {
30 // Enable CORS
31 res.setHeader("Access-Control-Allow-Origin", "*");
32 res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
33 res.setHeader("Access-Control-Allow-Headers", "Content-Type");
34
35 if (req.method === "OPTIONS") {
36 return res.status(200).end();
37 }
38
39 if (req.method !== "POST") {
40 res.setHeader("Allow", "POST");
41 return res.status(405).json({ error: `Method ${req.method} not allowed` });
42 }
43
44 const message = req.body;
45 if (!message || typeof message !== "object") {
46 return res.status(400).json({ error: "Invalid JSON-RPC request." });
47 }
48
49 const { jsonrpc, method, id, params } = message;
50
51 if (jsonrpc !== "2.0") {
52 return res.status(400).json({
53 jsonrpc: "2.0",
54 id: id || null,
55 error: { code: -32600, message: "Invalid Request: expected jsonrpc: '2.0'" }
56 });
57 }
58
59 const supabaseUrl = process.env.VITE_SUPABASE_URL || process.env.SUPABASE_URL;
60 const supabaseAnonKey = process.env.VITE_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY;
61
62 if (!supabaseUrl || !supabaseAnonKey) {
63 return res.status(200).json({
64 jsonrpc: "2.0",
65 id,
66 error: { code: -32000, message: "Server configuration error: Supabase credentials are missing on Vercel." }
67 });
68 }
69
70 const supabase = createClient(supabaseUrl, supabaseAnonKey);
71
72 try {
73 switch (method) {
74 case "initialize": {
75 return res.status(200).json({
76 jsonrpc: "2.0",
77 id,
78 result: {
79 protocolVersion: "2024-11-05",
80 capabilities: {
81 tools: {}
82 },
83 serverInfo: {
84 name: "CodeGraphContext-Dynamic-MCP",
85 version: "1.0.0"
86 }

Callers

nothing calls this directly

Calls 11

resolveFunction · 0.85
fromMethod · 0.80
subscribeMethod · 0.80
onMethod · 0.80
sendMethod · 0.80
errorMethod · 0.80
extractSessionTokenFunction · 0.70
cleanupFunction · 0.70
mapMethod · 0.65
addMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected