@andrebuzeli/git-mcp 11.0.0 → 11.0.2
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 +51 -2
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -50,14 +50,63 @@ async function dispatch(req) {
|
|
|
50
50
|
throw new Error('Tool/action não suportado')
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
function writeJsonRpc(id, result, error) {
|
|
54
|
+
const msg = error ? { jsonrpc: '2.0', id, error } : { jsonrpc: '2.0', id, result }
|
|
55
|
+
process.stdout.write(JSON.stringify(msg) + '\n')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function listSchemas() {
|
|
59
|
+
const mod = await import('./tools/git-meta.js')
|
|
60
|
+
const meta = new mod.GitMetaTool(getEnv())
|
|
61
|
+
return await meta.handle('list', process.cwd(), {})
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
export async function startServer() {
|
|
54
65
|
process.stdin.setEncoding('utf-8')
|
|
55
66
|
let buf = ''
|
|
67
|
+
writeJsonRpc(0, { serverInfo: { name: '@andrebuzeli/git-mcp', version: '11.0.1' }, capabilities: { tools: true } })
|
|
56
68
|
process.stdin.on('data', async chunk => {
|
|
57
69
|
buf += chunk
|
|
58
|
-
try {
|
|
70
|
+
try {
|
|
71
|
+
const req = JSON.parse(buf); buf = ''
|
|
72
|
+
if (req && req.jsonrpc === '2.0' && typeof req.method === 'string') {
|
|
73
|
+
const id = req.id
|
|
74
|
+
const m = req.method
|
|
75
|
+
const p = req.params || {}
|
|
76
|
+
try {
|
|
77
|
+
if (m === 'initialize') {
|
|
78
|
+
const result = { serverInfo: { name: '@andrebuzeli/git-mcp', version: '11.0.0' }, capabilities: { tools: true } }
|
|
79
|
+
writeJsonRpc(id, result)
|
|
80
|
+
} else if (m === 'tools/list') {
|
|
81
|
+
const schemas = await listSchemas()
|
|
82
|
+
writeJsonRpc(id, { tools: schemas })
|
|
83
|
+
} else if (m === 'tools/call' || m === 'callTool' || m === 'call') {
|
|
84
|
+
const call = {
|
|
85
|
+
tool: p.name || p.tool,
|
|
86
|
+
action: p.action,
|
|
87
|
+
projectPath: p.projectPath || p.path,
|
|
88
|
+
args: p.args || p.arguments || {}
|
|
89
|
+
}
|
|
90
|
+
const res = await dispatch(call)
|
|
91
|
+
writeJsonRpc(id, { result: res })
|
|
92
|
+
} else if (m === 'ping') {
|
|
93
|
+
writeJsonRpc(id, { ok: true })
|
|
94
|
+
} else {
|
|
95
|
+
writeJsonRpc(id, undefined, { code: -32601, message: 'Method not found', data: m })
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
writeJsonRpc(id, undefined, { code: -32000, message: err?.message || 'Server error' })
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
const res = await dispatch(req)
|
|
102
|
+
process.stdout.write(JSON.stringify({ json: res }) + '\n')
|
|
103
|
+
}
|
|
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
|
+
}
|
|
59
109
|
})
|
|
60
|
-
console.log('git-mcp pronto')
|
|
61
110
|
}
|
|
62
111
|
|
|
63
112
|
export async function callOnce(req) { return await dispatch(req) }
|