Add create_repo tool to MCP server

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
agent
2026-03-24 09:23:22 -04:00
parent 9132394fd5
commit 634bf3353f
3 changed files with 42 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ The scripts in this repo should collectively cover:
| Tool | Description | | Tool | Description |
|---|---| |---|---|
| `create_repo` | Create a new repository |
| `list_repos` | List repos accessible to the agent account | | `list_repos` | List repos accessible to the agent account |
| `view_repo` | File list, default branch, README excerpt | | `view_repo` | File list, default branch, README excerpt |
| `view_file` | Raw content of a file at a given branch/path | | `view_file` | Raw content of a file at a given branch/path |

View File

@@ -38,6 +38,31 @@ export interface PRDetails {
isMerged: boolean; isMerged: boolean;
} }
// Create a new repository
export async function createRepo(
{ page }: Session,
name: string,
description = '',
isPrivate = false,
): Promise<{ url: string; cloneUrl: string }> {
await page.goto(`${GITEA_URL}/repo/create`, { waitUntil: 'load' });
await page.fill('input[name="repo_name"]', name);
if (description) await page.fill('textarea[name="description"]', description);
if (isPrivate) await page.check('input[name="private"]');
await Promise.all([
page.waitForNavigation({ waitUntil: 'load' }),
page.getByRole('button', { name: 'Create Repository' }).click(),
]);
const cloneUrl =
(await page.locator('#repo-clone-https, input#clone-url').inputValue().catch(() => '')) ||
`${GITEA_URL}/${USERNAME}/${name}.git`;
return { url: page.url(), cloneUrl };
}
// List repos visible to the logged-in user // List repos visible to the logged-in user
export async function listRepos({ page }: Session): Promise<Repo[]> { export async function listRepos({ page }: Session): Promise<Repo[]> {
await page.goto(`${GITEA_URL}/${USERNAME}`, { waitUntil: 'load' }); await page.goto(`${GITEA_URL}/${USERNAME}`, { waitUntil: 'load' });

View File

@@ -19,6 +19,19 @@ async function withSession<T>(fn: (session: Session) => Promise<T>): Promise<T>
} }
const TOOLS = [ const TOOLS = [
{
name: 'create_repo',
description: 'Create a new repository on Gitea.',
inputSchema: {
type: 'object',
required: ['name'],
properties: {
name: { type: 'string', description: 'Repository name' },
description: { type: 'string', description: 'Optional description' },
private: { type: 'boolean', description: 'Make the repo private (default: false)' },
},
},
},
{ {
name: 'list_repos', name: 'list_repos',
description: 'List repositories accessible to the Gitea agent account.', description: 'List repositories accessible to the Gitea agent account.',
@@ -144,6 +157,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
let result: unknown; let result: unknown;
switch (name) { switch (name) {
case 'create_repo':
result = await withSession(s => gitea.createRepo(s, a.name as string, a.description as string | undefined, a.private as boolean | undefined));
break;
case 'list_repos': case 'list_repos':
result = await withSession(s => gitea.listRepos(s)); result = await withSession(s => gitea.listRepos(s));
break; break;