upload_project_wiki_attachment
Upload files as attachments to a GitLab project wiki by specifying the branch, file path, project ID, and content. Simplify documentation and resource management directly within the wiki.
Instructions
Upload an attachment to a GitLab project wiki
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | ||
| content | No | ||
| file_path | No | ||
| project_id | No |
Input Schema (JSON Schema)
{
"properties": {
"branch": {
"type": "string"
},
"content": {
"type": "string"
},
"file_path": {
"type": "string"
},
"project_id": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/gitlab-api.ts:1043-1085 (handler)Core handler function that performs the actual upload of wiki attachment to GitLab project wiki using the GitLab API.async uploadProjectWikiAttachment( projectId: string, options: { file_path: string; content: string; branch?: string; } ): Promise<GitLabWikiAttachment> { // Convert content to base64 if it's not already const content = options.content.startsWith("data:") ? options.content : `data:application/octet-stream;base64,${Buffer.from(options.content).toString('base64')}`; const response = await fetch( `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/wikis/attachments`, { method: "POST", headers: { Authorization: `Bearer ${this.token}`, "Content-Type": "application/json", }, body: JSON.stringify({ file_name: options.file_path.split('/').pop(), file_path: options.file_path, content: content, branch: options.branch, }), } ); if (!response.ok) { throw new McpError( ErrorCode.InternalError, `GitLab API error: ${response.statusText}` ); } // Parse the response JSON const attachment = await response.json(); // Validate and return the response return GitLabWikiAttachmentSchema.parse(attachment); }
- src/index.ts:609-617 (handler)MCP server request handler that parses input arguments with the schema and delegates to the GitLabApi handler method.case "upload_project_wiki_attachment": { const args = UploadProjectWikiAttachmentSchema.parse(request.params.arguments); const attachment = await gitlabApi.uploadProjectWikiAttachment(args.project_id, { file_path: args.file_path, content: args.content, branch: args.branch }); return formatWikiAttachmentResponse(attachment); }
- src/schemas.ts:553-558 (schema)Zod schema defining the input validation for the upload_project_wiki_attachment tool: project_id, file_path, content, optional branch.export const UploadProjectWikiAttachmentSchema = z.object({ project_id: z.string(), file_path: z.string(), content: z.string(), branch: z.string().optional() });
- src/index.ts:223-228 (registration)Tool registration in the ALL_TOOLS array, defining name, description, input schema, and read-only status for the MCP server.{ name: "upload_project_wiki_attachment", description: "Upload an attachment to a GitLab project wiki", inputSchema: createJsonSchema(UploadProjectWikiAttachmentSchema), readOnly: false },