@znt/mcp 1.1.1 → 2.0.1
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/AGENTS_EXAMPLE.md +50 -0
- package/README.md +459 -90
- package/index.js +18 -119
- package/package.json +30 -21
- package/src/credential-setup.js +726 -0
- package/src/metrics.js +121 -0
- package/src/server.js +30 -0
- package/src/tool-definitions.js +143 -0
- package/src/znt-tools.js +555 -0
package/index.js
CHANGED
|
@@ -1,129 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
-
import {
|
|
7
|
-
CallToolRequestSchema,
|
|
8
|
-
ListToolsRequestSchema,
|
|
9
|
-
} from '@modelcontextprotocol/sdk/types.js';
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
const ZNT_API_URL = (process.env.ZNT_API_URL || 'http://localhost:8080').replace(/\/$/, '');
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
let clientPromise = null;
|
|
5
|
+
import { createZntMcpServer } from "./src/server.js";
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
* Establishes an SSE connection to the native Znt Go MCP Server
|
|
19
|
-
*/
|
|
20
|
-
async function connectClient() {
|
|
21
|
-
const sseUrl = new URL(`${ZNT_API_URL}/mcp/sse`);
|
|
22
|
-
const transport = new SSEClientTransport(sseUrl);
|
|
23
|
-
const client = new Client(
|
|
24
|
-
{ name: 'znt-mcp-adapter', version: '1.2.0' },
|
|
25
|
-
{ capabilities: {} }
|
|
26
|
-
);
|
|
7
|
+
const application = createZntMcpServer();
|
|
27
8
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
clientInstance = null;
|
|
35
|
-
clientPromise = null;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
await client.connect(transport);
|
|
39
|
-
clientInstance = client;
|
|
40
|
-
return client;
|
|
9
|
+
try {
|
|
10
|
+
await application.initialize();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
// Keep the MCP endpoint available. Tool calls retry the complete
|
|
13
|
+
// install-and-start sequence after a transient download or startup failure.
|
|
14
|
+
console.error(`znt-core is not ready: ${error.message}`);
|
|
41
15
|
}
|
|
42
16
|
|
|
43
|
-
|
|
44
|
-
* Returns active connected client or initiates a new connection
|
|
45
|
-
*/
|
|
46
|
-
async function getZntClient() {
|
|
47
|
-
if (clientInstance) {
|
|
48
|
-
return clientInstance;
|
|
49
|
-
}
|
|
50
|
-
if (clientPromise) {
|
|
51
|
-
return clientPromise;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
clientPromise = connectClient().catch((err) => {
|
|
55
|
-
clientInstance = null;
|
|
56
|
-
clientPromise = null;
|
|
57
|
-
throw new Error(`Failed to connect to Znt Go server at ${ZNT_API_URL}/mcp. Make sure Znt backend is running (go run main.go). Detail: ${err.message}`);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return clientPromise;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ─── MCP Server Setup (STDIO) ────────────────────────────────────
|
|
64
|
-
const server = new Server(
|
|
65
|
-
{ name: 'znt-mcp-adapter', version: '1.2.0' },
|
|
66
|
-
{ capabilities: { tools: {} } }
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// ─── Dynamic Tools Listing ───────────────────────────────────────
|
|
70
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
71
|
-
try {
|
|
72
|
-
const client = await getZntClient();
|
|
73
|
-
const res = await client.listTools();
|
|
74
|
-
return { tools: res.tools || [] };
|
|
75
|
-
} catch (err) {
|
|
76
|
-
// If backend is offline, return descriptive fallback status tool
|
|
77
|
-
return {
|
|
78
|
-
tools: [
|
|
79
|
-
{
|
|
80
|
-
name: 'znatok_server_offline',
|
|
81
|
-
description: `Znt backend is offline (${err.message}). Start server with 'go run main.go' to enable tools.`,
|
|
82
|
-
inputSchema: { type: 'object', properties: {} }
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// ─── Dynamic Tools Proxy Execution ──────────────────────────────
|
|
90
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
91
|
-
const toolName = request.params.name;
|
|
92
|
-
if (toolName === 'znatok_server_offline') {
|
|
93
|
-
return {
|
|
94
|
-
content: [{
|
|
95
|
-
type: 'text',
|
|
96
|
-
text: `Znt backend server is not running on ${ZNT_API_URL}. Please start Znt backend by running 'go run main.go' in workspace.`
|
|
97
|
-
}],
|
|
98
|
-
isError: true
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const client = await getZntClient();
|
|
104
|
-
const res = await client.callTool({
|
|
105
|
-
name: toolName,
|
|
106
|
-
arguments: request.params.arguments || {}
|
|
107
|
-
});
|
|
108
|
-
return res;
|
|
109
|
-
} catch (err) {
|
|
110
|
-
return {
|
|
111
|
-
content: [{
|
|
112
|
-
type: 'text',
|
|
113
|
-
text: `Error executing tool ${toolName} via Znt Go backend: ${err.message}`
|
|
114
|
-
}],
|
|
115
|
-
isError: true
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
});
|
|
17
|
+
await application.server.connect(new StdioServerTransport());
|
|
119
18
|
|
|
120
|
-
|
|
121
|
-
async function
|
|
122
|
-
|
|
123
|
-
|
|
19
|
+
let closing = false;
|
|
20
|
+
async function close() {
|
|
21
|
+
if (closing) return;
|
|
22
|
+
closing = true;
|
|
23
|
+
application.disconnect();
|
|
24
|
+
await application.server.close();
|
|
124
25
|
}
|
|
125
26
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
process.exit(1);
|
|
129
|
-
});
|
|
27
|
+
process.once("SIGINT", close);
|
|
28
|
+
process.once("SIGTERM", close);
|
package/package.json
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@znt/mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Model Context Protocol
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Model Context Protocol server for znt-core through @znt/sdk-nodejs",
|
|
6
5
|
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"znt-mcp": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"src",
|
|
13
|
+
"README.md",
|
|
14
|
+
"AGENTS_EXAMPLE.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "node index.js",
|
|
18
|
+
"test": "node --test",
|
|
19
|
+
"pack:check": "npm pack --dry-run"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
23
|
+
"@znt/sdk-nodejs": "^1.0.0",
|
|
24
|
+
"yaml": "^2.9.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
7
32
|
"keywords": [
|
|
8
33
|
"mcp",
|
|
9
34
|
"mcp-server",
|
|
@@ -12,23 +37,7 @@
|
|
|
12
37
|
"znatok",
|
|
13
38
|
"semantic-search",
|
|
14
39
|
"code-analysis",
|
|
15
|
-
"call-graph"
|
|
16
|
-
"ast",
|
|
17
|
-
"ai-agent",
|
|
18
|
-
"antigravity",
|
|
19
|
-
"claude-desktop"
|
|
40
|
+
"call-graph"
|
|
20
41
|
],
|
|
21
|
-
"
|
|
22
|
-
"znt-mcp": "./index.js"
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"index.js"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"start": "node index.js"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@modelcontextprotocol/sdk": "^1.0.1",
|
|
32
|
-
"ws": "^8.21.1"
|
|
33
|
-
}
|
|
42
|
+
"license": "UNLICENSED"
|
|
34
43
|
}
|