Add support for retrieving wiki page content in list_wiki_pages (#82)
Co-authored-by: Vince Liao <vince.liao@nextbank.com.tw>
This commit is contained in:
11
index.ts
11
index.ts
@ -171,6 +171,7 @@ import {
|
|||||||
GitLabCompareResult,
|
GitLabCompareResult,
|
||||||
GitLabCompareResultSchema,
|
GitLabCompareResultSchema,
|
||||||
GetBranchDiffsSchema,
|
GetBranchDiffsSchema,
|
||||||
|
ListWikiPagesOptions,
|
||||||
} from "./schemas.js";
|
} from "./schemas.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2376,12 +2377,14 @@ async function listGroupProjects(
|
|||||||
*/
|
*/
|
||||||
async function listWikiPages(
|
async function listWikiPages(
|
||||||
projectId: string,
|
projectId: string,
|
||||||
options: Omit<z.infer<typeof ListWikiPagesSchema>, "project_id"> = {}
|
options: Omit<ListWikiPagesOptions, "project_id"> = {}
|
||||||
): Promise<GitLabWikiPage[]> {
|
): Promise<GitLabWikiPage[]> {
|
||||||
projectId = decodeURIComponent(projectId); // Decode project ID
|
projectId = decodeURIComponent(projectId); // Decode project ID
|
||||||
const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/wikis`);
|
const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/wikis`);
|
||||||
if (options.page) url.searchParams.append("page", options.page.toString());
|
if (options.page) url.searchParams.append("page", options.page.toString());
|
||||||
if (options.per_page) url.searchParams.append("per_page", options.per_page.toString());
|
if (options.per_page) url.searchParams.append("per_page", options.per_page.toString());
|
||||||
|
if (options.with_content)
|
||||||
|
url.searchParams.append("with_content", options.with_content.toString());
|
||||||
const response = await fetch(url.toString(), {
|
const response = await fetch(url.toString(), {
|
||||||
...DEFAULT_FETCH_CONFIG,
|
...DEFAULT_FETCH_CONFIG,
|
||||||
});
|
});
|
||||||
@ -3597,8 +3600,10 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "list_wiki_pages": {
|
case "list_wiki_pages": {
|
||||||
const { project_id, page, per_page } = ListWikiPagesSchema.parse(request.params.arguments);
|
const { project_id, page, per_page, with_content } = ListWikiPagesSchema.parse(
|
||||||
const wikiPages = await listWikiPages(project_id, { page, per_page });
|
request.params.arguments
|
||||||
|
);
|
||||||
|
const wikiPages = await listWikiPages(project_id, { page, per_page, with_content });
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: JSON.stringify(wikiPages, null, 2) }],
|
content: [{ type: "text", text: JSON.stringify(wikiPages, null, 2) }],
|
||||||
};
|
};
|
||||||
|
@ -1197,7 +1197,9 @@ export const ListGroupProjectsSchema = z.object({
|
|||||||
// Add wiki operation schemas
|
// Add wiki operation schemas
|
||||||
export const ListWikiPagesSchema = z.object({
|
export const ListWikiPagesSchema = z.object({
|
||||||
project_id: z.string().describe("Project ID or URL-encoded path"),
|
project_id: z.string().describe("Project ID or URL-encoded path"),
|
||||||
|
with_content: z.boolean().optional().describe("Include content of the wiki pages"),
|
||||||
}).merge(PaginationOptionsSchema);
|
}).merge(PaginationOptionsSchema);
|
||||||
|
|
||||||
export const GetWikiPageSchema = z.object({
|
export const GetWikiPageSchema = z.object({
|
||||||
project_id: z.string().describe("Project ID or URL-encoded path"),
|
project_id: z.string().describe("Project ID or URL-encoded path"),
|
||||||
slug: z.string().describe("URL-encoded slug of the wiki page"),
|
slug: z.string().describe("URL-encoded slug of the wiki page"),
|
||||||
@ -1226,7 +1228,7 @@ export const GitLabWikiPageSchema = z.object({
|
|||||||
title: z.string(),
|
title: z.string(),
|
||||||
slug: z.string(),
|
slug: z.string(),
|
||||||
format: z.string(),
|
format: z.string(),
|
||||||
content: z.string(),
|
content: z.string().optional(),
|
||||||
created_at: z.string().optional(),
|
created_at: z.string().optional(),
|
||||||
updated_at: z.string().optional(),
|
updated_at: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user