@templmf/temp-solf-lmf 0.0.141 → 0.0.143
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/1.jpg +0 -0
- package/2.jpg +0 -0
- package/new/common.ts +113 -0
- package/new/http.ts +50 -0
- package/new/package.json.bak +23 -0
- package/new/sse.ts +78 -0
- package/new/stdio.ts +0 -0
- package/package.json +1 -1
- package/pic.png +0 -0
package/1.jpg
ADDED
|
Binary file
|
package/2.jpg
ADDED
|
Binary file
|
package/new/common.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import axios, { AxiosInstance } from "axios";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
// ================= Config =================
|
|
8
|
+
|
|
9
|
+
export const GITLAB_URL =
|
|
10
|
+
process.env.GITLAB_API_URL ??
|
|
11
|
+
"http://localhost/api/v3";
|
|
12
|
+
|
|
13
|
+
const TOKEN =
|
|
14
|
+
process.env.GITLAB_PRIVATE_TOKEN ??
|
|
15
|
+
process.env.GITLAB_PERSONAL_ACCESS_TOKEN ??
|
|
16
|
+
"";
|
|
17
|
+
|
|
18
|
+
if (!TOKEN) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"GITLAB_PRIVATE_TOKEN or GITLAB_PERSONAL_ACCESS_TOKEN is required."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ================= Axios =================
|
|
25
|
+
|
|
26
|
+
const api: AxiosInstance = axios.create({
|
|
27
|
+
baseURL: GITLAB_URL,
|
|
28
|
+
timeout: 30000,
|
|
29
|
+
headers: {
|
|
30
|
+
"PRIVATE-TOKEN": TOKEN,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === "0") {
|
|
35
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function request<T>(
|
|
39
|
+
method: "GET" | "POST" | "PUT",
|
|
40
|
+
path: string,
|
|
41
|
+
payload?: Record<string, unknown>,
|
|
42
|
+
): Promise<T> {
|
|
43
|
+
try {
|
|
44
|
+
const res = await api.request<T>({
|
|
45
|
+
method,
|
|
46
|
+
url: path,
|
|
47
|
+
...(method === "GET"
|
|
48
|
+
? { params: payload }
|
|
49
|
+
: { data: payload }),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return res.data;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (axios.isAxiosError(err)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`GitLab API ${err.response?.status}: ${
|
|
57
|
+
(err.response?.data as any)?.message ??
|
|
58
|
+
err.message
|
|
59
|
+
}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const gitlabGet = <T>(
|
|
68
|
+
path: string,
|
|
69
|
+
params?: Record<string, unknown>,
|
|
70
|
+
) => request<T>("GET", path, params);
|
|
71
|
+
|
|
72
|
+
export const gitlabPost = <T>(
|
|
73
|
+
path: string,
|
|
74
|
+
body?: Record<string, unknown>,
|
|
75
|
+
) => request<T>("POST", path, body);
|
|
76
|
+
|
|
77
|
+
export const gitlabPut = <T>(
|
|
78
|
+
path: string,
|
|
79
|
+
body?: Record<string, unknown>,
|
|
80
|
+
) => request<T>("PUT", path, body);
|
|
81
|
+
|
|
82
|
+
export function text(data: unknown) {
|
|
83
|
+
return {
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: "text" as const,
|
|
87
|
+
text: JSON.stringify(data, null, 2),
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ================= Server =================
|
|
94
|
+
|
|
95
|
+
export function createServer() {
|
|
96
|
+
|
|
97
|
+
const server = new McpServer({
|
|
98
|
+
name: "gitlab-v3-mcp-server",
|
|
99
|
+
version: "1.0.0",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ====================================================
|
|
103
|
+
// registerTool(...)
|
|
104
|
+
// registerTool(...)
|
|
105
|
+
// registerTool(...)
|
|
106
|
+
// ...
|
|
107
|
+
//
|
|
108
|
+
// 这里直接把你原来的所有 Tool 粘过来即可
|
|
109
|
+
// 不需要改任何代码
|
|
110
|
+
// ====================================================
|
|
111
|
+
|
|
112
|
+
return server;
|
|
113
|
+
}
|
package/new/http.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import express from "express";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
StreamableHTTPServerTransport,
|
|
7
|
+
} from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
createServer,
|
|
11
|
+
} from "./common.js";
|
|
12
|
+
|
|
13
|
+
const HOST =
|
|
14
|
+
process.env.MCP_HOST ??
|
|
15
|
+
"0.0.0.0";
|
|
16
|
+
|
|
17
|
+
const PORT =
|
|
18
|
+
Number(process.env.MCP_PORT ?? 3000);
|
|
19
|
+
|
|
20
|
+
const app = express();
|
|
21
|
+
|
|
22
|
+
app.use(express.json());
|
|
23
|
+
|
|
24
|
+
app.post("/mcp", async (req, res) => {
|
|
25
|
+
|
|
26
|
+
const server = createServer();
|
|
27
|
+
|
|
28
|
+
const transport =
|
|
29
|
+
new StreamableHTTPServerTransport({
|
|
30
|
+
sessionIdGenerator: () =>
|
|
31
|
+
crypto.randomUUID(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await server.connect(transport);
|
|
35
|
+
|
|
36
|
+
await transport.handleRequest(
|
|
37
|
+
req,
|
|
38
|
+
res,
|
|
39
|
+
req.body,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
app.listen(PORT, HOST, () => {
|
|
45
|
+
|
|
46
|
+
console.log(
|
|
47
|
+
`GitLab MCP Streamable HTTP listening on http://${HOST}:${PORT}/mcp`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"bin": {
|
|
4
|
+
"gitlab-mcp": "./dist/stdio.js",
|
|
5
|
+
"gitlab-mcp-http": "./dist/http.js",
|
|
6
|
+
"gitlab-mcp-sse": "./dist/sse.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsx src/stdio.ts",
|
|
11
|
+
"dev:http": "tsx src/http.ts",
|
|
12
|
+
"dev:sse": "tsx src/sse.ts",
|
|
13
|
+
"start": "node dist/stdio.js",
|
|
14
|
+
"start:http": "node dist/http.js",
|
|
15
|
+
"start:sse": "node dist/sse.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.x",
|
|
19
|
+
"axios": "^1.x",
|
|
20
|
+
"express": "^5.x",
|
|
21
|
+
"zod": "^4.x"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/new/sse.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import express from "express";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
SSEServerTransport,
|
|
7
|
+
} from "@modelcontextprotocol/sdk/server/sse.js";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
createServer,
|
|
11
|
+
} from "./common.js";
|
|
12
|
+
|
|
13
|
+
const HOST =
|
|
14
|
+
process.env.MCP_HOST ??
|
|
15
|
+
"0.0.0.0";
|
|
16
|
+
|
|
17
|
+
const PORT =
|
|
18
|
+
Number(process.env.MCP_PORT ?? 3000);
|
|
19
|
+
|
|
20
|
+
const app = express();
|
|
21
|
+
|
|
22
|
+
app.use(express.json());
|
|
23
|
+
|
|
24
|
+
const transports = new Map<
|
|
25
|
+
string,
|
|
26
|
+
SSEServerTransport
|
|
27
|
+
>();
|
|
28
|
+
|
|
29
|
+
app.get("/sse", async (_, res) => {
|
|
30
|
+
|
|
31
|
+
const server = createServer();
|
|
32
|
+
|
|
33
|
+
const transport =
|
|
34
|
+
new SSEServerTransport(
|
|
35
|
+
"/messages",
|
|
36
|
+
res,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
transports.set(
|
|
40
|
+
transport.sessionId,
|
|
41
|
+
transport,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
await server.connect(transport);
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
app.post("/messages", async (req, res) => {
|
|
49
|
+
|
|
50
|
+
const sessionId =
|
|
51
|
+
req.query.sessionId as string;
|
|
52
|
+
|
|
53
|
+
const transport =
|
|
54
|
+
transports.get(sessionId);
|
|
55
|
+
|
|
56
|
+
if (!transport) {
|
|
57
|
+
|
|
58
|
+
res.status(404).send("Unknown session");
|
|
59
|
+
|
|
60
|
+
return;
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await transport.handlePostMessage(
|
|
65
|
+
req,
|
|
66
|
+
res,
|
|
67
|
+
req.body,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
app.listen(PORT, HOST, () => {
|
|
73
|
+
|
|
74
|
+
console.log(
|
|
75
|
+
`GitLab MCP SSE listening on http://${HOST}:${PORT}/sse`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
});
|
package/new/stdio.ts
ADDED
|
File without changes
|
package/package.json
CHANGED
package/pic.png
DELETED
|
Binary file
|