@verifik/mcp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +543 -2
- package/data/field-enrichment.json +452 -0
- package/docs/field-formats.md +148 -0
- package/lib/catalog.js +183 -0
- package/lib/client-features.js +64 -0
- package/lib/config.js +75 -0
- package/lib/description.js +67 -0
- package/lib/error-response.js +210 -0
- package/lib/field-enrichment.js +103 -0
- package/lib/field-normalize.js +65 -0
- package/lib/filters.js +53 -0
- package/lib/meta-tools.js +128 -0
- package/lib/proxy.js +224 -0
- package/lib/tool-naming.js +51 -0
- package/lib/tool-schema.js +245 -0
- package/lib/url-builder.js +58 -0
- package/lib/validate-args.js +230 -0
- package/package.json +60 -5
- package/server.js +140 -0
package/server.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { Server } = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const {
|
|
7
|
+
CallToolRequestSchema,
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
} = require("@modelcontextprotocol/sdk/types.js");
|
|
10
|
+
|
|
11
|
+
const { loadConfig } = require("./lib/config");
|
|
12
|
+
const { CatalogCache } = require("./lib/catalog");
|
|
13
|
+
const { invokeFeature, formatProxyResult, formatValidationError } = require("./lib/proxy");
|
|
14
|
+
const {
|
|
15
|
+
META_TOOL_DEFINITIONS,
|
|
16
|
+
handleListCatalog,
|
|
17
|
+
handleGetFeature,
|
|
18
|
+
} = require("./lib/meta-tools");
|
|
19
|
+
const { buildInputSchema } = require("./lib/tool-schema");
|
|
20
|
+
const { validateToolArgs } = require("./lib/validate-args");
|
|
21
|
+
|
|
22
|
+
const { version: packageVersion } = require("./package.json");
|
|
23
|
+
|
|
24
|
+
const SERVER_NAME = "verifik-smartcheck";
|
|
25
|
+
const SERVER_VERSION = packageVersion;
|
|
26
|
+
|
|
27
|
+
const logStderr = (message) => {
|
|
28
|
+
process.stderr.write(`[${SERVER_NAME}] ${message}\n`);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const createServer = async () => {
|
|
32
|
+
const config = loadConfig();
|
|
33
|
+
const catalogCache = new CatalogCache(config);
|
|
34
|
+
|
|
35
|
+
logStderr(`Loading catalog from ${config.apiBase} ...`);
|
|
36
|
+
await catalogCache.getState();
|
|
37
|
+
logStderr(`Catalog loaded with ${catalogCache.state.tools.length} proxy tools.`);
|
|
38
|
+
|
|
39
|
+
const server = new Server(
|
|
40
|
+
{
|
|
41
|
+
name: SERVER_NAME,
|
|
42
|
+
version: SERVER_VERSION,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
capabilities: {
|
|
46
|
+
tools: {},
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
52
|
+
const state = await catalogCache.getState();
|
|
53
|
+
return {
|
|
54
|
+
tools: [...META_TOOL_DEFINITIONS, ...state.tools],
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
59
|
+
const toolName = request.params.name;
|
|
60
|
+
const args = request.params.arguments || {};
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
if (toolName === "verifik_list_catalog") {
|
|
64
|
+
const payload = await handleListCatalog(catalogCache, args);
|
|
65
|
+
return structuredResult(payload);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (toolName === "verifik_get_feature") {
|
|
69
|
+
const payload = await handleGetFeature(catalogCache, args);
|
|
70
|
+
return structuredResult(payload);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const feature = catalogCache.resolveFeatureByToolName(toolName);
|
|
74
|
+
|
|
75
|
+
if (!feature) {
|
|
76
|
+
return errorResult(`Unknown tool: ${toolName}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const inputSchema = buildInputSchema(feature);
|
|
80
|
+
const validationError = validateToolArgs(args, feature, inputSchema);
|
|
81
|
+
|
|
82
|
+
if (validationError) {
|
|
83
|
+
const formatted = formatValidationError(validationError);
|
|
84
|
+
return {
|
|
85
|
+
content: [{ type: "text", text: formatted.text }],
|
|
86
|
+
structuredContent: formatted.structuredContent,
|
|
87
|
+
isError: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const proxyResult = await invokeFeature(feature, args, config);
|
|
92
|
+
const formatted = formatProxyResult(proxyResult);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
content: [{ type: "text", text: formatted.text }],
|
|
96
|
+
structuredContent: formatted.structuredContent,
|
|
97
|
+
isError: !proxyResult.ok,
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return errorResult(error instanceof Error ? error.message : String(error));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return server;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {unknown} payload
|
|
109
|
+
*/
|
|
110
|
+
const structuredResult = (payload) => {
|
|
111
|
+
const text = JSON.stringify(payload, null, 2);
|
|
112
|
+
return {
|
|
113
|
+
content: [{ type: "text", text }],
|
|
114
|
+
structuredContent: payload,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {string} message
|
|
120
|
+
*/
|
|
121
|
+
const errorResult = (message) => {
|
|
122
|
+
const formatted = formatValidationError(message);
|
|
123
|
+
return {
|
|
124
|
+
content: [{ type: "text", text: formatted.text }],
|
|
125
|
+
structuredContent: formatted.structuredContent,
|
|
126
|
+
isError: true,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const main = async () => {
|
|
131
|
+
const server = await createServer();
|
|
132
|
+
const transport = new StdioServerTransport();
|
|
133
|
+
await server.connect(transport);
|
|
134
|
+
logStderr("stdio transport connected.");
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
main().catch((error) => {
|
|
138
|
+
logStderr(error instanceof Error ? error.message : String(error));
|
|
139
|
+
process.exit(1);
|
|
140
|
+
});
|