Add create_repo tool to MCP server
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,7 @@ The scripts in this repo should collectively cover:
|
||||
|
||||
| Tool | Description |
|
||||
|---|---|
|
||||
| `create_repo` | Create a new repository |
|
||||
| `list_repos` | List repos accessible to the agent account |
|
||||
| `view_repo` | File list, default branch, README excerpt |
|
||||
| `view_file` | Raw content of a file at a given branch/path |
|
||||
|
||||
25
lib/gitea.ts
25
lib/gitea.ts
@@ -38,6 +38,31 @@ export interface PRDetails {
|
||||
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
|
||||
export async function listRepos({ page }: Session): Promise<Repo[]> {
|
||||
await page.goto(`${GITEA_URL}/${USERNAME}`, { waitUntil: 'load' });
|
||||
|
||||
16
server.ts
16
server.ts
@@ -19,6 +19,19 @@ async function withSession<T>(fn: (session: Session) => Promise<T>): Promise<T>
|
||||
}
|
||||
|
||||
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',
|
||||
description: 'List repositories accessible to the Gitea agent account.',
|
||||
@@ -144,6 +157,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
let result: unknown;
|
||||
|
||||
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':
|
||||
result = await withSession(s => gitea.listRepos(s));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user