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";
|
||||
// Add type imports for proxy agents
|
||||
import { Agent } from "http";
|
||||
import { Agent as HttpsAgent } from 'https';
|
||||
import { Agent as HttpsAgent } from "https";
|
||||
import { URL } from "url";
|
||||
|
||||
import {
|
||||
@ -187,7 +187,7 @@ try {
|
||||
SERVER_VERSION = packageJson.version || SERVER_VERSION;
|
||||
}
|
||||
} 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(
|
||||
@ -215,8 +215,8 @@ const HTTPS_PROXY = process.env.HTTPS_PROXY;
|
||||
const NODE_TLS_REJECT_UNAUTHORIZED = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
||||
const GITLAB_CA_CERT_PATH = process.env.GITLAB_CA_CERT_PATH;
|
||||
|
||||
let sslOptions= undefined;
|
||||
if (NODE_TLS_REJECT_UNAUTHORIZED === '0') {
|
||||
let sslOptions = undefined;
|
||||
if (NODE_TLS_REJECT_UNAUTHORIZED === "0") {
|
||||
sslOptions = { rejectUnauthorized: false };
|
||||
} else if (GITLAB_CA_CERT_PATH) {
|
||||
const ca = fs.readFileSync(GITLAB_CA_CERT_PATH);
|
||||
@ -323,8 +323,7 @@ const allTools = [
|
||||
},
|
||||
{
|
||||
name: "get_branch_diffs",
|
||||
description:
|
||||
"Get the changes/diffs between two branches or commits in a GitLab project",
|
||||
description: "Get the changes/diffs between two branches or commits in a GitLab project",
|
||||
inputSchema: zodToJsonSchema(GetBranchDiffsSchema),
|
||||
},
|
||||
{
|
||||
@ -908,7 +907,7 @@ async function listIssues(
|
||||
Object.entries(options).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
const keys = ["labels", "assignee_username"];
|
||||
if ( keys.includes(key)) {
|
||||
if (keys.includes(key)) {
|
||||
if (Array.isArray(value)) {
|
||||
// Handle array of labels
|
||||
value.forEach(label => {
|
||||
@ -1259,12 +1258,20 @@ async function listDiscussions(
|
||||
|
||||
// Extract pagination headers
|
||||
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_per_page: response.headers.get("x-per-page") ? 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_per_page: response.headers.get("x-per-page")
|
||||
? 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_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({
|
||||
@ -1859,9 +1866,7 @@ async function getBranchDiffs(
|
||||
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.text();
|
||||
throw new Error(
|
||||
`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`
|
||||
);
|
||||
throw new Error(`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
@ -2643,10 +2648,13 @@ async function createPipeline(
|
||||
|
||||
const body: any = { ref };
|
||||
if (variables && variables.length > 0) {
|
||||
body.variables = variables.reduce((acc, { key, value }) => {
|
||||
body.variables = variables.reduce(
|
||||
(acc, { key, value }) => {
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
},
|
||||
{} as Record<string, string>
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
@ -3035,9 +3043,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||
? tools1
|
||||
: tools1.filter(tool => !milestoneToolNames.includes(tool.name));
|
||||
// Toggle pipeline tools by USE_PIPELINE flag
|
||||
let tools = USE_PIPELINE
|
||||
? tools2
|
||||
: tools2.filter(tool => !pipelineToolNames.includes(tool.name));
|
||||
let tools = USE_PIPELINE ? tools2 : tools2.filter(tool => !pipelineToolNames.includes(tool.name));
|
||||
|
||||
// <<< START: Gemini 호환성을 위해 $schema 제거 >>>
|
||||
tools = tools.map(tool => {
|
||||
@ -3111,12 +3117,7 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
||||
|
||||
case "get_branch_diffs": {
|
||||
const args = GetBranchDiffsSchema.parse(request.params.arguments);
|
||||
const diffResp = await getBranchDiffs(
|
||||
args.project_id,
|
||||
args.from,
|
||||
args.to,
|
||||
args.straight
|
||||
);
|
||||
const diffResp = await getBranchDiffs(args.project_id, args.from, args.to, args.straight);
|
||||
|
||||
if (args.excluded_file_patterns?.length) {
|
||||
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
|
||||
diffResp.diffs = diffResp.diffs.filter(diff =>
|
||||
!matchesAnyPattern(diff.new_path)
|
||||
);
|
||||
diffResp.diffs = diffResp.diffs.filter(diff => !matchesAnyPattern(diff.new_path));
|
||||
}
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
|
||||
@ -3945,12 +3944,11 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
||||
*/
|
||||
async function runServer() {
|
||||
try {
|
||||
console.error("========================");
|
||||
console.error(`GitLab MCP Server v${SERVER_VERSION}`);
|
||||
console.error(`API URL: ${GITLAB_API_URL}`);
|
||||
console.error("========================");
|
||||
if ( !SSE )
|
||||
{
|
||||
// Server startup banner removed - inappropriate use of console.error for logging
|
||||
// Server version banner removed - inappropriate use of console.error for logging
|
||||
// API URL banner removed - inappropriate use of console.error for logging
|
||||
// Server startup banner removed - inappropriate use of console.error for logging
|
||||
if (!SSE) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
} else {
|
||||
@ -3980,7 +3978,6 @@ async function runServer() {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
}
|
||||
console.error("GitLab MCP Server running on stdio");
|
||||
} catch (error) {
|
||||
console.error("Error initializing server:", error);
|
||||
process.exit(1);
|
||||
|
Reference in New Issue
Block a user