mcp-jasypt-server 1.0.0
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/index.mjs +113 -0
- package/package.json +21 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP stdio server:代理本仓库 Spring Boot 的 Jasypt 接口。
|
|
3
|
+
* 需要 Node.js >= 18(全局 fetch)。
|
|
4
|
+
*
|
|
5
|
+
* 环境变量 JASYPT_API_BASE:API 根路径,默认 http://127.0.0.1:8091/hnair-tools/api
|
|
6
|
+
*
|
|
7
|
+
* Cursor 配置示例(settings.json):
|
|
8
|
+
* "mcpServers": {
|
|
9
|
+
* "jasypt-tools": {
|
|
10
|
+
* "command": "node",
|
|
11
|
+
* "args": ["D:/code/tools/trunk/devkit/mcp-jasypt-server/index.mjs"],
|
|
12
|
+
* "env": { "JASYPT_API_BASE": "http://127.0.0.1:8091/hnair-tools/api" }
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
18
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
19
|
+
import { z } from 'zod'
|
|
20
|
+
|
|
21
|
+
const API_BASE = (process.env.JASYPT_API_BASE || 'http://127.0.0.1:8091/hnair-tools/api').replace(
|
|
22
|
+
/\/$/,
|
|
23
|
+
'',
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
async function postJasypt(path, body) {
|
|
27
|
+
const url = `${API_BASE}${path.startsWith('/') ? path : `/${path}`}`
|
|
28
|
+
const res = await fetch(url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
body: JSON.stringify(body),
|
|
32
|
+
})
|
|
33
|
+
const text = await res.text()
|
|
34
|
+
let data
|
|
35
|
+
try {
|
|
36
|
+
data = JSON.parse(text)
|
|
37
|
+
} catch {
|
|
38
|
+
throw new Error(`HTTP ${res.status}: ${text}`)
|
|
39
|
+
}
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const msg = typeof data?.message === 'string' ? data.message : text
|
|
42
|
+
throw new Error(msg || `HTTP ${res.status}`)
|
|
43
|
+
}
|
|
44
|
+
return data
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const mcpServer = new McpServer({
|
|
48
|
+
name: 'jasypt-tools',
|
|
49
|
+
version: '1.0.0',
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
mcpServer.registerTool(
|
|
53
|
+
'jasypt_encrypt_yaml',
|
|
54
|
+
{
|
|
55
|
+
description:
|
|
56
|
+
'调用后端 Jasypt 对 YAML/文本加密:自动识别 username、password、url、secret、user、account、key、lv 等敏感段名;值为 true/false 不加密。可选 targetKeys、algorithm。',
|
|
57
|
+
inputSchema: {
|
|
58
|
+
content: z.string().describe('原始 YAML 或文本'),
|
|
59
|
+
masterPassword: z.string().describe('Jasypt 密码'),
|
|
60
|
+
algorithm: z
|
|
61
|
+
.string()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('空则后端默认 PBEWithMD5AndDES;可选 PBEWITHHMACSHA512ANDAES_256'),
|
|
64
|
+
targetKeys: z.array(z.string()).optional().describe('额外要加密的 key 或路径(叶子名或 a.b.c)'),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
async ({ content, masterPassword, algorithm, targetKeys }) => {
|
|
68
|
+
const data = await postJasypt('/jasypt/encrypt-text', {
|
|
69
|
+
content,
|
|
70
|
+
masterPassword,
|
|
71
|
+
algorithm: algorithm || undefined,
|
|
72
|
+
targetKeys: targetKeys?.length ? targetKeys : undefined,
|
|
73
|
+
})
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: 'text', text: data.output ?? JSON.stringify(data) }],
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
mcpServer.registerTool(
|
|
81
|
+
'jasypt_decrypt_yaml',
|
|
82
|
+
{
|
|
83
|
+
description: '调用后端 Jasypt 解密文本中的 ENC(...) 片段,algorithm 需与加密时一致。',
|
|
84
|
+
inputSchema: {
|
|
85
|
+
content: z.string().describe('含 ENC(...) 的文本'),
|
|
86
|
+
masterPassword: z.string().describe('Jasypt 密码'),
|
|
87
|
+
algorithm: z
|
|
88
|
+
.string()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe('空则后端默认 PBEWithMD5AndDES;需与加密时一致'),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
async ({ content, masterPassword, algorithm }) => {
|
|
94
|
+
const data = await postJasypt('/jasypt/decrypt-text', {
|
|
95
|
+
content,
|
|
96
|
+
masterPassword,
|
|
97
|
+
algorithm: algorithm || undefined,
|
|
98
|
+
})
|
|
99
|
+
return {
|
|
100
|
+
content: [{ type: 'text', text: data.output ?? JSON.stringify(data) }],
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
async function main() {
|
|
106
|
+
const transport = new StdioServerTransport()
|
|
107
|
+
await mcpServer.connect(transport)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main().catch((err) => {
|
|
111
|
+
console.error(err)
|
|
112
|
+
process.exit(1)
|
|
113
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-jasypt-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP stdio server for hnair-tools Jasypt encrypt/decrypt API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.mjs",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node index.mjs",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
19
|
+
"zod": "^3.23.8"
|
|
20
|
+
}
|
|
21
|
+
}
|