@andrebuzeli/git-mcp 11.0.4 → 11.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server.js +56 -41
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -52,7 +52,9 @@ async function dispatch(req) {
|
|
|
52
52
|
|
|
53
53
|
function writeJsonRpc(id, result, error) {
|
|
54
54
|
const msg = error ? { jsonrpc: '2.0', id, error } : { jsonrpc: '2.0', id, result }
|
|
55
|
-
|
|
55
|
+
const json = JSON.stringify(msg)
|
|
56
|
+
const out = `Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`
|
|
57
|
+
process.stdout.write(out)
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
async function listSchemas() {
|
|
@@ -67,49 +69,62 @@ export async function startServer() {
|
|
|
67
69
|
process.stdin.resume()
|
|
68
70
|
process.stdin.on('data', async chunk => {
|
|
69
71
|
buf += chunk
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} else if (m === 'tools/list' || m === 'listOfferings') {
|
|
85
|
-
let schemas = await listSchemas()
|
|
86
|
-
if (schemas && !Array.isArray(schemas)) { schemas = Object.entries(schemas).map(([name, s]) => ({ name, ...s })) }
|
|
87
|
-
writeJsonRpc(id, { tools: schemas })
|
|
88
|
-
} else if (m === 'tools/call' || m === 'callTool' || m === 'call') {
|
|
89
|
-
const call = {
|
|
90
|
-
tool: p.name || p.tool,
|
|
91
|
-
action: p.action,
|
|
92
|
-
projectPath: p.projectPath || p.path,
|
|
93
|
-
args: p.args || p.arguments || {}
|
|
94
|
-
}
|
|
95
|
-
const res = await dispatch(call)
|
|
96
|
-
writeJsonRpc(id, { result: res })
|
|
97
|
-
} else if (m === 'ping') {
|
|
98
|
-
writeJsonRpc(id, { ok: true })
|
|
99
|
-
} else {
|
|
100
|
-
writeJsonRpc(id, undefined, { code: -32601, message: 'Method not found', data: m })
|
|
101
|
-
}
|
|
102
|
-
} catch (err) {
|
|
103
|
-
writeJsonRpc(id, undefined, { code: -32000, message: err?.message || 'Server error' })
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
writeJsonRpc(req?.id ?? null, undefined, { code: -32600, message: 'Invalid Request' })
|
|
107
|
-
}
|
|
108
|
-
} catch (e) {
|
|
109
|
-
// Ignore non-JSON lines or malformed input
|
|
72
|
+
// Try LSP-like framing with Content-Length
|
|
73
|
+
while (true) {
|
|
74
|
+
const headerEnd = buf.indexOf('\r\n\r\n')
|
|
75
|
+
if (headerEnd === -1) break
|
|
76
|
+
const header = buf.slice(0, headerEnd)
|
|
77
|
+
const m = header.match(/Content-Length:\s*(\d+)/i)
|
|
78
|
+
const len = m ? parseInt(m[1], 10) : null
|
|
79
|
+
const bodyStart = headerEnd + 4
|
|
80
|
+
if (len == null) {
|
|
81
|
+
// No content-length, fall back to line-based
|
|
82
|
+
const line = buf.slice(bodyStart)
|
|
83
|
+
buf = ''
|
|
84
|
+
try { const req = JSON.parse(line); await handleRpc(req) } catch { /* ignore */ }
|
|
85
|
+
break
|
|
110
86
|
}
|
|
87
|
+
if (buf.length - bodyStart < len) break
|
|
88
|
+
const body = buf.slice(bodyStart, bodyStart + len)
|
|
89
|
+
buf = buf.slice(bodyStart + len)
|
|
90
|
+
try { const req = JSON.parse(body); await handleRpc(req) } catch (e) { /* ignore parse errors */ }
|
|
111
91
|
}
|
|
112
92
|
})
|
|
113
93
|
}
|
|
114
94
|
|
|
95
|
+
async function handleRpc(req) {
|
|
96
|
+
if (req && req.jsonrpc === '2.0' && typeof req.method === 'string') {
|
|
97
|
+
const id = req.id
|
|
98
|
+
const m = req.method
|
|
99
|
+
const p = req.params || {}
|
|
100
|
+
try {
|
|
101
|
+
if (m === 'initialize') {
|
|
102
|
+
const result = { serverInfo: { name: '@andrebuzeli/git-mcp', version: '11.0.4' }, capabilities: { tools: true } }
|
|
103
|
+
writeJsonRpc(id, result)
|
|
104
|
+
} else if (m === 'tools/list' || m === 'listOfferings') {
|
|
105
|
+
let schemas = await listSchemas()
|
|
106
|
+
if (schemas && !Array.isArray(schemas)) { schemas = Object.entries(schemas).map(([name, s]) => ({ name, ...s })) }
|
|
107
|
+
writeJsonRpc(id, { tools: schemas })
|
|
108
|
+
} else if (m === 'tools/call' || m === 'callTool' || m === 'call') {
|
|
109
|
+
const call = {
|
|
110
|
+
tool: p.name || p.tool,
|
|
111
|
+
action: p.action,
|
|
112
|
+
projectPath: p.projectPath || p.path,
|
|
113
|
+
args: p.args || p.arguments || {}
|
|
114
|
+
}
|
|
115
|
+
const res = await dispatch(call)
|
|
116
|
+
writeJsonRpc(id, { result: res })
|
|
117
|
+
} else if (m === 'ping') {
|
|
118
|
+
writeJsonRpc(id, { ok: true })
|
|
119
|
+
} else {
|
|
120
|
+
writeJsonRpc(id, undefined, { code: -32601, message: 'Method not found', data: m })
|
|
121
|
+
}
|
|
122
|
+
} catch (err) {
|
|
123
|
+
writeJsonRpc(id, undefined, { code: -32000, message: err?.message || 'Server error' })
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
writeJsonRpc(req?.id ?? null, undefined, { code: -32600, message: 'Invalid Request' })
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
115
130
|
export async function callOnce(req) { return await dispatch(req) }
|