@andrebuzeli/git-mcp 11.0.2 → 11.0.4
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 +38 -35
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -64,47 +64,50 @@ async function listSchemas() {
|
|
|
64
64
|
export async function startServer() {
|
|
65
65
|
process.stdin.setEncoding('utf-8')
|
|
66
66
|
let buf = ''
|
|
67
|
-
|
|
67
|
+
process.stdin.resume()
|
|
68
68
|
process.stdin.on('data', async chunk => {
|
|
69
69
|
buf += chunk
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
const lines = buf.split(/\r?\n/)
|
|
71
|
+
buf = lines.pop() || ''
|
|
72
|
+
for (const line of lines) {
|
|
73
|
+
if (!line.trim()) continue
|
|
74
|
+
try {
|
|
75
|
+
const req = JSON.parse(line)
|
|
76
|
+
if (req && req.jsonrpc === '2.0' && typeof req.method === 'string') {
|
|
77
|
+
const id = req.id
|
|
78
|
+
const m = req.method
|
|
79
|
+
const p = req.params || {}
|
|
80
|
+
try {
|
|
81
|
+
if (m === 'initialize') {
|
|
82
|
+
const result = { serverInfo: { name: '@andrebuzeli/git-mcp', version: '11.0.2' }, capabilities: { tools: true } }
|
|
83
|
+
writeJsonRpc(id, result)
|
|
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 })
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
writeJsonRpc(id, {
|
|
92
|
-
} else if (m === 'ping') {
|
|
93
|
-
writeJsonRpc(id, { ok: true })
|
|
94
|
-
} else {
|
|
95
|
-
writeJsonRpc(id, undefined, { code: -32601, message: 'Method not found', data: m })
|
|
102
|
+
} catch (err) {
|
|
103
|
+
writeJsonRpc(id, undefined, { code: -32000, message: err?.message || 'Server error' })
|
|
96
104
|
}
|
|
97
|
-
}
|
|
98
|
-
writeJsonRpc(id, undefined, { code: -
|
|
105
|
+
} else {
|
|
106
|
+
writeJsonRpc(req?.id ?? null, undefined, { code: -32600, message: 'Invalid Request' })
|
|
99
107
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
process.stdout.write(JSON.stringify({ json: res }) + '\n')
|
|
108
|
+
} catch (e) {
|
|
109
|
+
// Ignore non-JSON lines or malformed input
|
|
103
110
|
}
|
|
104
|
-
} catch (e) {
|
|
105
|
-
if (e instanceof SyntaxError) return
|
|
106
|
-
process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error', data: e.message } }) + '\n')
|
|
107
|
-
buf = ''
|
|
108
111
|
}
|
|
109
112
|
})
|
|
110
113
|
}
|