feat: initialize BetterNews MCP server with core functionality

- Add .gitignore to exclude node_modules, dist, and .env files
- Create README.md with setup instructions and API key information
- Add package.json with dependencies, scripts, and project metadata
- Implement BetterNewsClient for API interactions
- Set up index.ts to initialize MCP server and register tools
- Create tools for managing news, comments, sources, users, moderation, and tickets
- Add TypeScript configuration for project compilation
This commit is contained in:
Space-Banane
2026-06-17 21:30:52 +02:00
commit 6c0a079808
13 changed files with 1005 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import type { BetterNewsClient } from "../client.js";
export function registerCommentTools(server: McpServer, client: BetterNewsClient) {
server.tool(
"list_comments",
"List comments on a news item. Moderators also see hidden comments. Requires news:read scope.",
{
newsItemId: z.string().uuid().describe("News item UUID"),
page: z.number().int().positive().optional().describe("Page number (default 1)"),
limit: z.number().int().min(1).max(100).optional().describe("Items per page (default 20)"),
},
async ({ newsItemId, page, limit }) => {
const data = await client.get<unknown>(`/api/news/${newsItemId}/comments`, { page, limit });
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
},
);
server.tool(
"create_comment",
"Post a comment on a published news item. Requires news:comment scope.",
{
newsItemId: z.string().uuid().describe("News item UUID"),
content: z.string().min(1).max(2000).describe("Comment text"),
},
async ({ newsItemId, content }) => {
const data = await client.post<unknown>(`/api/news/${newsItemId}/comments`, { content });
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
},
);
server.tool(
"delete_comment",
"Delete a comment. Owners can delete their own; Mod/Admin can delete any. Requires news:comment scope.",
{
newsItemId: z.string().uuid().describe("News item UUID"),
commentId: z.string().uuid().describe("Comment UUID"),
},
async ({ newsItemId, commentId }) => {
const data = await client.delete<unknown>(`/api/news/${newsItemId}/comments/${commentId}`);
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
},
);
}