style: format code for consistency and readability ✨
🚀 Breaking Changes: - None 📝 Details: - Adjusted import statements for consistency - Reformatted code for better readability - Removed unnecessary console.error statements
This commit is contained in:
67
index.ts
67
index.ts
@ -17,7 +17,7 @@ import path from "path";
|
|||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
// Add type imports for proxy agents
|
// Add type imports for proxy agents
|
||||||
import { Agent } from "http";
|
import { Agent } from "http";
|
||||||
import { Agent as HttpsAgent } from 'https';
|
import { Agent as HttpsAgent } from "https";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -187,7 +187,7 @@ try {
|
|||||||
SERVER_VERSION = packageJson.version || SERVER_VERSION;
|
SERVER_VERSION = packageJson.version || SERVER_VERSION;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Warning: Could not read version from package.json:", error);
|
// Warning: Could not read version from package.json - silently continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = new Server(
|
const server = new Server(
|
||||||
@ -215,8 +215,8 @@ const HTTPS_PROXY = process.env.HTTPS_PROXY;
|
|||||||
const NODE_TLS_REJECT_UNAUTHORIZED = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
const NODE_TLS_REJECT_UNAUTHORIZED = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
||||||
const GITLAB_CA_CERT_PATH = process.env.GITLAB_CA_CERT_PATH;
|
const GITLAB_CA_CERT_PATH = process.env.GITLAB_CA_CERT_PATH;
|
||||||
|
|
||||||
let sslOptions= undefined;
|
let sslOptions = undefined;
|
||||||
if (NODE_TLS_REJECT_UNAUTHORIZED === '0') {
|
if (NODE_TLS_REJECT_UNAUTHORIZED === "0") {
|
||||||
sslOptions = { rejectUnauthorized: false };
|
sslOptions = { rejectUnauthorized: false };
|
||||||
} else if (GITLAB_CA_CERT_PATH) {
|
} else if (GITLAB_CA_CERT_PATH) {
|
||||||
const ca = fs.readFileSync(GITLAB_CA_CERT_PATH);
|
const ca = fs.readFileSync(GITLAB_CA_CERT_PATH);
|
||||||
@ -323,8 +323,7 @@ const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "get_branch_diffs",
|
name: "get_branch_diffs",
|
||||||
description:
|
description: "Get the changes/diffs between two branches or commits in a GitLab project",
|
||||||
"Get the changes/diffs between two branches or commits in a GitLab project",
|
|
||||||
inputSchema: zodToJsonSchema(GetBranchDiffsSchema),
|
inputSchema: zodToJsonSchema(GetBranchDiffsSchema),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -908,7 +907,7 @@ async function listIssues(
|
|||||||
Object.entries(options).forEach(([key, value]) => {
|
Object.entries(options).forEach(([key, value]) => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
const keys = ["labels", "assignee_username"];
|
const keys = ["labels", "assignee_username"];
|
||||||
if ( keys.includes(key)) {
|
if (keys.includes(key)) {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
// Handle array of labels
|
// Handle array of labels
|
||||||
value.forEach(label => {
|
value.forEach(label => {
|
||||||
@ -1259,12 +1258,20 @@ async function listDiscussions(
|
|||||||
|
|
||||||
// Extract pagination headers
|
// Extract pagination headers
|
||||||
const pagination = {
|
const pagination = {
|
||||||
x_next_page: response.headers.get("x-next-page") ? parseInt(response.headers.get("x-next-page")!) : null,
|
x_next_page: response.headers.get("x-next-page")
|
||||||
|
? parseInt(response.headers.get("x-next-page")!)
|
||||||
|
: null,
|
||||||
x_page: response.headers.get("x-page") ? parseInt(response.headers.get("x-page")!) : undefined,
|
x_page: response.headers.get("x-page") ? parseInt(response.headers.get("x-page")!) : undefined,
|
||||||
x_per_page: response.headers.get("x-per-page") ? parseInt(response.headers.get("x-per-page")!) : undefined,
|
x_per_page: response.headers.get("x-per-page")
|
||||||
x_prev_page: response.headers.get("x-prev-page") ? parseInt(response.headers.get("x-prev-page")!) : null,
|
? parseInt(response.headers.get("x-per-page")!)
|
||||||
|
: undefined,
|
||||||
|
x_prev_page: response.headers.get("x-prev-page")
|
||||||
|
? parseInt(response.headers.get("x-prev-page")!)
|
||||||
|
: null,
|
||||||
x_total: response.headers.get("x-total") ? parseInt(response.headers.get("x-total")!) : null,
|
x_total: response.headers.get("x-total") ? parseInt(response.headers.get("x-total")!) : null,
|
||||||
x_total_pages: response.headers.get("x-total-pages") ? parseInt(response.headers.get("x-total-pages")!) : null,
|
x_total_pages: response.headers.get("x-total-pages")
|
||||||
|
? parseInt(response.headers.get("x-total-pages")!)
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return PaginatedDiscussionsResponseSchema.parse({
|
return PaginatedDiscussionsResponseSchema.parse({
|
||||||
@ -1859,9 +1866,7 @@ async function getBranchDiffs(
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorBody = await response.text();
|
const errorBody = await response.text();
|
||||||
throw new Error(
|
throw new Error(`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`);
|
||||||
`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@ -2643,10 +2648,13 @@ async function createPipeline(
|
|||||||
|
|
||||||
const body: any = { ref };
|
const body: any = { ref };
|
||||||
if (variables && variables.length > 0) {
|
if (variables && variables.length > 0) {
|
||||||
body.variables = variables.reduce((acc, { key, value }) => {
|
body.variables = variables.reduce(
|
||||||
|
(acc, { key, value }) => {
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
},
|
||||||
|
{} as Record<string, string>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(url.toString(), {
|
const response = await fetch(url.toString(), {
|
||||||
@ -3035,9 +3043,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|||||||
? tools1
|
? tools1
|
||||||
: tools1.filter(tool => !milestoneToolNames.includes(tool.name));
|
: tools1.filter(tool => !milestoneToolNames.includes(tool.name));
|
||||||
// Toggle pipeline tools by USE_PIPELINE flag
|
// Toggle pipeline tools by USE_PIPELINE flag
|
||||||
let tools = USE_PIPELINE
|
let tools = USE_PIPELINE ? tools2 : tools2.filter(tool => !pipelineToolNames.includes(tool.name));
|
||||||
? tools2
|
|
||||||
: tools2.filter(tool => !pipelineToolNames.includes(tool.name));
|
|
||||||
|
|
||||||
// <<< START: Gemini 호환성을 위해 $schema 제거 >>>
|
// <<< START: Gemini 호환성을 위해 $schema 제거 >>>
|
||||||
tools = tools.map(tool => {
|
tools = tools.map(tool => {
|
||||||
@ -3111,12 +3117,7 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
|||||||
|
|
||||||
case "get_branch_diffs": {
|
case "get_branch_diffs": {
|
||||||
const args = GetBranchDiffsSchema.parse(request.params.arguments);
|
const args = GetBranchDiffsSchema.parse(request.params.arguments);
|
||||||
const diffResp = await getBranchDiffs(
|
const diffResp = await getBranchDiffs(args.project_id, args.from, args.to, args.straight);
|
||||||
args.project_id,
|
|
||||||
args.from,
|
|
||||||
args.to,
|
|
||||||
args.straight
|
|
||||||
);
|
|
||||||
|
|
||||||
if (args.excluded_file_patterns?.length) {
|
if (args.excluded_file_patterns?.length) {
|
||||||
const regexPatterns = args.excluded_file_patterns.map(pattern => new RegExp(pattern));
|
const regexPatterns = args.excluded_file_patterns.map(pattern => new RegExp(pattern));
|
||||||
@ -3128,9 +3129,7 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Filter out files that match any of the regex patterns on new files
|
// Filter out files that match any of the regex patterns on new files
|
||||||
diffResp.diffs = diffResp.diffs.filter(diff =>
|
diffResp.diffs = diffResp.diffs.filter(diff => !matchesAnyPattern(diff.new_path));
|
||||||
!matchesAnyPattern(diff.new_path)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
|
content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
|
||||||
@ -3945,12 +3944,11 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
|||||||
*/
|
*/
|
||||||
async function runServer() {
|
async function runServer() {
|
||||||
try {
|
try {
|
||||||
console.error("========================");
|
// Server startup banner removed - inappropriate use of console.error for logging
|
||||||
console.error(`GitLab MCP Server v${SERVER_VERSION}`);
|
// Server version banner removed - inappropriate use of console.error for logging
|
||||||
console.error(`API URL: ${GITLAB_API_URL}`);
|
// API URL banner removed - inappropriate use of console.error for logging
|
||||||
console.error("========================");
|
// Server startup banner removed - inappropriate use of console.error for logging
|
||||||
if ( !SSE )
|
if (!SSE) {
|
||||||
{
|
|
||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
} else {
|
} else {
|
||||||
@ -3980,7 +3978,6 @@ async function runServer() {
|
|||||||
console.log(`Server is running on port ${PORT}`);
|
console.log(`Server is running on port ${PORT}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.error("GitLab MCP Server running on stdio");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error initializing server:", error);
|
console.error("Error initializing server:", error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
Reference in New Issue
Block a user