Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
cdf4697ef1 |
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,17 +1,3 @@
|
||||
## [1.0.63] - 2025-06-12
|
||||
|
||||
### Added
|
||||
|
||||
- 📊 **CI Job Log Pagination**: Added pagination support for CI job logs to prevent context window flooding
|
||||
- `get_pipeline_job_output` now supports optional `limit` and `offset` parameters
|
||||
- Default limit is 1000 lines when pagination is used
|
||||
- Returns lines from the end of the log, with configurable offset
|
||||
- Includes truncation metadata showing what was skipped
|
||||
- Maintains backward compatibility (no parameters = full log)
|
||||
- See: [PR #97](https://github.com/zereight/gitlab-mcp/pull/97)
|
||||
|
||||
---
|
||||
|
||||
## [1.0.62] - 2025-06-10
|
||||
|
||||
### Fixed
|
||||
|
189
index.ts
189
index.ts
@ -172,6 +172,12 @@ import {
|
||||
GitLabCompareResultSchema,
|
||||
GetBranchDiffsSchema,
|
||||
ListWikiPagesOptions,
|
||||
ListCommitsSchema,
|
||||
GetCommitSchema,
|
||||
GetCommitDiffSchema,
|
||||
type ListCommitsOptions,
|
||||
type GetCommitOptions,
|
||||
type GetCommitDiffOptions,
|
||||
} from "./schemas.js";
|
||||
|
||||
/**
|
||||
@ -523,7 +529,7 @@ const allTools = [
|
||||
},
|
||||
{
|
||||
name: "get_pipeline_job_output",
|
||||
description: "Get the output/trace of a GitLab pipeline job with optional pagination to limit context window usage",
|
||||
description: "Get the output/trace of a GitLab pipeline job number",
|
||||
inputSchema: zodToJsonSchema(GetPipelineJobOutputSchema),
|
||||
},
|
||||
{
|
||||
@ -596,6 +602,21 @@ const allTools = [
|
||||
description: "Get GitLab user details by usernames",
|
||||
inputSchema: zodToJsonSchema(GetUsersSchema),
|
||||
},
|
||||
{
|
||||
name: "list_commits",
|
||||
description: "List repository commits with filtering options",
|
||||
inputSchema: zodToJsonSchema(ListCommitsSchema),
|
||||
},
|
||||
{
|
||||
name: "get_commit",
|
||||
description: "Get details of a specific commit",
|
||||
inputSchema: zodToJsonSchema(GetCommitSchema),
|
||||
},
|
||||
{
|
||||
name: "get_commit_diff",
|
||||
description: "Get changes/diffs of a specific commit",
|
||||
inputSchema: zodToJsonSchema(GetCommitDiffSchema),
|
||||
},
|
||||
];
|
||||
|
||||
// Define which tools are read-only
|
||||
@ -634,6 +655,9 @@ const readOnlyTools = [
|
||||
"list_wiki_pages",
|
||||
"get_wiki_page",
|
||||
"get_users",
|
||||
"list_commits",
|
||||
"get_commit",
|
||||
"get_commit_diff",
|
||||
];
|
||||
|
||||
// Define which tools are related to wiki and can be toggled by USE_GITLAB_WIKI
|
||||
@ -2611,11 +2635,9 @@ async function getPipelineJob(projectId: string, jobId: number): Promise<GitLabP
|
||||
*
|
||||
* @param {string} projectId - The ID or URL-encoded path of the project
|
||||
* @param {number} jobId - The ID of the job
|
||||
* @param {number} limit - Maximum number of lines to return from the end (default: 1000)
|
||||
* @param {number} offset - Number of lines to skip from the end (default: 0)
|
||||
* @returns {Promise<string>} The job output/trace
|
||||
*/
|
||||
async function getPipelineJobOutput(projectId: string, jobId: number, limit?: number, offset?: number): Promise<string> {
|
||||
async function getPipelineJobOutput(projectId: string, jobId: number): Promise<string> {
|
||||
projectId = decodeURIComponent(projectId); // Decode project ID
|
||||
const url = new URL(
|
||||
`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/jobs/${jobId}/trace`
|
||||
@ -2634,35 +2656,7 @@ async function getPipelineJobOutput(projectId: string, jobId: number, limit?: nu
|
||||
}
|
||||
|
||||
await handleGitLabError(response);
|
||||
const fullTrace = await response.text();
|
||||
|
||||
// Apply client-side pagination to limit context window usage
|
||||
if (limit !== undefined || offset !== undefined) {
|
||||
const lines = fullTrace.split('\n');
|
||||
const startOffset = offset || 0;
|
||||
const maxLines = limit || 1000;
|
||||
|
||||
// Return lines from the end, skipping offset lines and limiting to maxLines
|
||||
const startIndex = Math.max(0, lines.length - startOffset - maxLines);
|
||||
const endIndex = lines.length - startOffset;
|
||||
|
||||
const selectedLines = lines.slice(startIndex, endIndex);
|
||||
const result = selectedLines.join('\n');
|
||||
|
||||
// Add metadata about truncation
|
||||
if (startIndex > 0 || endIndex < lines.length) {
|
||||
const totalLines = lines.length;
|
||||
const shownLines = selectedLines.length;
|
||||
const skippedFromStart = startIndex;
|
||||
const skippedFromEnd = startOffset;
|
||||
|
||||
return `[Log truncated: showing ${shownLines} of ${totalLines} lines, skipped ${skippedFromStart} from start, ${skippedFromEnd} from end]\n\n${result}`;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return fullTrace;
|
||||
return await response.text();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3069,6 +3063,107 @@ async function getUsers(usernames: string[]): Promise<GitLabUsersResponse> {
|
||||
return GitLabUsersResponseSchema.parse(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* List repository commits
|
||||
* 저장소 커밋 목록 조회
|
||||
*
|
||||
* @param {string} projectId - Project ID or URL-encoded path
|
||||
* @param {ListCommitsOptions} options - List commits options
|
||||
* @returns {Promise<GitLabCommit[]>} List of commits
|
||||
*/
|
||||
async function listCommits(
|
||||
projectId: string,
|
||||
options: Omit<ListCommitsOptions, "project_id"> = {}
|
||||
): Promise<GitLabCommit[]> {
|
||||
projectId = decodeURIComponent(projectId);
|
||||
const url = new URL(
|
||||
`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/commits`
|
||||
);
|
||||
|
||||
// Add query parameters
|
||||
if (options.ref_name) url.searchParams.append("ref_name", options.ref_name);
|
||||
if (options.since) url.searchParams.append("since", options.since);
|
||||
if (options.until) url.searchParams.append("until", options.until);
|
||||
if (options.path) url.searchParams.append("path", options.path);
|
||||
if (options.author) url.searchParams.append("author", options.author);
|
||||
if (options.all) url.searchParams.append("all", options.all.toString());
|
||||
if (options.with_stats) url.searchParams.append("with_stats", options.with_stats.toString());
|
||||
if (options.first_parent) url.searchParams.append("first_parent", options.first_parent.toString());
|
||||
if (options.order) url.searchParams.append("order", options.order);
|
||||
if (options.trailers) url.searchParams.append("trailers", options.trailers.toString());
|
||||
if (options.page) url.searchParams.append("page", options.page.toString());
|
||||
if (options.per_page) url.searchParams.append("per_page", options.per_page.toString());
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
...DEFAULT_FETCH_CONFIG,
|
||||
});
|
||||
|
||||
await handleGitLabError(response);
|
||||
|
||||
const data = await response.json();
|
||||
return z.array(GitLabCommitSchema).parse(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single commit
|
||||
* 단일 커밋 정보 조회
|
||||
*
|
||||
* @param {string} projectId - Project ID or URL-encoded path
|
||||
* @param {string} sha - The commit hash or name of a repository branch or tag
|
||||
* @param {boolean} [stats] - Include commit stats
|
||||
* @returns {Promise<GitLabCommit>} The commit details
|
||||
*/
|
||||
async function getCommit(
|
||||
projectId: string,
|
||||
sha: string,
|
||||
stats?: boolean
|
||||
): Promise<GitLabCommit> {
|
||||
projectId = decodeURIComponent(projectId);
|
||||
const url = new URL(
|
||||
`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/commits/${encodeURIComponent(sha)}`
|
||||
);
|
||||
|
||||
if (stats) {
|
||||
url.searchParams.append("stats", "true");
|
||||
}
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
...DEFAULT_FETCH_CONFIG,
|
||||
});
|
||||
|
||||
await handleGitLabError(response);
|
||||
|
||||
const data = await response.json();
|
||||
return GitLabCommitSchema.parse(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commit diff
|
||||
* 커밋 변경사항 조회
|
||||
*
|
||||
* @param {string} projectId - Project ID or URL-encoded path
|
||||
* @param {string} sha - The commit hash or name of a repository branch or tag
|
||||
* @returns {Promise<GitLabMergeRequestDiff[]>} The commit diffs
|
||||
*/
|
||||
async function getCommitDiff(
|
||||
projectId: string,
|
||||
sha: string
|
||||
): Promise<GitLabMergeRequestDiff[]> {
|
||||
projectId = decodeURIComponent(projectId);
|
||||
const url = new URL(
|
||||
`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/repository/commits/${encodeURIComponent(sha)}/diff`
|
||||
);
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
...DEFAULT_FETCH_CONFIG,
|
||||
});
|
||||
|
||||
await handleGitLabError(response);
|
||||
|
||||
const data = await response.json();
|
||||
return z.array(GitLabDiffSchema).parse(data);
|
||||
}
|
||||
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||
// Apply read-only filter first
|
||||
const tools0 = GITLAB_READ_ONLY_MODE
|
||||
@ -3762,8 +3857,8 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
||||
}
|
||||
|
||||
case "get_pipeline_job_output": {
|
||||
const { project_id, job_id, limit, offset } = GetPipelineJobOutputSchema.parse(request.params.arguments);
|
||||
const jobOutput = await getPipelineJobOutput(project_id, job_id, limit, offset);
|
||||
const { project_id, job_id } = GetPipelineJobOutputSchema.parse(request.params.arguments);
|
||||
const jobOutput = await getPipelineJobOutput(project_id, job_id);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
@ -3963,6 +4058,30 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
||||
};
|
||||
}
|
||||
|
||||
case "list_commits": {
|
||||
const args = ListCommitsSchema.parse(request.params.arguments);
|
||||
const commits = await listCommits(args.project_id, args);
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(commits, null, 2) }],
|
||||
};
|
||||
}
|
||||
|
||||
case "get_commit": {
|
||||
const args = GetCommitSchema.parse(request.params.arguments);
|
||||
const commit = await getCommit(args.project_id, args.sha, args.stats);
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(commit, null, 2) }],
|
||||
};
|
||||
}
|
||||
|
||||
case "get_commit_diff": {
|
||||
const args = GetCommitDiffSchema.parse(request.params.arguments);
|
||||
const diff = await getCommitDiff(args.project_id, args.sha);
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(diff, null, 2) }],
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown tool: ${request.params.name}`);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zereight/mcp-gitlab",
|
||||
"version": "1.0.63",
|
||||
"version": "1.0.62",
|
||||
"description": "MCP server for using the GitLab API",
|
||||
"license": "MIT",
|
||||
"author": "zereight",
|
||||
|
42
schemas.ts
42
schemas.ts
@ -191,8 +191,6 @@ export const CancelPipelineSchema = z.object({
|
||||
export const GetPipelineJobOutputSchema = z.object({
|
||||
project_id: z.string().describe("Project ID or URL-encoded path"),
|
||||
job_id: z.number().describe("The ID of the job"),
|
||||
limit: z.number().optional().describe("Maximum number of lines to return from the end of the log (default: 1000)"),
|
||||
offset: z.number().optional().describe("Number of lines to skip from the end of the log (default: 0)"),
|
||||
});
|
||||
|
||||
// User schemas
|
||||
@ -409,8 +407,17 @@ export const GitLabCommitSchema = z.object({
|
||||
committer_name: z.string(),
|
||||
committer_email: z.string(),
|
||||
committed_date: z.string(),
|
||||
created_at: z.string().optional(), // Add created_at field
|
||||
message: z.string().optional(), // Add full message field
|
||||
web_url: z.string(), // Changed from html_url to match GitLab API
|
||||
parent_ids: z.array(z.string()), // Changed from parents to match GitLab API
|
||||
stats: z.object({
|
||||
additions: z.number().optional().nullable(),
|
||||
deletions: z.number().optional().nullable(),
|
||||
total: z.number().optional().nullable(),
|
||||
}).optional(), // Only present when with_stats=true
|
||||
trailers: z.record(z.string()).optional().default({}), // Git trailers, may be empty object
|
||||
extended_trailers: z.record(z.array(z.string())).optional().default({}), // Extended trailers, may be empty object
|
||||
});
|
||||
|
||||
// Reference schema
|
||||
@ -1330,6 +1337,34 @@ export const PromoteProjectMilestoneSchema = GetProjectMilestoneSchema;
|
||||
// Schema for getting burndown chart events for a milestone
|
||||
export const GetMilestoneBurndownEventsSchema = GetProjectMilestoneSchema.merge(PaginationOptionsSchema);
|
||||
|
||||
// Add schemas for commit operations
|
||||
export const ListCommitsSchema = z.object({
|
||||
project_id: z.string().describe("Project ID or complete URL-encoded path to project"),
|
||||
ref_name: z.string().optional().describe("The name of a repository branch, tag or revision range, or if not given the default branch"),
|
||||
since: z.string().optional().describe("Only commits after or on this date are returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ"),
|
||||
until: z.string().optional().describe("Only commits before or on this date are returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ"),
|
||||
path: z.string().optional().describe("The file path"),
|
||||
author: z.string().optional().describe("Search commits by commit author"),
|
||||
all: z.boolean().optional().describe("Retrieve every commit from the repository"),
|
||||
with_stats: z.boolean().optional().describe("Stats about each commit are added to the response"),
|
||||
first_parent: z.boolean().optional().describe("Follow only the first parent commit upon seeing a merge commit"),
|
||||
order: z.enum(["default", "topo"]).optional().describe("List commits in order"),
|
||||
trailers: z.boolean().optional().describe("Parse and include Git trailers for every commit"),
|
||||
page: z.number().optional().describe("Page number for pagination (default: 1)"),
|
||||
per_page: z.number().optional().describe("Number of items per page (max: 100, default: 20)"),
|
||||
});
|
||||
|
||||
export const GetCommitSchema = z.object({
|
||||
project_id: z.string().describe("Project ID or complete URL-encoded path to project"),
|
||||
sha: z.string().describe("The commit hash or name of a repository branch or tag"),
|
||||
stats: z.boolean().optional().describe("Include commit stats"),
|
||||
});
|
||||
|
||||
export const GetCommitDiffSchema = z.object({
|
||||
project_id: z.string().describe("Project ID or complete URL-encoded path to project"),
|
||||
sha: z.string().describe("The commit hash or name of a repository branch or tag"),
|
||||
});
|
||||
|
||||
// Export types
|
||||
export type GitLabAuthor = z.infer<typeof GitLabAuthorSchema>;
|
||||
export type GitLabFork = z.infer<typeof GitLabForkSchema>;
|
||||
@ -1396,3 +1431,6 @@ export type GetMilestoneBurndownEventsOptions = z.infer<typeof GetMilestoneBurnd
|
||||
export type GitLabUser = z.infer<typeof GitLabUserSchema>;
|
||||
export type GitLabUsersResponse = z.infer<typeof GitLabUsersResponseSchema>;
|
||||
export type PaginationOptions = z.infer<typeof PaginationOptionsSchema>;
|
||||
export type ListCommitsOptions = z.infer<typeof ListCommitsSchema>;
|
||||
export type GetCommitOptions = z.infer<typeof GetCommitSchema>;
|
||||
export type GetCommitDiffOptions = z.infer<typeof GetCommitDiffSchema>;
|
||||
|
Reference in New Issue
Block a user