From 4ac78a996cb4ec4e1af161e390de4af4645bca76 Mon Sep 17 00:00:00 2001 From: Raduan77 Date: Thu, 28 Nov 2024 09:51:03 +0100 Subject: [PATCH 01/63] code for search in github --- src/github/index.ts | 558 +++++++++++++++++++++++++--------------- src/github/package.json | 2 + src/github/schemas.ts | 351 ++++++++++++++++++++----- 3 files changed, 639 insertions(+), 272 deletions(-) diff --git a/src/github/index.ts b/src/github/index.ts index 0676a34c..bddd9f46 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -41,19 +41,32 @@ import { CreateIssueSchema, CreatePullRequestSchema, ForkRepositorySchema, - CreateBranchSchema -} from './schemas.js'; -import { z } from 'zod'; -import { zodToJsonSchema } from 'zod-to-json-schema'; + CreateBranchSchema, + SearchCodeSchema, + SearchIssuesSchema, + SearchUsersSchema, + SearchCodeResponseSchema, + SearchIssuesResponseSchema, + SearchUsersResponseSchema, + type SearchCodeResponse, + type SearchIssuesResponse, + type SearchUsersResponse, +} from "./schemas.js"; +import { zodToJsonSchema } from "zod-to-json-schema"; +import { z } from "zod"; +import type { CallToolRequest } from "@modelcontextprotocol/sdk/types.js"; -const server = new Server({ - name: "github-mcp-server", - version: "0.1.0", -}, { - capabilities: { - tools: {} +const server = new Server( + { + name: "github-mcp-server", + version: "0.1.0", + }, + { + capabilities: { + tools: {}, + }, } -}); +); const GITHUB_PERSONAL_ACCESS_TOKEN = process.env.GITHUB_PERSONAL_ACCESS_TOKEN; @@ -67,17 +80,17 @@ async function forkRepository( repo: string, organization?: string ): Promise { - const url = organization + const url = organization ? `https://api.github.com/repos/${owner}/${repo}/forks?organization=${organization}` : `https://api.github.com/repos/${owner}/${repo}/forks`; const response = await fetch(url, { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, }); if (!response.ok) { @@ -93,21 +106,21 @@ async function createBranch( options: z.infer ): Promise { const fullRef = `refs/heads/${options.ref}`; - + const response = await fetch( `https://api.github.com/repos/${owner}/${repo}/git/refs`, { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ ref: fullRef, - sha: options.sha - }) + sha: options.sha, + }), } ); @@ -126,10 +139,10 @@ async function getDefaultBranchSHA( `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/main`, { headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, } ); @@ -138,15 +151,17 @@ async function getDefaultBranchSHA( `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/master`, { headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, } ); if (!masterResponse.ok) { - throw new Error("Could not find default branch (tried 'main' and 'master')"); + throw new Error( + "Could not find default branch (tried 'main' and 'master')" + ); } const data = GitHubReferenceSchema.parse(await masterResponse.json()); @@ -170,10 +185,10 @@ async function getFileContents( const response = await fetch(url, { headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, }); if (!response.ok) { @@ -184,7 +199,7 @@ async function getFileContents( // If it's a file, decode the content if (!Array.isArray(data) && data.content) { - data.content = Buffer.from(data.content, 'base64').toString('utf8'); + data.content = Buffer.from(data.content, "base64").toString("utf8"); } return data; @@ -200,12 +215,12 @@ async function createIssue( { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, - body: JSON.stringify(options) + body: JSON.stringify(options), } ); @@ -226,12 +241,12 @@ async function createPullRequest( { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, - body: JSON.stringify(options) + body: JSON.stringify(options), } ); @@ -251,7 +266,7 @@ async function createOrUpdateFile( branch: string, sha?: string ): Promise { - const encodedContent = Buffer.from(content).toString('base64'); + const encodedContent = Buffer.from(content).toString("base64"); let currentSha = sha; if (!currentSha) { @@ -261,28 +276,30 @@ async function createOrUpdateFile( currentSha = existingFile.sha; } } catch (error) { - console.error('Note: File does not exist in branch, will create new file'); + console.error( + "Note: File does not exist in branch, will create new file" + ); } } const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`; - + const body = { message, content: encodedContent, branch, - ...(currentSha ? { sha: currentSha } : {}) + ...(currentSha ? { sha: currentSha } : {}), }; const response = await fetch(url, { method: "PUT", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, - body: JSON.stringify(body) + body: JSON.stringify(body), }); if (!response.ok) { @@ -298,11 +315,11 @@ async function createTree( files: FileOperation[], baseTree?: string ): Promise { - const tree = files.map(file => ({ + const tree = files.map((file) => ({ path: file.path, - mode: '100644' as const, - type: 'blob' as const, - content: file.content + mode: "100644" as const, + type: "blob" as const, + content: file.content, })); const response = await fetch( @@ -310,15 +327,15 @@ async function createTree( { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ tree, - base_tree: baseTree - }) + base_tree: baseTree, + }), } ); @@ -341,16 +358,16 @@ async function createCommit( { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ message, tree, - parents - }) + parents, + }), } ); @@ -372,15 +389,15 @@ async function updateReference( { method: "PATCH", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ sha, - force: true - }) + force: true, + }), } ); @@ -402,10 +419,10 @@ async function pushFiles( `https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${branch}`, { headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, } ); @@ -417,7 +434,9 @@ async function pushFiles( const commitSha = ref.object.sha; const tree = await createTree(owner, repo, files, commitSha); - const commit = await createCommit(owner, repo, message, tree.sha, [commitSha]); + const commit = await createCommit(owner, repo, message, tree.sha, [ + commitSha, + ]); return await updateReference(owner, repo, `heads/${branch}`, commit.sha); } @@ -433,10 +452,10 @@ async function searchRepositories( const response = await fetch(url.toString(), { headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, }); if (!response.ok) { @@ -452,12 +471,12 @@ async function createRepository( const response = await fetch("https://api.github.com/user/repos", { method: "POST", headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", "User-Agent": "github-mcp-server", - "Content-Type": "application/json" + "Content-Type": "application/json", }, - body: JSON.stringify(options) + body: JSON.stringify(options), }); if (!response.ok) { @@ -467,172 +486,307 @@ async function createRepository( return GitHubRepositorySchema.parse(await response.json()); } +async function searchCode( + params: z.infer +): Promise { + const url = new URL("https://api.github.com/search/code"); + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + url.searchParams.append(key, value.toString()); + } + }); + + const response = await fetch(url.toString(), { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + }); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return SearchCodeResponseSchema.parse(await response.json()); +} + +async function searchIssues( + params: z.infer +): Promise { + const url = new URL("https://api.github.com/search/issues"); + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + url.searchParams.append(key, value.toString()); + } + }); + + const response = await fetch(url.toString(), { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + }); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return SearchIssuesResponseSchema.parse(await response.json()); +} + +async function searchUsers( + params: z.infer +): Promise { + const url = new URL("https://api.github.com/search/users"); + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + url.searchParams.append(key, value.toString()); + } + }); + + const response = await fetch(url.toString(), { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + }); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return SearchUsersResponseSchema.parse(await response.json()); +} + server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "create_or_update_file", description: "Create or update a single file in a GitHub repository", - inputSchema: zodToJsonSchema(CreateOrUpdateFileSchema) + inputSchema: zodToJsonSchema(CreateOrUpdateFileSchema), }, { name: "search_repositories", description: "Search for GitHub repositories", - inputSchema: zodToJsonSchema(SearchRepositoriesSchema) + inputSchema: zodToJsonSchema(SearchRepositoriesSchema), }, { name: "create_repository", description: "Create a new GitHub repository in your account", - inputSchema: zodToJsonSchema(CreateRepositorySchema) + inputSchema: zodToJsonSchema(CreateRepositorySchema), }, { name: "get_file_contents", - description: "Get the contents of a file or directory from a GitHub repository", - inputSchema: zodToJsonSchema(GetFileContentsSchema) + description: + "Get the contents of a file or directory from a GitHub repository", + inputSchema: zodToJsonSchema(GetFileContentsSchema), }, { name: "push_files", - description: "Push multiple files to a GitHub repository in a single commit", - inputSchema: zodToJsonSchema(PushFilesSchema) + description: + "Push multiple files to a GitHub repository in a single commit", + inputSchema: zodToJsonSchema(PushFilesSchema), }, { name: "create_issue", description: "Create a new issue in a GitHub repository", - inputSchema: zodToJsonSchema(CreateIssueSchema) + inputSchema: zodToJsonSchema(CreateIssueSchema), }, { name: "create_pull_request", description: "Create a new pull request in a GitHub repository", - inputSchema: zodToJsonSchema(CreatePullRequestSchema) + inputSchema: zodToJsonSchema(CreatePullRequestSchema), }, { name: "fork_repository", - description: "Fork a GitHub repository to your account or specified organization", - inputSchema: zodToJsonSchema(ForkRepositorySchema) + description: + "Fork a GitHub repository to your account or specified organization", + inputSchema: zodToJsonSchema(ForkRepositorySchema), }, { name: "create_branch", description: "Create a new branch in a GitHub repository", - inputSchema: zodToJsonSchema(CreateBranchSchema) - } - ] + inputSchema: zodToJsonSchema(CreateBranchSchema), + }, + { + name: "search_code", + description: "Search for code across GitHub repositories", + inputSchema: zodToJsonSchema(SearchCodeSchema), + }, + { + name: "search_issues", + description: + "Search for issues and pull requests across GitHub repositories", + inputSchema: zodToJsonSchema(SearchIssuesSchema), + }, + { + name: "search_users", + description: "Search for users on GitHub", + inputSchema: zodToJsonSchema(SearchUsersSchema), + }, + ], }; }); -server.setRequestHandler(CallToolRequestSchema, async (request) => { - try { - if (!request.params.arguments) { - throw new Error("Arguments are required"); - } - - switch (request.params.name) { - case "fork_repository": { - const args = ForkRepositorySchema.parse(request.params.arguments); - const fork = await forkRepository(args.owner, args.repo, args.organization); - return { toolResult: fork }; +server.setRequestHandler( + CallToolRequestSchema, + async (request: CallToolRequest) => { + try { + if (!request.params.arguments) { + throw new Error("Arguments are required"); } - case "create_branch": { - const args = CreateBranchSchema.parse(request.params.arguments); - let sha: string; - if (args.from_branch) { - const response = await fetch( - `https://api.github.com/repos/${args.owner}/${args.repo}/git/refs/heads/${args.from_branch}`, - { - headers: { - "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, - "Accept": "application/vnd.github.v3+json", - "User-Agent": "github-mcp-server" - } - } + switch (request.params.name) { + case "fork_repository": { + const args = ForkRepositorySchema.parse(request.params.arguments); + const fork = await forkRepository( + args.owner, + args.repo, + args.organization ); - - if (!response.ok) { - throw new Error(`Source branch '${args.from_branch}' not found`); - } - - const data = GitHubReferenceSchema.parse(await response.json()); - sha = data.object.sha; - } else { - sha = await getDefaultBranchSHA(args.owner, args.repo); + return { toolResult: fork }; } - const branch = await createBranch(args.owner, args.repo, { - ref: args.branch, - sha - }); + case "create_branch": { + const args = CreateBranchSchema.parse(request.params.arguments); + let sha: string; + if (args.from_branch) { + const response = await fetch( + `https://api.github.com/repos/${args.owner}/${args.repo}/git/refs/heads/${args.from_branch}`, + { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + } + ); - return { toolResult: branch }; + if (!response.ok) { + throw new Error(`Source branch '${args.from_branch}' not found`); + } + + const data = GitHubReferenceSchema.parse(await response.json()); + sha = data.object.sha; + } else { + sha = await getDefaultBranchSHA(args.owner, args.repo); + } + + const branch = await createBranch(args.owner, args.repo, { + ref: args.branch, + sha, + }); + + return { toolResult: branch }; + } + + case "search_repositories": { + const args = SearchRepositoriesSchema.parse(request.params.arguments); + const results = await searchRepositories( + args.query, + args.page, + args.perPage + ); + return { toolResult: results }; + } + + case "create_repository": { + const args = CreateRepositorySchema.parse(request.params.arguments); + const repository = await createRepository(args); + return { toolResult: repository }; + } + + case "get_file_contents": { + const args = GetFileContentsSchema.parse(request.params.arguments); + const contents = await getFileContents( + args.owner, + args.repo, + args.path, + args.branch + ); + return { toolResult: contents }; + } + + case "create_or_update_file": { + const args = CreateOrUpdateFileSchema.parse(request.params.arguments); + const result = await createOrUpdateFile( + args.owner, + args.repo, + args.path, + args.content, + args.message, + args.branch, + args.sha + ); + return { toolResult: result }; + } + + case "push_files": { + const args = PushFilesSchema.parse(request.params.arguments); + const result = await pushFiles( + args.owner, + args.repo, + args.branch, + args.files, + args.message + ); + return { toolResult: result }; + } + + case "create_issue": { + const args = CreateIssueSchema.parse(request.params.arguments); + const { owner, repo, ...options } = args; + const issue = await createIssue(owner, repo, options); + return { toolResult: issue }; + } + + case "create_pull_request": { + const args = CreatePullRequestSchema.parse(request.params.arguments); + const { owner, repo, ...options } = args; + const pullRequest = await createPullRequest(owner, repo, options); + return { toolResult: pullRequest }; + } + + case "search_code": { + const args = SearchCodeSchema.parse(request.params.arguments); + const results = await searchCode(args); + return { toolResult: results }; + } + + case "search_issues": { + const args = SearchIssuesSchema.parse(request.params.arguments); + const results = await searchIssues(args); + return { toolResult: results }; + } + + case "search_users": { + const args = SearchUsersSchema.parse(request.params.arguments); + const results = await searchUsers(args); + return { toolResult: results }; + } + + default: + throw new Error(`Unknown tool: ${request.params.name}`); } - - case "search_repositories": { - const args = SearchRepositoriesSchema.parse(request.params.arguments); - const results = await searchRepositories(args.query, args.page, args.perPage); - return { toolResult: results }; - } - - case "create_repository": { - const args = CreateRepositorySchema.parse(request.params.arguments); - const repository = await createRepository(args); - return { toolResult: repository }; - } - - case "get_file_contents": { - const args = GetFileContentsSchema.parse(request.params.arguments); - const contents = await getFileContents(args.owner, args.repo, args.path, args.branch); - return { toolResult: contents }; - } - - case "create_or_update_file": { - const args = CreateOrUpdateFileSchema.parse(request.params.arguments); - const result = await createOrUpdateFile( - args.owner, - args.repo, - args.path, - args.content, - args.message, - args.branch, - args.sha + } catch (error) { + if (error instanceof z.ZodError) { + throw new Error( + `Invalid arguments: ${error.errors + .map( + (e: z.ZodError["errors"][number]) => + `${e.path.join(".")}: ${e.message}` + ) + .join(", ")}` ); - return { toolResult: result }; } - - case "push_files": { - const args = PushFilesSchema.parse(request.params.arguments); - const result = await pushFiles( - args.owner, - args.repo, - args.branch, - args.files, - args.message - ); - return { toolResult: result }; - } - - case "create_issue": { - const args = CreateIssueSchema.parse(request.params.arguments); - const { owner, repo, ...options } = args; - const issue = await createIssue(owner, repo, options); - return { toolResult: issue }; - } - - case "create_pull_request": { - const args = CreatePullRequestSchema.parse(request.params.arguments); - const { owner, repo, ...options } = args; - const pullRequest = await createPullRequest(owner, repo, options); - return { toolResult: pullRequest }; - } - - default: - throw new Error(`Unknown tool: ${request.params.name}`); + throw error; } - } catch (error) { - if (error instanceof z.ZodError) { - throw new Error(`Invalid arguments: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`); - } - throw error; } -}); +); async function runServer() { const transport = new StdioServerTransport(); @@ -643,4 +797,4 @@ async function runServer() { runServer().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); -}); \ No newline at end of file +}); diff --git a/src/github/package.json b/src/github/package.json index bc7710e4..25c52b72 100644 --- a/src/github/package.json +++ b/src/github/package.json @@ -20,8 +20,10 @@ }, "dependencies": { "@modelcontextprotocol/sdk": "0.6.0", + "@types/node": "^20.11.0", "@types/node-fetch": "^2.6.12", "node-fetch": "^3.3.2", + "zod": "^3.22.4", "zod-to-json-schema": "^3.23.5" }, "devDependencies": { diff --git a/src/github/schemas.ts b/src/github/schemas.ts index 213458eb..7acb0ab4 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -1,10 +1,10 @@ -import { z } from 'zod'; +import { z } from "zod"; // Base schemas for common types export const GitHubAuthorSchema = z.object({ name: z.string(), email: z.string(), - date: z.string() + date: z.string(), }); // Repository related schemas @@ -15,7 +15,7 @@ export const GitHubOwnerSchema = z.object({ avatar_url: z.string(), url: z.string(), html_url: z.string(), - type: z.string() + type: z.string(), }); export const GitHubRepositorySchema = z.object({ @@ -35,7 +35,7 @@ export const GitHubRepositorySchema = z.object({ git_url: z.string(), ssh_url: z.string(), clone_url: z.string(), - default_branch: z.string() + default_branch: z.string(), }); // File content schemas @@ -50,7 +50,7 @@ export const GitHubFileContentSchema = z.object({ url: z.string(), git_url: z.string(), html_url: z.string(), - download_url: z.string() + download_url: z.string(), }); export const GitHubDirectoryContentSchema = z.object({ @@ -62,35 +62,35 @@ export const GitHubDirectoryContentSchema = z.object({ url: z.string(), git_url: z.string(), html_url: z.string(), - download_url: z.string().nullable() + download_url: z.string().nullable(), }); export const GitHubContentSchema = z.union([ GitHubFileContentSchema, - z.array(GitHubDirectoryContentSchema) + z.array(GitHubDirectoryContentSchema), ]); // Operation schemas export const FileOperationSchema = z.object({ path: z.string(), - content: z.string() + content: z.string(), }); // Tree and commit schemas export const GitHubTreeEntrySchema = z.object({ path: z.string(), - mode: z.enum(['100644', '100755', '040000', '160000', '120000']), - type: z.enum(['blob', 'tree', 'commit']), + mode: z.enum(["100644", "100755", "040000", "160000", "120000"]), + type: z.enum(["blob", "tree", "commit"]), size: z.number().optional(), sha: z.string(), - url: z.string() + url: z.string(), }); export const GitHubTreeSchema = z.object({ sha: z.string(), url: z.string(), tree: z.array(GitHubTreeEntrySchema), - truncated: z.boolean() + truncated: z.boolean(), }); export const GitHubCommitSchema = z.object({ @@ -102,12 +102,14 @@ export const GitHubCommitSchema = z.object({ message: z.string(), tree: z.object({ sha: z.string(), - url: z.string() + url: z.string(), }), - parents: z.array(z.object({ - sha: z.string(), - url: z.string() - })) + parents: z.array( + z.object({ + sha: z.string(), + url: z.string(), + }) + ), }); // Reference schema @@ -118,8 +120,8 @@ export const GitHubReferenceSchema = z.object({ object: z.object({ sha: z.string(), type: z.string(), - url: z.string() - }) + url: z.string(), + }), }); // Input schemas for operations @@ -127,7 +129,7 @@ export const CreateRepositoryOptionsSchema = z.object({ name: z.string(), description: z.string().optional(), private: z.boolean().optional(), - auto_init: z.boolean().optional() + auto_init: z.boolean().optional(), }); export const CreateIssueOptionsSchema = z.object({ @@ -135,7 +137,7 @@ export const CreateIssueOptionsSchema = z.object({ body: z.string().optional(), assignees: z.array(z.string()).optional(), milestone: z.number().optional(), - labels: z.array(z.string()).optional() + labels: z.array(z.string()).optional(), }); export const CreatePullRequestOptionsSchema = z.object({ @@ -144,12 +146,12 @@ export const CreatePullRequestOptionsSchema = z.object({ head: z.string(), base: z.string(), maintainer_can_modify: z.boolean().optional(), - draft: z.boolean().optional() + draft: z.boolean().optional(), }); export const CreateBranchOptionsSchema = z.object({ ref: z.string(), - sha: z.string() + sha: z.string(), }); // Response schemas for operations @@ -164,21 +166,23 @@ export const GitHubCreateUpdateFileResponseSchema = z.object({ committer: GitHubAuthorSchema, message: z.string(), tree: z.object({ - sha: z.string(), - url: z.string() - }), - parents: z.array(z.object({ sha: z.string(), url: z.string(), - html_url: z.string() - })) - }) + }), + parents: z.array( + z.object({ + sha: z.string(), + url: z.string(), + html_url: z.string(), + }) + ), + }), }); export const GitHubSearchResponseSchema = z.object({ total_count: z.number(), incomplete_results: z.boolean(), - items: z.array(GitHubRepositorySchema) + items: z.array(GitHubRepositorySchema), }); // Fork related schemas @@ -188,14 +192,14 @@ export const GitHubForkParentSchema = z.object({ owner: z.object({ login: z.string(), id: z.number(), - avatar_url: z.string() + avatar_url: z.string(), }), - html_url: z.string() + html_url: z.string(), }); export const GitHubForkSchema = GitHubRepositorySchema.extend({ parent: GitHubForkParentSchema, - source: GitHubForkParentSchema + source: GitHubForkParentSchema, }); // Issue related schemas @@ -206,7 +210,7 @@ export const GitHubLabelSchema = z.object({ name: z.string(), color: z.string(), default: z.boolean(), - description: z.string().optional() + description: z.string().optional(), }); export const GitHubIssueAssigneeSchema = z.object({ @@ -214,7 +218,7 @@ export const GitHubIssueAssigneeSchema = z.object({ id: z.number(), avatar_url: z.string(), url: z.string(), - html_url: z.string() + html_url: z.string(), }); export const GitHubMilestoneSchema = z.object({ @@ -226,7 +230,7 @@ export const GitHubMilestoneSchema = z.object({ number: z.number(), title: z.string(), description: z.string(), - state: z.string() + state: z.string(), }); export const GitHubIssueSchema = z.object({ @@ -251,7 +255,7 @@ export const GitHubIssueSchema = z.object({ created_at: z.string(), updated_at: z.string(), closed_at: z.string().nullable(), - body: z.string() + body: z.string(), }); // Pull Request related schemas @@ -260,7 +264,7 @@ export const GitHubPullRequestHeadSchema = z.object({ ref: z.string(), sha: z.string(), user: GitHubIssueAssigneeSchema, - repo: GitHubRepositorySchema + repo: GitHubRepositorySchema, }); export const GitHubPullRequestSchema = z.object({ @@ -285,12 +289,12 @@ export const GitHubPullRequestSchema = z.object({ assignee: GitHubIssueAssigneeSchema.nullable(), assignees: z.array(GitHubIssueAssigneeSchema), head: GitHubPullRequestHeadSchema, - base: GitHubPullRequestHeadSchema + base: GitHubPullRequestHeadSchema, }); const RepoParamsSchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), - repo: z.string().describe("Repository name") + repo: z.string().describe("Repository name"), }); export const CreateOrUpdateFileSchema = RepoParamsSchema.extend({ @@ -298,81 +302,288 @@ export const CreateOrUpdateFileSchema = RepoParamsSchema.extend({ content: z.string().describe("Content of the file"), message: z.string().describe("Commit message"), branch: z.string().describe("Branch to create/update the file in"), - sha: z.string().optional() - .describe("SHA of the file being replaced (required when updating existing files)") + sha: z + .string() + .optional() + .describe( + "SHA of the file being replaced (required when updating existing files)" + ), }); export const SearchRepositoriesSchema = z.object({ query: z.string().describe("Search query (see GitHub search syntax)"), - page: z.number().optional().describe("Page number for pagination (default: 1)"), - perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)") + page: z + .number() + .optional() + .describe("Page number for pagination (default: 1)"), + perPage: z + .number() + .optional() + .describe("Number of results per page (default: 30, max: 100)"), }); export const CreateRepositorySchema = z.object({ name: z.string().describe("Repository name"), description: z.string().optional().describe("Repository description"), - private: z.boolean().optional().describe("Whether the repository should be private"), - autoInit: z.boolean().optional().describe("Initialize with README.md") + private: z + .boolean() + .optional() + .describe("Whether the repository should be private"), + autoInit: z.boolean().optional().describe("Initialize with README.md"), }); export const GetFileContentsSchema = RepoParamsSchema.extend({ path: z.string().describe("Path to the file or directory"), - branch: z.string().optional().describe("Branch to get contents from") + branch: z.string().optional().describe("Branch to get contents from"), }); export const PushFilesSchema = RepoParamsSchema.extend({ branch: z.string().describe("Branch to push to (e.g., 'main' or 'master')"), - files: z.array(z.object({ - path: z.string().describe("Path where to create the file"), - content: z.string().describe("Content of the file") - })).describe("Array of files to push"), - message: z.string().describe("Commit message") + files: z + .array( + z.object({ + path: z.string().describe("Path where to create the file"), + content: z.string().describe("Content of the file"), + }) + ) + .describe("Array of files to push"), + message: z.string().describe("Commit message"), }); export const CreateIssueSchema = RepoParamsSchema.extend({ title: z.string().describe("Issue title"), body: z.string().optional().describe("Issue body/description"), - assignees: z.array(z.string()).optional().describe("Array of usernames to assign"), + assignees: z + .array(z.string()) + .optional() + .describe("Array of usernames to assign"), labels: z.array(z.string()).optional().describe("Array of label names"), - milestone: z.number().optional().describe("Milestone number to assign") + milestone: z.number().optional().describe("Milestone number to assign"), }); export const CreatePullRequestSchema = RepoParamsSchema.extend({ title: z.string().describe("Pull request title"), body: z.string().optional().describe("Pull request body/description"), - head: z.string().describe("The name of the branch where your changes are implemented"), - base: z.string().describe("The name of the branch you want the changes pulled into"), - draft: z.boolean().optional().describe("Whether to create the pull request as a draft"), - maintainer_can_modify: z.boolean().optional() - .describe("Whether maintainers can modify the pull request") + head: z + .string() + .describe("The name of the branch where your changes are implemented"), + base: z + .string() + .describe("The name of the branch you want the changes pulled into"), + draft: z + .boolean() + .optional() + .describe("Whether to create the pull request as a draft"), + maintainer_can_modify: z + .boolean() + .optional() + .describe("Whether maintainers can modify the pull request"), }); export const ForkRepositorySchema = RepoParamsSchema.extend({ - organization: z.string().optional() - .describe("Optional: organization to fork to (defaults to your personal account)") + organization: z + .string() + .optional() + .describe( + "Optional: organization to fork to (defaults to your personal account)" + ), }); export const CreateBranchSchema = RepoParamsSchema.extend({ branch: z.string().describe("Name for the new branch"), - from_branch: z.string().optional() - .describe("Optional: source branch to create from (defaults to the repository's default branch)") + from_branch: z + .string() + .optional() + .describe( + "Optional: source branch to create from (defaults to the repository's default branch)" + ), +}); + +// Search Response Schemas +export const SearchCodeItemSchema = z.object({ + name: z.string(), + path: z.string(), + sha: z.string(), + url: z.string(), + git_url: z.string(), + html_url: z.string(), + repository: GitHubRepositorySchema, + score: z.number(), +}); + +export const SearchCodeResponseSchema = z.object({ + total_count: z.number(), + incomplete_results: z.boolean(), + items: z.array(SearchCodeItemSchema), +}); + +export const SearchIssueItemSchema = z.object({ + url: z.string(), + repository_url: z.string(), + labels_url: z.string(), + comments_url: z.string(), + events_url: z.string(), + html_url: z.string(), + id: z.number(), + node_id: z.string(), + number: z.number(), + title: z.string(), + user: GitHubIssueAssigneeSchema, + labels: z.array(GitHubLabelSchema), + state: z.string(), + locked: z.boolean(), + assignee: GitHubIssueAssigneeSchema.nullable(), + assignees: z.array(GitHubIssueAssigneeSchema), + comments: z.number(), + created_at: z.string(), + updated_at: z.string(), + closed_at: z.string().nullable(), + body: z.string(), + score: z.number(), + pull_request: z + .object({ + url: z.string(), + html_url: z.string(), + diff_url: z.string(), + patch_url: z.string(), + }) + .optional(), +}); + +export const SearchIssuesResponseSchema = z.object({ + total_count: z.number(), + incomplete_results: z.boolean(), + items: z.array(SearchIssueItemSchema), +}); + +export const SearchUserItemSchema = z.object({ + login: z.string(), + id: z.number(), + node_id: z.string(), + avatar_url: z.string(), + gravatar_id: z.string(), + url: z.string(), + html_url: z.string(), + followers_url: z.string(), + following_url: z.string(), + gists_url: z.string(), + starred_url: z.string(), + subscriptions_url: z.string(), + organizations_url: z.string(), + repos_url: z.string(), + events_url: z.string(), + received_events_url: z.string(), + type: z.string(), + site_admin: z.boolean(), + score: z.number(), +}); + +export const SearchUsersResponseSchema = z.object({ + total_count: z.number(), + incomplete_results: z.boolean(), + items: z.array(SearchUserItemSchema), +}); + +// Search Input Schemas +export const SearchCodeSchema = z.object({ + q: z.string().describe("Search query (see GitHub code search syntax)"), + sort: z + .enum(["", "indexed"]) + .optional() + .describe("Sort field (only 'indexed' is supported)"), + order: z + .enum(["asc", "desc"]) + .optional() + .describe("Sort order (asc or desc)"), + per_page: z + .number() + .min(1) + .max(100) + .optional() + .describe("Results per page (max 100)"), + page: z.number().min(1).optional().describe("Page number"), +}); + +export const SearchIssuesSchema = z.object({ + q: z.string().describe("Search query (see GitHub issues search syntax)"), + sort: z + .enum([ + "comments", + "reactions", + "reactions-+1", + "reactions--1", + "reactions-smile", + "reactions-thinking_face", + "reactions-heart", + "reactions-tada", + "interactions", + "created", + "updated", + ]) + .optional() + .describe("Sort field"), + order: z + .enum(["asc", "desc"]) + .optional() + .describe("Sort order (asc or desc)"), + per_page: z + .number() + .min(1) + .max(100) + .optional() + .describe("Results per page (max 100)"), + page: z.number().min(1).optional().describe("Page number"), +}); + +export const SearchUsersSchema = z.object({ + q: z.string().describe("Search query (see GitHub users search syntax)"), + sort: z + .enum(["followers", "repositories", "joined"]) + .optional() + .describe("Sort field"), + order: z + .enum(["asc", "desc"]) + .optional() + .describe("Sort order (asc or desc)"), + per_page: z + .number() + .min(1) + .max(100) + .optional() + .describe("Results per page (max 100)"), + page: z.number().min(1).optional().describe("Page number"), }); // Export types export type GitHubAuthor = z.infer; export type GitHubFork = z.infer; export type GitHubIssue = z.infer; -export type GitHubPullRequest = z.infer;export type GitHubRepository = z.infer; +export type GitHubPullRequest = z.infer; +export type GitHubRepository = z.infer; export type GitHubFileContent = z.infer; -export type GitHubDirectoryContent = z.infer; +export type GitHubDirectoryContent = z.infer< + typeof GitHubDirectoryContentSchema +>; export type GitHubContent = z.infer; export type FileOperation = z.infer; export type GitHubTree = z.infer; export type GitHubCommit = z.infer; export type GitHubReference = z.infer; -export type CreateRepositoryOptions = z.infer; +export type CreateRepositoryOptions = z.infer< + typeof CreateRepositoryOptionsSchema +>; export type CreateIssueOptions = z.infer; -export type CreatePullRequestOptions = z.infer; +export type CreatePullRequestOptions = z.infer< + typeof CreatePullRequestOptionsSchema +>; export type CreateBranchOptions = z.infer; -export type GitHubCreateUpdateFileResponse = z.infer; -export type GitHubSearchResponse = z.infer; \ No newline at end of file +export type GitHubCreateUpdateFileResponse = z.infer< + typeof GitHubCreateUpdateFileResponseSchema +>; +export type GitHubSearchResponse = z.infer; +export type SearchCodeItem = z.infer; +export type SearchCodeResponse = z.infer; +export type SearchIssueItem = z.infer; +export type SearchIssuesResponse = z.infer; +export type SearchUserItem = z.infer; +export type SearchUsersResponse = z.infer; From c6a2597fcacead84436c6b4f3f266c13c9a5ff0a Mon Sep 17 00:00:00 2001 From: Raduan77 Date: Thu, 28 Nov 2024 09:54:14 +0100 Subject: [PATCH 02/63] bump docs --- src/github/README.md | 57 ++++++++++- src/github/package.json | 2 +- src/github/schemas.ts | 204 ++++++++++++++++++++++++++-------------- 3 files changed, 192 insertions(+), 71 deletions(-) diff --git a/src/github/README.md b/src/github/README.md index cfd268a8..b5b0bfa6 100644 --- a/src/github/README.md +++ b/src/github/README.md @@ -1,6 +1,6 @@ # GitHub MCP Server -MCP Server for the GitHub API, enabling file operations, repository management, and more. +MCP Server for the GitHub API, enabling file operations, repository management, search functionality, and more. ### Features @@ -8,6 +8,7 @@ MCP Server for the GitHub API, enabling file operations, repository management, - **Comprehensive Error Handling**: Clear error messages for common issues - **Git History Preservation**: Operations maintain proper Git history without force pushing - **Batch Operations**: Support for both single-file and multi-file operations +- **Advanced Search**: Support for searching code, issues/PRs, and users ## Tools @@ -102,6 +103,60 @@ MCP Server for the GitHub API, enabling file operations, repository management, - `from_branch` (optional string): Source branch (defaults to repo default) - Returns: Created branch reference +10. `search_code` + - Search for code across GitHub repositories + - Inputs: + - `q` (string): Search query using GitHub code search syntax + - `sort` (optional string): Sort field ('indexed' only) + - `order` (optional string): Sort order ('asc' or 'desc') + - `per_page` (optional number): Results per page (max 100) + - `page` (optional number): Page number + - Returns: Code search results with repository context + +11. `search_issues` + - Search for issues and pull requests + - Inputs: + - `q` (string): Search query using GitHub issues search syntax + - `sort` (optional string): Sort field (comments, reactions, created, etc.) + - `order` (optional string): Sort order ('asc' or 'desc') + - `per_page` (optional number): Results per page (max 100) + - `page` (optional number): Page number + - Returns: Issue and pull request search results + +12. `search_users` + - Search for GitHub users + - Inputs: + - `q` (string): Search query using GitHub users search syntax + - `sort` (optional string): Sort field (followers, repositories, joined) + - `order` (optional string): Sort order ('asc' or 'desc') + - `per_page` (optional number): Results per page (max 100) + - `page` (optional number): Page number + - Returns: User search results + +## Search Query Syntax + +### Code Search +- `language:javascript`: Search by programming language +- `repo:owner/name`: Search in specific repository +- `path:app/src`: Search in specific path +- `extension:js`: Search by file extension +- Example: `q: "import express" language:typescript path:src/` + +### Issues Search +- `is:issue` or `is:pr`: Filter by type +- `is:open` or `is:closed`: Filter by state +- `label:bug`: Search by label +- `author:username`: Search by author +- Example: `q: "memory leak" is:issue is:open label:bug` + +### Users Search +- `type:user` or `type:org`: Filter by account type +- `followers:>1000`: Filter by followers +- `location:London`: Search by location +- Example: `q: "fullstack developer" location:London followers:>100` + +For detailed search syntax, see [GitHub's searching documentation](https://docs.github.com/en/search-github/searching-on-github). + ## Setup ### Personal Access Token diff --git a/src/github/package.json b/src/github/package.json index 25c52b72..e15e486d 100644 --- a/src/github/package.json +++ b/src/github/package.json @@ -1,6 +1,6 @@ { "name": "@modelcontextprotocol/server-github", - "version": "0.5.1", + "version": "0.6.0", "description": "MCP server for using the GitHub API", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", diff --git a/src/github/schemas.ts b/src/github/schemas.ts index 7acb0ab4..f6b98727 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -399,98 +399,148 @@ export const CreateBranchSchema = RepoParamsSchema.extend({ ), }); -// Search Response Schemas +/** + * Response schema for a code search result item + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-code + */ export const SearchCodeItemSchema = z.object({ - name: z.string(), - path: z.string(), - sha: z.string(), - url: z.string(), - git_url: z.string(), - html_url: z.string(), - repository: GitHubRepositorySchema, - score: z.number(), + name: z.string().describe("The name of the file"), + path: z.string().describe("The path to the file in the repository"), + sha: z.string().describe("The SHA hash of the file"), + url: z.string().describe("The API URL for this file"), + git_url: z.string().describe("The Git URL for this file"), + html_url: z.string().describe("The HTML URL to view this file on GitHub"), + repository: GitHubRepositorySchema.describe( + "The repository where this file was found" + ), + score: z.number().describe("The search result score"), }); +/** + * Response schema for code search results + */ export const SearchCodeResponseSchema = z.object({ - total_count: z.number(), - incomplete_results: z.boolean(), - items: z.array(SearchCodeItemSchema), + total_count: z.number().describe("Total number of matching results"), + incomplete_results: z + .boolean() + .describe("Whether the results are incomplete"), + items: z.array(SearchCodeItemSchema).describe("The search results"), }); +/** + * Response schema for an issue search result item + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests + */ export const SearchIssueItemSchema = z.object({ - url: z.string(), - repository_url: z.string(), - labels_url: z.string(), - comments_url: z.string(), - events_url: z.string(), - html_url: z.string(), - id: z.number(), - node_id: z.string(), - number: z.number(), - title: z.string(), - user: GitHubIssueAssigneeSchema, - labels: z.array(GitHubLabelSchema), - state: z.string(), - locked: z.boolean(), - assignee: GitHubIssueAssigneeSchema.nullable(), - assignees: z.array(GitHubIssueAssigneeSchema), - comments: z.number(), - created_at: z.string(), - updated_at: z.string(), - closed_at: z.string().nullable(), - body: z.string(), - score: z.number(), + url: z.string().describe("The API URL for this issue"), + repository_url: z + .string() + .describe("The API URL for the repository where this issue was found"), + labels_url: z.string().describe("The API URL for the labels of this issue"), + comments_url: z.string().describe("The API URL for comments of this issue"), + events_url: z.string().describe("The API URL for events of this issue"), + html_url: z.string().describe("The HTML URL to view this issue on GitHub"), + id: z.number().describe("The ID of this issue"), + node_id: z.string().describe("The Node ID of this issue"), + number: z.number().describe("The number of this issue"), + title: z.string().describe("The title of this issue"), + user: GitHubIssueAssigneeSchema.describe("The user who created this issue"), + labels: z.array(GitHubLabelSchema).describe("The labels of this issue"), + state: z.string().describe("The state of this issue"), + locked: z.boolean().describe("Whether this issue is locked"), + assignee: GitHubIssueAssigneeSchema.nullable().describe( + "The assignee of this issue" + ), + assignees: z + .array(GitHubIssueAssigneeSchema) + .describe("The assignees of this issue"), + comments: z.number().describe("The number of comments on this issue"), + created_at: z.string().describe("The creation time of this issue"), + updated_at: z.string().describe("The last update time of this issue"), + closed_at: z.string().nullable().describe("The closure time of this issue"), + body: z.string().describe("The body of this issue"), + score: z.number().describe("The search result score"), pull_request: z .object({ - url: z.string(), - html_url: z.string(), - diff_url: z.string(), - patch_url: z.string(), + url: z.string().describe("The API URL for this pull request"), + html_url: z.string().describe("The HTML URL to view this pull request"), + diff_url: z.string().describe("The URL to view the diff"), + patch_url: z.string().describe("The URL to view the patch"), }) - .optional(), + .optional() + .describe("Pull request details if this is a PR"), }); +/** + * Response schema for issue search results + */ export const SearchIssuesResponseSchema = z.object({ - total_count: z.number(), - incomplete_results: z.boolean(), - items: z.array(SearchIssueItemSchema), + total_count: z.number().describe("Total number of matching results"), + incomplete_results: z + .boolean() + .describe("Whether the results are incomplete"), + items: z.array(SearchIssueItemSchema).describe("The search results"), }); +/** + * Response schema for a user search result item + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-users + */ export const SearchUserItemSchema = z.object({ - login: z.string(), - id: z.number(), - node_id: z.string(), - avatar_url: z.string(), - gravatar_id: z.string(), - url: z.string(), - html_url: z.string(), - followers_url: z.string(), - following_url: z.string(), - gists_url: z.string(), - starred_url: z.string(), - subscriptions_url: z.string(), - organizations_url: z.string(), - repos_url: z.string(), - events_url: z.string(), - received_events_url: z.string(), - type: z.string(), - site_admin: z.boolean(), - score: z.number(), + login: z.string().describe("The username of the user"), + id: z.number().describe("The ID of the user"), + node_id: z.string().describe("The Node ID of the user"), + avatar_url: z.string().describe("The avatar URL of the user"), + gravatar_id: z.string().describe("The Gravatar ID of the user"), + url: z.string().describe("The API URL for this user"), + html_url: z.string().describe("The HTML URL to view this user on GitHub"), + followers_url: z.string().describe("The API URL for followers of this user"), + following_url: z.string().describe("The API URL for following of this user"), + gists_url: z.string().describe("The API URL for gists of this user"), + starred_url: z + .string() + .describe("The API URL for starred repositories of this user"), + subscriptions_url: z + .string() + .describe("The API URL for subscriptions of this user"), + organizations_url: z + .string() + .describe("The API URL for organizations of this user"), + repos_url: z.string().describe("The API URL for repositories of this user"), + events_url: z.string().describe("The API URL for events of this user"), + received_events_url: z + .string() + .describe("The API URL for received events of this user"), + type: z.string().describe("The type of this user"), + site_admin: z.boolean().describe("Whether this user is a site administrator"), + score: z.number().describe("The search result score"), }); +/** + * Response schema for user search results + */ export const SearchUsersResponseSchema = z.object({ - total_count: z.number(), - incomplete_results: z.boolean(), - items: z.array(SearchUserItemSchema), + total_count: z.number().describe("Total number of matching results"), + incomplete_results: z + .boolean() + .describe("Whether the results are incomplete"), + items: z.array(SearchUserItemSchema).describe("The search results"), }); -// Search Input Schemas +/** + * Input schema for code search + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-code--parameters + */ export const SearchCodeSchema = z.object({ - q: z.string().describe("Search query (see GitHub code search syntax)"), + q: z + .string() + .describe( + "Search query. See GitHub code search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code" + ), sort: z .enum(["", "indexed"]) .optional() - .describe("Sort field (only 'indexed' is supported)"), + .describe("Sort field. Only 'indexed' is supported"), order: z .enum(["asc", "desc"]) .optional() @@ -504,8 +554,16 @@ export const SearchCodeSchema = z.object({ page: z.number().min(1).optional().describe("Page number"), }); +/** + * Input schema for issues search + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests--parameters + */ export const SearchIssuesSchema = z.object({ - q: z.string().describe("Search query (see GitHub issues search syntax)"), + q: z + .string() + .describe( + "Search query. See GitHub issues search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests" + ), sort: z .enum([ "comments", @@ -535,8 +593,16 @@ export const SearchIssuesSchema = z.object({ page: z.number().min(1).optional().describe("Page number"), }); +/** + * Input schema for users search + * @see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-users--parameters + */ export const SearchUsersSchema = z.object({ - q: z.string().describe("Search query (see GitHub users search syntax)"), + q: z + .string() + .describe( + "Search query. See GitHub users search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-users" + ), sort: z .enum(["followers", "repositories", "joined"]) .optional() From 08015830a68f4dfa2cc56e40cdd82538ea85322c Mon Sep 17 00:00:00 2001 From: Jerad Bitner Date: Thu, 28 Nov 2024 13:59:37 -0800 Subject: [PATCH 03/63] feat: add issue management functionalities for github - Implemented `listIssues`, `updateIssue`, and `addIssueComment` functions to manage GitHub issues. - Introduced corresponding schemas: `ListIssuesOptionsSchema`, `UpdateIssueOptionsSchema`, and `IssueCommentSchema`. - Updated server request handlers to support new functionalities. - Enhanced README with documentation for new features. --- src/github/README.md | 37 ++++++++++++ src/github/index.ts | 133 +++++++++++++++++++++++++++++++++++++++++- src/github/schemas.ts | 33 +++++++++++ 3 files changed, 202 insertions(+), 1 deletion(-) diff --git a/src/github/README.md b/src/github/README.md index cfd268a8..a3ce0a13 100644 --- a/src/github/README.md +++ b/src/github/README.md @@ -102,6 +102,43 @@ MCP Server for the GitHub API, enabling file operations, repository management, - `from_branch` (optional string): Source branch (defaults to repo default) - Returns: Created branch reference +10. `list_issues` + - List and filter repository issues + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `state` (optional string): Filter by state ('open', 'closed', 'all') + - `labels` (optional string[]): Filter by labels + - `sort` (optional string): Sort by ('created', 'updated', 'comments') + - `direction` (optional string): Sort direction ('asc', 'desc') + - `since` (optional string): Filter by date (ISO 8601 timestamp) + - `page` (optional number): Page number + - `per_page` (optional number): Results per page + - Returns: Array of issue details + +11. `update_issue` + - Update an existing issue + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `issue_number` (number): Issue number to update + - `title` (optional string): New title + - `body` (optional string): New description + - `state` (optional string): New state ('open' or 'closed') + - `labels` (optional string[]): New labels + - `assignees` (optional string[]): New assignees + - `milestone` (optional number): New milestone number + - Returns: Updated issue details + +12. `add_issue_comment` + - Add a comment to an issue + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `issue_number` (number): Issue number to comment on + - `body` (string): Comment text + - Returns: Created comment details + ## Setup ### Personal Access Token diff --git a/src/github/index.ts b/src/github/index.ts index 0676a34c..ab691e38 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -41,7 +41,10 @@ import { CreateIssueSchema, CreatePullRequestSchema, ForkRepositorySchema, - CreateBranchSchema + CreateBranchSchema, + ListIssuesOptionsSchema, + UpdateIssueOptionsSchema, + IssueCommentSchema } from './schemas.js'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; @@ -467,6 +470,98 @@ async function createRepository( return GitHubRepositorySchema.parse(await response.json()); } +async function listIssues( + owner: string, + repo: string, + options: z.infer +): Promise { + const url = new URL(`https://api.github.com/repos/${owner}/${repo}/issues`); + + // Add query parameters + if (options.state) url.searchParams.append('state', options.state); + if (options.labels) url.searchParams.append('labels', options.labels.join(',')); + if (options.sort) url.searchParams.append('sort', options.sort); + if (options.direction) url.searchParams.append('direction', options.direction); + if (options.since) url.searchParams.append('since', options.since); + if (options.page) url.searchParams.append('page', options.page.toString()); + if (options.per_page) url.searchParams.append('per_page', options.per_page.toString()); + + const response = await fetch(url.toString(), { + headers: { + "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + "Accept": "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server" + } + }); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return z.array(GitHubIssueSchema).parse(await response.json()); +} + +async function updateIssue( + owner: string, + repo: string, + issueNumber: number, + options: z.infer +): Promise { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`, + { + method: "PATCH", + headers: { + "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + "Accept": "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + "Content-Type": "application/json" + }, + body: JSON.stringify({ + title: options.title, + body: options.body, + state: options.state, + labels: options.labels, + assignees: options.assignees, + milestone: options.milestone + }) + } + ); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return GitHubIssueSchema.parse(await response.json()); +} + +async function addIssueComment( + owner: string, + repo: string, + issueNumber: number, + body: string +): Promise> { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}/comments`, + { + method: "POST", + headers: { + "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + "Accept": "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + "Content-Type": "application/json" + }, + body: JSON.stringify({ body }) + } + ); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return IssueCommentSchema.parse(await response.json()); +} + server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ @@ -514,6 +609,21 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { name: "create_branch", description: "Create a new branch in a GitHub repository", inputSchema: zodToJsonSchema(CreateBranchSchema) + }, + { + name: "list_issues", + description: "List issues in a GitHub repository with filtering options", + inputSchema: zodToJsonSchema(ListIssuesOptionsSchema) + }, + { + name: "update_issue", + description: "Update an existing issue in a GitHub repository", + inputSchema: zodToJsonSchema(UpdateIssueOptionsSchema) + }, + { + name: "add_issue_comment", + description: "Add a comment to an existing issue", + inputSchema: zodToJsonSchema(IssueCommentSchema) } ] }; @@ -623,6 +733,27 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { toolResult: pullRequest }; } + case "list_issues": { + const args = ListIssuesOptionsSchema.parse(request.params.arguments); + const { owner, repo, ...options } = args; + const issues = await listIssues(owner, repo, options); + return { toolResult: issues }; + } + + case "update_issue": { + const args = UpdateIssueOptionsSchema.parse(request.params.arguments); + const { owner, repo, issue_number, ...options } = args; + const issue = await updateIssue(owner, repo, issue_number, options); + return { toolResult: issue }; + } + + case "add_issue_comment": { + const args = IssueCommentSchema.parse(request.params.arguments); + const { owner, repo, issue_number, body } = args; + const comment = await addIssueComment(owner, repo, issue_number, body); + return { toolResult: comment }; + } + default: throw new Error(`Unknown tool: ${request.params.name}`); } diff --git a/src/github/schemas.ts b/src/github/schemas.ts index 213458eb..e57ea6d9 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -358,6 +358,39 @@ export const CreateBranchSchema = RepoParamsSchema.extend({ .describe("Optional: source branch to create from (defaults to the repository's default branch)") }); +// Add these schema definitions for issue management + +export const ListIssuesOptionsSchema = z.object({ + owner: z.string(), + repo: z.string(), + state: z.enum(['open', 'closed', 'all']).optional(), + labels: z.array(z.string()).optional(), + sort: z.enum(['created', 'updated', 'comments']).optional(), + direction: z.enum(['asc', 'desc']).optional(), + since: z.string().optional(), // ISO 8601 timestamp + page: z.number().optional(), + per_page: z.number().optional() +}); + +export const UpdateIssueOptionsSchema = z.object({ + owner: z.string(), + repo: z.string(), + issue_number: z.number(), + title: z.string().optional(), + body: z.string().optional(), + state: z.enum(['open', 'closed']).optional(), + labels: z.array(z.string()).optional(), + assignees: z.array(z.string()).optional(), + milestone: z.number().optional() +}); + +export const IssueCommentSchema = z.object({ + owner: z.string(), + repo: z.string(), + issue_number: z.number(), + body: z.string() +}); + // Export types export type GitHubAuthor = z.infer; export type GitHubFork = z.infer; From acc6e2af428e00aed3767ec6e4ee82d21c058ba3 Mon Sep 17 00:00:00 2001 From: Henry Mao Date: Sat, 30 Nov 2024 05:05:03 -0800 Subject: [PATCH 04/63] Added Obsidian Community MCP --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 28604b9a..ce50722f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Each MCP server is implemented with either the [Typescript MCP SDK](https://gith - **[Cloudflare](https://github.com/cloudflare/mcp-server-cloudflare)** - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1) - **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Interact with your crash reporting and real using monitoring data on your Raygun account +- **[Obsidian Markdown Notes](https://github.com/calclavia/mcp-obsidian)** - Read and search through your Obsidian vault or any directory containing Markdown notes ## 🚀 Getting Started From 2b731fb70f950ad6fa4560653afdc20beeb49789 Mon Sep 17 00:00:00 2001 From: Mati Horovitz <7645314@gmail.com> Date: Sat, 30 Nov 2024 20:22:35 +0200 Subject: [PATCH 05/63] fix(fetch): fix puppeteer server to allow evaluate async functions --- src/puppeteer/index.ts | 43 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/puppeteer/index.ts b/src/puppeteer/index.ts index d3aa2a30..82f7c86d 100644 --- a/src/puppeteer/index.ts +++ b/src/puppeteer/index.ts @@ -124,6 +124,15 @@ async function ensureBrowser() { return page!; } +declare global { + interface Window { + mcpHelper: { + logs: string[], + originalConsole: Partial, + } + } +} + async function handleToolCall(name: string, args: any): Promise<{ toolResult: CallToolResult }> { const page = await ensureBrowser(); @@ -285,33 +294,35 @@ async function handleToolCall(name: string, args: any): Promise<{ toolResult: Ca case "puppeteer_evaluate": try { - const result = await page.evaluate((script) => { - const logs: string[] = []; - const originalConsole = { ...console }; + await page.evaluate(() => { + window.mcpHelper = { + logs: [], + originalConsole: { ...console }, + }; ['log', 'info', 'warn', 'error'].forEach(method => { (console as any)[method] = (...args: any[]) => { - logs.push(`[${method}] ${args.join(' ')}`); - (originalConsole as any)[method](...args); + window.mcpHelper.logs.push(`[${method}] ${args.join(' ')}`); + (window.mcpHelper.originalConsole as any)[method](...args); }; - }); + } ); + } ); - try { - const result = eval(script); - Object.assign(console, originalConsole); - return { result, logs }; - } catch (error) { - Object.assign(console, originalConsole); - throw error; - } - }, args.script); + const result = await page.evaluate( args.script ); + + const logs = await page.evaluate(() => { + Object.assign(console, window.mcpHelper.originalConsole); + const logs = window.mcpHelper.logs; + delete ( window.mcpHelper as any).logs; + return logs; + }); return { toolResult: { content: [ { type: "text", - text: `Execution result:\n${JSON.stringify(result.result, null, 2)}\n\nConsole output:\n${result.logs.join('\n')}`, + text: `Execution result:\n${JSON.stringify(result, null, 2)}\n\nConsole output:\n${logs.join('\n')}`, }, ], isError: false, From 68b880d96b797a0bddf0322effb29edf67afdc8d Mon Sep 17 00:00:00 2001 From: Mati Horovitz <7645314@gmail.com> Date: Sat, 30 Nov 2024 22:57:18 +0200 Subject: [PATCH 06/63] Fix cleanup --- src/puppeteer/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/puppeteer/index.ts b/src/puppeteer/index.ts index 82f7c86d..9840fc2e 100644 --- a/src/puppeteer/index.ts +++ b/src/puppeteer/index.ts @@ -313,7 +313,7 @@ async function handleToolCall(name: string, args: any): Promise<{ toolResult: Ca const logs = await page.evaluate(() => { Object.assign(console, window.mcpHelper.originalConsole); const logs = window.mcpHelper.logs; - delete ( window.mcpHelper as any).logs; + delete ( window as any).mcpHelper; return logs; }); @@ -426,4 +426,4 @@ async function runServer() { await server.connect(transport); } -runServer().catch(console.error); \ No newline at end of file +runServer().catch(console.error); From e73d831c2563a722d39b8e963d2841e43337c925 Mon Sep 17 00:00:00 2001 From: RamXX Date: Sun, 1 Dec 2024 10:58:43 -0800 Subject: [PATCH 07/63] Added new community link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 28604b9a..060b3a8a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Each MCP server is implemented with either the [Typescript MCP SDK](https://gith - **[Cloudflare](https://github.com/cloudflare/mcp-server-cloudflare)** - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1) - **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Interact with your crash reporting and real using monitoring data on your Raygun account +- **[Tavily search](https://github.com/RamXX/mcp-tavily")** - An MCP server for Tavily's search & news API, with explicit site inclusions/exclusions ## 🚀 Getting Started From 1096d5cd7520c031abd545d860518706a02dfd45 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Mon, 2 Dec 2024 15:13:05 -0800 Subject: [PATCH 08/63] edit_file tool --- src/filesystem/index.ts | 234 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index b4c4e92d..ebe84a08 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -106,6 +106,27 @@ const WriteFileArgsSchema = z.object({ content: z.string(), }); +const EditOperation = z.object({ + startLine: z.number().int().min(1).optional(), + contextLines: z.number().int().min(0).default(3), + oldText: z.string(), + newText: z.string(), + verifyState: z.boolean().default(true), + readBeforeEdit: z.boolean().default(false), + findAnchor: z.string().optional(), + anchorOffset: z.number().int().default(0), + beforeContext: z.string().optional(), + afterContext: z.string().optional(), + contextRadius: z.number().int().min(0).default(3), + insertMode: z.enum(['replace', 'before', 'after']).default('replace'), + dryRun: z.boolean().default(false), +}); + +const EditFileArgsSchema = z.object({ + path: z.string(), + edits: z.array(EditOperation), +}); + const CreateDirectoryArgsSchema = z.object({ path: z.string(), }); @@ -202,6 +223,166 @@ async function searchFiles( return results; } +// Line ending detection and normalization utilities +function detectLineEnding(content: string): string { + // Check if the content contains CRLF + if (content.includes('\r\n')) { + return '\r\n'; + } + // Default to LF + return '\n'; +} + +function normalizeLineEndings(content: string): string { + // Convert all line endings to LF for internal processing + return content.replace(/\r\n/g, '\n'); +} + +function preserveLineEndings(newContent: string, originalLineEnding: string): string { + // Ensure all line endings match the original file + if (originalLineEnding === '\r\n') { + return newContent.replace(/\n/g, '\r\n'); + } + return newContent; +} + +// Edit preview type +interface EditPreview { + originalContent: string; + newContent: string; + lineNumber: number; + matchedAnchor?: string; + contextVerified: boolean; +} + +// File editing utilities +async function applyFileEdits(filePath: string, edits: z.infer[]): Promise { + // Read the file and detect its line endings + let currentContent = await fs.readFile(filePath, 'utf-8'); + const originalLineEnding = detectLineEnding(currentContent); + + // Normalize content for processing + currentContent = normalizeLineEndings(currentContent); + const previews: EditPreview[] = []; + let lines = currentContent.split('\n'); + + // Sort edits by line number in descending order + const sortedEdits = [...edits].sort((a, b) => { + if (a.startLine && b.startLine) { + return b.startLine - a.startLine; + } + return 0; + }); + + for (const edit of sortedEdits) { + // Normalize the edit text for comparison + const normalizedOldText = normalizeLineEndings(edit.oldText); + const normalizedNewText = normalizeLineEndings(edit.newText); + + let startIdx = edit.startLine ? edit.startLine - 1 : -1; + + if (edit.findAnchor) { + // Normalize anchor text and search in normalized content + const normalizedAnchor = normalizeLineEndings(edit.findAnchor); + const content = lines.join('\n'); + const anchorIdx = content.indexOf(normalizedAnchor); + if (anchorIdx === -1) { + throw new Error(`Anchor text not found: ${edit.findAnchor}`); + } + const beforeAnchor = content.substring(0, anchorIdx); + const anchorLine = beforeAnchor.split('\n').length - 1; + startIdx = anchorLine + (edit.anchorOffset || 0); + } + + if (startIdx === -1) { + throw new Error('No valid edit position found - need either startLine or findAnchor'); + } + + // Context verification with normalized line endings + let contextVerified = true; + if (edit.beforeContext || edit.afterContext) { + const radius = edit.contextRadius || 3; + const beforeText = normalizeLineEndings(lines.slice(Math.max(0, startIdx - radius), startIdx).join('\n')); + const afterText = normalizeLineEndings(lines.slice(startIdx + 1, startIdx + radius + 1).join('\n')); + + if (edit.beforeContext && !beforeText.includes(normalizeLineEndings(edit.beforeContext))) { + contextVerified = false; + } + if (edit.afterContext && !afterText.includes(normalizeLineEndings(edit.afterContext))) { + contextVerified = false; + } + + if (!contextVerified && edit.verifyState) { + throw new Error( + `Context verification failed at line ${startIdx + 1}.\n` + + `Expected before context: ${edit.beforeContext}\n` + + `Expected after context: ${edit.afterContext}\n` + + `Found before context: ${beforeText}\n` + + `Found after context: ${afterText}` + ); + } + } + + const oldLines = normalizedOldText.split('\n'); + const newLines = normalizedNewText.split('\n'); + + // Content verification with normalized line endings + if (edit.verifyState) { + const existingContent = normalizeLineEndings(lines.slice(startIdx, startIdx + oldLines.length).join('\n')); + if (existingContent !== normalizedOldText) { + throw new Error( + `Edit validation failed: Content mismatch at line ${startIdx + 1}.\n` + + `Expected:\n${edit.oldText}\n` + + `Found:\n${lines.slice(startIdx, startIdx + oldLines.length).join('\n')}` + ); + } + } + + if (edit.dryRun) { + previews.push({ + originalContent: preserveLineEndings(lines.slice(startIdx, startIdx + oldLines.length).join('\n'), originalLineEnding), + newContent: preserveLineEndings(edit.newText, originalLineEnding), + lineNumber: startIdx + 1, + matchedAnchor: edit.findAnchor, + contextVerified + }); + continue; + } + + // Apply the edit based on insertMode + switch (edit.insertMode) { + case 'before': + lines.splice(startIdx, 0, ...newLines); + break; + case 'after': + lines.splice(startIdx + oldLines.length, 0, ...newLines); + break; + default: // 'replace' + lines.splice(startIdx, oldLines.length, ...newLines); + } + + let updatedContent = lines.join('\n'); + + // Preserve original line endings when writing + updatedContent = preserveLineEndings(updatedContent, originalLineEnding); + + // Re-read file if requested + if (edit.readBeforeEdit) { + await fs.writeFile(filePath, updatedContent, 'utf-8'); + currentContent = await fs.readFile(filePath, 'utf-8'); + currentContent = normalizeLineEndings(currentContent); + lines = currentContent.split('\n'); + } + } + + if (edits.some(e => e.dryRun)) { + return previews; + } + + // Preserve original line endings in final content + return preserveLineEndings(lines.join('\n'), originalLineEnding); +} + // Tool handlers server.setRequestHandler(ListToolsRequestSchema, async () => { return { @@ -233,6 +414,29 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { "Handles text content with proper encoding. Only works within allowed directories.", inputSchema: zodToJsonSchema(WriteFileArgsSchema) as ToolInput, }, + { + name: "edit_file", + description: + "Make selective edits to a text file with advanced pattern matching and validation. " + + "Supports multiple edit modes:\n" + + "1. Line-based: Use startLine to specify exact positions\n" + + "2. Pattern-based: Use findAnchor to locate edit points by matching text\n" + + "3. Context-aware: Verify surrounding text with beforeContext/afterContext\n\n" + + "Features:\n" + + "- Dry run mode for previewing changes (dryRun: true)\n" + + "- Multiple insertion modes: 'replace', 'before', 'after'\n" + + "- Anchor-based positioning with offset support\n" + + "- Automatic state refresh between edits (readBeforeEdit)\n" + + "- Context verification to ensure edit safety\n\n" + + "Recommended workflow:\n" + + "1. Use dryRun to preview changes\n" + + "2. Use findAnchor for resilient positioning\n" + + "3. Enable readBeforeEdit for multi-step changes\n" + + "4. Verify context when position is critical\n\n" + + "This is safer than complete file overwrites as it verifies existing content " + + "and supports granular changes. Only works within allowed directories.", + inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, + }, { name: "create_directory", description: @@ -346,6 +550,36 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { }; } + case "edit_file": { + const parsed = EditFileArgsSchema.safeParse(args); + if (!parsed.success) { + throw new Error(`Invalid arguments for edit_file: ${parsed.error}`); + } + const validPath = await validatePath(parsed.data.path); + const result = await applyFileEdits(validPath, parsed.data.edits); + + // If it's a dry run, format the previews + if (Array.isArray(result)) { + const previewText = result.map(preview => + `Line ${preview.lineNumber}:\n` + + `${preview.matchedAnchor ? `Matched anchor: ${preview.matchedAnchor}\n` : ''}` + + `Context verified: ${preview.contextVerified}\n` + + `Original:\n${preview.originalContent}\n` + + `New:\n${preview.newContent}\n` + ).join('\n---\n'); + + return { + content: [{ type: "text", text: `Edit preview:\n${previewText}` }], + }; + } + + // Otherwise write the changes + await fs.writeFile(validPath, result, "utf-8"); + return { + content: [{ type: "text", text: `Successfully applied edits to ${parsed.data.path}` }], + }; + } + case "create_directory": { const parsed = CreateDirectoryArgsSchema.safeParse(args); if (!parsed.success) { From 9f2a77e044c59b48e3d6b89147c34499c4513795 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Mon, 2 Dec 2024 17:43:17 -0800 Subject: [PATCH 09/63] updated readme --- src/filesystem/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/filesystem/README.md b/src/filesystem/README.md index c2950cd5..99337d3c 100644 --- a/src/filesystem/README.md +++ b/src/filesystem/README.md @@ -36,6 +36,35 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio - `path` (string): File location - `content` (string): File content +- **edit_file** + - Make selective edits to files with advanced pattern matching + - Features: + - Multiple positioning modes: + - Line-based: Specify exact line numbers + - Pattern-based: Find positions using anchor text + - Context-aware: Verify surrounding content + - Insert modes: 'replace', 'before', or 'after' content + - Dry run preview of changes + - Cross-platform line ending support (CRLF/LF) + - Git-friendly content verification + - Inputs: + - `path` (string): File to edit + - `edits` (array): List of edit operations + - `startLine?` (number): Line number for edit (optional) + - `findAnchor?` (string): Text to locate edit position (optional) + - `anchorOffset` (number): Lines to offset from anchor (default: 0) + - `oldText` (string): Content to replace/verify + - `newText` (string): New content to insert + - `insertMode` (string): 'replace', 'before', or 'after' (default: 'replace') + - `beforeContext?` (string): Expected content before edit point (optional) + - `afterContext?` (string): Expected content after edit point (optional) + - `contextRadius` (number): Lines to check for context (default: 3) + - `verifyState` (boolean): Verify content matches before editing (default: true) + - `readBeforeEdit` (boolean): Refresh file state between edits (default: false) + - `dryRun` (boolean): Preview changes without applying them (default: false) + - Returns preview information for dry runs, otherwise applies changes + - Preserves original line endings and handles Git auto CRLF/LF + - **create_directory** - Create new directory or ensure it exists - Input: `path` (string) From a1bc14d38dc6b224b6074045c4794c353b21b19a Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Mon, 2 Dec 2024 17:48:19 -0800 Subject: [PATCH 10/63] improve line ending docs --- src/filesystem/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index ebe84a08..8ebae2fa 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -224,6 +224,12 @@ async function searchFiles( } // Line ending detection and normalization utilities +// These functions ensure consistent behavior across different platforms and Git configurations. +// They handle the following scenarios: +// - Windows CRLF (\r\n) vs Unix LF (\n) line endings +// - Git's core.autocrlf setting converting line endings +// - Mixed line endings within the same file +// This makes the edit functionality reliable regardless of the development environment. function detectLineEnding(content: string): string { // Check if the content contains CRLF if (content.includes('\r\n')) { From 431d90971722824e7c2966a4399b235f09cf3c52 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Mon, 2 Dec 2024 18:03:36 -0800 Subject: [PATCH 11/63] indentation support --- src/filesystem/index.ts | 126 +++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 53 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 8ebae2fa..44aa9480 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -223,13 +223,34 @@ async function searchFiles( return results; } -// Line ending detection and normalization utilities -// These functions ensure consistent behavior across different platforms and Git configurations. -// They handle the following scenarios: -// - Windows CRLF (\r\n) vs Unix LF (\n) line endings -// - Git's core.autocrlf setting converting line endings -// - Mixed line endings within the same file -// This makes the edit functionality reliable regardless of the development environment. +// Content normalization utilities +// These functions handle: +// - Line ending normalization (CRLF vs LF) +// - Indentation preservation and normalization +// - Git's core.autocrlf setting +// - Mixed line endings +// This makes the edit functionality reliable across different environments and formatting styles + +function normalizeForComparison(content: string): string { + // First normalize line endings + let normalized = content.replace(/\r\n/g, '\n'); + // Remove leading/trailing whitespace from each line while preserving empty lines + normalized = normalized.split('\n') + .map(line => line.trim()) + .join('\n'); + return normalized; +} + +function preserveIndentation(newContent: string, originalContent: string): string { + const originalLines = originalContent.split(/\r?\n/); + const indentMatch = originalLines.find(line => line.trim())?.match(/^\s*/); + const baseIndent = indentMatch ? indentMatch[0] : ''; + + return newContent.split(/\r?\n/) + .map(line => line.trim() ? baseIndent + line : line) + .join(originalContent.includes('\r\n') ? '\r\n' : '\n'); +} + function detectLineEnding(content: string): string { // Check if the content contains CRLF if (content.includes('\r\n')) { @@ -263,14 +284,10 @@ interface EditPreview { // File editing utilities async function applyFileEdits(filePath: string, edits: z.infer[]): Promise { - // Read the file and detect its line endings + // Read the file content let currentContent = await fs.readFile(filePath, 'utf-8'); - const originalLineEnding = detectLineEnding(currentContent); - - // Normalize content for processing - currentContent = normalizeLineEndings(currentContent); const previews: EditPreview[] = []; - let lines = currentContent.split('\n'); + let lines = currentContent.split(/\r?\n/); // Sort edits by line number in descending order const sortedEdits = [...edits].sort((a, b) => { @@ -281,73 +298,76 @@ async function applyFileEdits(filePath: string, edits: z.infer Date: Mon, 2 Dec 2024 19:03:48 -0800 Subject: [PATCH 12/63] line numbering improvements --- src/filesystem/index.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 44aa9480..ed6f627d 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -301,20 +301,21 @@ async function applyFileEdits(filePath: string, edits: z.infer Date: Mon, 2 Dec 2024 19:21:05 -0800 Subject: [PATCH 13/63] simplify text replacement approach for better reliability --- src/filesystem/index.ts | 203 +++++++++++++++------------------------- 1 file changed, 77 insertions(+), 126 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index ed6f627d..f88036de 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -107,19 +107,30 @@ const WriteFileArgsSchema = z.object({ }); const EditOperation = z.object({ - startLine: z.number().int().min(1).optional(), - contextLines: z.number().int().min(0).default(3), - oldText: z.string(), - newText: z.string(), - verifyState: z.boolean().default(true), - readBeforeEdit: z.boolean().default(false), - findAnchor: z.string().optional(), - anchorOffset: z.number().int().default(0), - beforeContext: z.string().optional(), - afterContext: z.string().optional(), - contextRadius: z.number().int().min(0).default(3), - insertMode: z.enum(['replace', 'before', 'after']).default('replace'), - dryRun: z.boolean().default(false), + // Primary edit specification + oldText: z.string().describe('Exact text to match, including whitespace/formatting'), + newText: z.string().describe('Replacement text with desired formatting'), + + // Location finding (one of these should be provided) + startLine: z.number().int().min(1).optional().describe('Exact line number to start edit'), + findAnchor: z.string().optional().describe('Text to search for to locate edit position'), + + // Edit behavior + insertMode: z.enum(['replace', 'before', 'after']).default('replace') + .describe('Whether to replace matched text or insert before/after it'), + verifyState: z.boolean().default(true) + .describe('Whether to verify exact text matches before editing'), + readBeforeEdit: z.boolean().default(false) + .describe('Whether to re-read file between multiple edits'), + + // Optional context verification + beforeContext: z.string().optional().describe('Text that should appear before edit point'), + afterContext: z.string().optional().describe('Text that should appear after edit point'), + contextRadius: z.number().int().min(0).default(3) + .describe('Number of lines to check for context matches'), + + // Preview mode + dryRun: z.boolean().default(false).describe('Preview changes without applying them'), }); const EditFileArgsSchema = z.object({ @@ -224,53 +235,14 @@ async function searchFiles( } // Content normalization utilities -// These functions handle: -// - Line ending normalization (CRLF vs LF) -// - Indentation preservation and normalization -// - Git's core.autocrlf setting -// - Mixed line endings -// This makes the edit functionality reliable across different environments and formatting styles - +// Used only for fuzzy matching of anchor text and context verification +// Does not affect the actual content replacement function normalizeForComparison(content: string): string { - // First normalize line endings - let normalized = content.replace(/\r\n/g, '\n'); - // Remove leading/trailing whitespace from each line while preserving empty lines - normalized = normalized.split('\n') + // Normalize line endings and whitespace for comparison only + return content.replace(/\r\n/g, '\n') + .split('\n') .map(line => line.trim()) .join('\n'); - return normalized; -} - -function preserveIndentation(newContent: string, originalContent: string): string { - const originalLines = originalContent.split(/\r?\n/); - const indentMatch = originalLines.find(line => line.trim())?.match(/^\s*/); - const baseIndent = indentMatch ? indentMatch[0] : ''; - - return newContent.split(/\r?\n/) - .map(line => line.trim() ? baseIndent + line : line) - .join(originalContent.includes('\r\n') ? '\r\n' : '\n'); -} - -function detectLineEnding(content: string): string { - // Check if the content contains CRLF - if (content.includes('\r\n')) { - return '\r\n'; - } - // Default to LF - return '\n'; -} - -function normalizeLineEndings(content: string): string { - // Convert all line endings to LF for internal processing - return content.replace(/\r\n/g, '\n'); -} - -function preserveLineEndings(newContent: string, originalLineEnding: string): string { - // Ensure all line endings match the original file - if (originalLineEnding === '\r\n') { - return newContent.replace(/\n/g, '\r\n'); - } - return newContent; } // Edit preview type @@ -287,48 +259,37 @@ async function applyFileEdits(filePath: string, edits: z.infer { - if (a.startLine && b.startLine) { - return b.startLine - a.startLine; - } - return 0; - }); - - for (const edit of sortedEdits) { - let startIdx = edit.startLine ? edit.startLine - 1 : -1; + for (const edit of edits) { + let editContent = currentContent; + let editPosition = -1; + // Find the edit position using anchor if provided if (edit.findAnchor) { - // Use line-by-line comparison for accurate anchor matching - let foundLine = -1; + const normalizedContent = normalizeForComparison(currentContent); const normalizedAnchor = normalizeForComparison(edit.findAnchor); + const anchorPos = normalizedContent.indexOf(normalizedAnchor); - for (let i = 0; i < lines.length; i++) { - const normalizedLine = normalizeForComparison(lines[i]); - if (normalizedLine.includes(normalizedAnchor)) { - foundLine = i; - break; - } - } - if (foundLine === -1) { + if (anchorPos === -1) { throw new Error(`Edit failed - anchor text not found: ${edit.findAnchor} in ${filePath}`); } - startIdx = foundLine + (edit.anchorOffset || 0); - } - - if (startIdx === -1) { + + // Map normalized position back to original content + editPosition = currentContent.slice(0, anchorPos).split('\n').length - 1; + } else if (edit.startLine) { + editPosition = edit.startLine - 1; + } else { throw new Error(`Edit failed - no valid position found in ${filePath}. Operation requires either startLine or findAnchor`); } - - // Context verification with normalized comparison - let contextVerified = true; + + // Verify context if provided if (edit.beforeContext || edit.afterContext) { + const lines = currentContent.split('\n'); const radius = edit.contextRadius || 3; - const beforeText = lines.slice(Math.max(0, startIdx - radius), startIdx).join('\n'); - const afterText = lines.slice(startIdx + 1, startIdx + radius + 1).join('\n'); + const beforeText = lines.slice(Math.max(0, editPosition - radius), editPosition).join('\n'); + const afterText = lines.slice(editPosition + 1, editPosition + radius + 1).join('\n'); + let contextVerified = true; if (edit.beforeContext && !normalizeForComparison(beforeText).includes(normalizeForComparison(edit.beforeContext))) { contextVerified = false; } @@ -338,67 +299,58 @@ async function applyFileEdits(filePath: string, edits: z.infer Date: Mon, 2 Dec 2024 19:38:33 -0800 Subject: [PATCH 14/63] simplify edit_file to use git-style diffs and substring matching --- src/filesystem/index.ts | 187 ++++++++-------------------------------- 1 file changed, 38 insertions(+), 149 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index f88036de..ff113afe 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -107,30 +107,12 @@ const WriteFileArgsSchema = z.object({ }); const EditOperation = z.object({ - // Primary edit specification - oldText: z.string().describe('Exact text to match, including whitespace/formatting'), - newText: z.string().describe('Replacement text with desired formatting'), - - // Location finding (one of these should be provided) - startLine: z.number().int().min(1).optional().describe('Exact line number to start edit'), - findAnchor: z.string().optional().describe('Text to search for to locate edit position'), - - // Edit behavior - insertMode: z.enum(['replace', 'before', 'after']).default('replace') - .describe('Whether to replace matched text or insert before/after it'), - verifyState: z.boolean().default(true) - .describe('Whether to verify exact text matches before editing'), - readBeforeEdit: z.boolean().default(false) - .describe('Whether to re-read file between multiple edits'), - - // Optional context verification - beforeContext: z.string().optional().describe('Text that should appear before edit point'), - afterContext: z.string().optional().describe('Text that should appear after edit point'), - contextRadius: z.number().int().min(0).default(3) - .describe('Number of lines to check for context matches'), - - // Preview mode - dryRun: z.boolean().default(false).describe('Preview changes without applying them'), + // The text to search for + oldText: z.string().describe('Text to search for - can be a substring of the target'), + // The new text to replace with + newText: z.string().describe('Text to replace the found text with'), + // Optional: preview changes without applying them + dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') }); const EditFileArgsSchema = z.object({ @@ -234,131 +216,59 @@ async function searchFiles( return results; } -// Content normalization utilities -// Used only for fuzzy matching of anchor text and context verification -// Does not affect the actual content replacement -function normalizeForComparison(content: string): string { - // Normalize line endings and whitespace for comparison only - return content.replace(/\r\n/g, '\n') - .split('\n') - .map(line => line.trim()) - .join('\n'); -} - // Edit preview type interface EditPreview { - originalContent: string; - newContent: string; + original: string; + modified: string; lineNumber: number; - matchedAnchor?: string; - contextVerified: boolean; + preview: string; // Git-style diff format } // File editing utilities async function applyFileEdits(filePath: string, edits: z.infer[]): Promise { - // Read the file content - let currentContent = await fs.readFile(filePath, 'utf-8'); + let content = await fs.readFile(filePath, 'utf-8'); const previews: EditPreview[] = []; for (const edit of edits) { - let editContent = currentContent; - let editPosition = -1; - - // Find the edit position using anchor if provided - if (edit.findAnchor) { - const normalizedContent = normalizeForComparison(currentContent); - const normalizedAnchor = normalizeForComparison(edit.findAnchor); - const anchorPos = normalizedContent.indexOf(normalizedAnchor); - - if (anchorPos === -1) { - throw new Error(`Edit failed - anchor text not found: ${edit.findAnchor} in ${filePath}`); - } - - // Map normalized position back to original content - editPosition = currentContent.slice(0, anchorPos).split('\n').length - 1; - } else if (edit.startLine) { - editPosition = edit.startLine - 1; - } else { - throw new Error(`Edit failed - no valid position found in ${filePath}. Operation requires either startLine or findAnchor`); - } - - // Verify context if provided - if (edit.beforeContext || edit.afterContext) { - const lines = currentContent.split('\n'); - const radius = edit.contextRadius || 3; - const beforeText = lines.slice(Math.max(0, editPosition - radius), editPosition).join('\n'); - const afterText = lines.slice(editPosition + 1, editPosition + radius + 1).join('\n'); - - let contextVerified = true; - if (edit.beforeContext && !normalizeForComparison(beforeText).includes(normalizeForComparison(edit.beforeContext))) { - contextVerified = false; - } - if (edit.afterContext && !normalizeForComparison(afterText).includes(normalizeForComparison(edit.afterContext))) { - contextVerified = false; - } - - if (!contextVerified && edit.verifyState) { - throw new Error( - `Edit failed - context verification failed in ${filePath} at line ${editPosition + 1}\n` + - `Expected before context: ${edit.beforeContext}\n` + - `Expected after context: ${edit.afterContext}\n` + - `Found before context: ${beforeText}\n` + - `Found after context: ${afterText}\n` - ); - } - } - - // Look for exact match of oldText - const searchStr = edit.oldText; - const searchPos = currentContent.indexOf(searchStr); - - if (searchPos === -1 && edit.verifyState) { + const pos = content.indexOf(edit.oldText); + if (pos === -1) { throw new Error( - `Edit failed - content not found in ${filePath}\n` + - `Expected to find:\n${searchStr}\n` + `Search text not found in ${filePath}:\n${edit.oldText}` ); } + // Calculate line number for reporting + const lineNumber = content.slice(0, pos).split(/\r?\n/).length; + if (edit.dryRun) { + // Create git-style diff preview + const preview = [ + `@@ line ${lineNumber} @@`, + '<<<<<<< ORIGINAL', + edit.oldText, + '=======', + edit.newText, + '>>>>>>> MODIFIED' + ].join('\n'); + previews.push({ - originalContent: searchStr, - newContent: edit.newText, - lineNumber: editPosition + 1, - matchedAnchor: edit.findAnchor, - contextVerified: true + original: edit.oldText, + modified: edit.newText, + lineNumber, + preview }); continue; } - // Apply the edit based on insertMode - switch (edit.insertMode) { - case 'before': - editContent = currentContent.slice(0, searchPos) + - edit.newText + currentContent.slice(searchPos); - break; - case 'after': - editContent = currentContent.slice(0, searchPos + searchStr.length) + - edit.newText + currentContent.slice(searchPos + searchStr.length); - break; - default: // 'replace' - editContent = currentContent.slice(0, searchPos) + - edit.newText + currentContent.slice(searchPos + searchStr.length); - } - - // Update content for next edit - if (edit.readBeforeEdit) { - await fs.writeFile(filePath, editContent, 'utf-8'); - currentContent = await fs.readFile(filePath, 'utf-8'); - } else { - currentContent = editContent; - } + // Apply the edit + content = content.slice(0, pos) + edit.newText + content.slice(pos + edit.oldText.length); } if (edits.some(e => e.dryRun)) { return previews; } - return currentContent; + return content; } // Tool handlers @@ -395,24 +305,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { { name: "edit_file", description: - "Make selective edits to a text file with advanced pattern matching and validation. " + - "Supports multiple edit modes:\n" + - "1. Line-based: Use startLine to specify exact positions\n" + - "2. Pattern-based: Use findAnchor to locate edit points by matching text\n" + - "3. Context-aware: Verify surrounding text with beforeContext/afterContext\n\n" + - "Features:\n" + - "- Dry run mode for previewing changes (dryRun: true)\n" + - "- Multiple insertion modes: 'replace', 'before', 'after'\n" + - "- Anchor-based positioning with offset support\n" + - "- Automatic state refresh between edits (readBeforeEdit)\n" + - "- Context verification to ensure edit safety\n\n" + - "Recommended workflow:\n" + - "1. Use dryRun to preview changes\n" + - "2. Use findAnchor for resilient positioning\n" + - "3. Enable readBeforeEdit for multi-step changes\n" + - "4. Verify context when position is critical\n\n" + - "This is safer than complete file overwrites as it verifies existing content " + - "and supports granular changes. Only works within allowed directories.", + "Make selective edits to a text file using simple search and replace with git-style preview format. " + + "Finds text to replace using substring matching and shows changes in a familiar git-diff format. " + + "Use dry run mode to preview changes before applying them. " + + "Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, }, { @@ -538,14 +434,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { // If it's a dry run, format the previews if (Array.isArray(result)) { - const previewText = result.map(preview => - `Line ${preview.lineNumber}:\n` + - `${preview.matchedAnchor ? `Matched anchor: ${preview.matchedAnchor}\n` : ''}` + - `Context verified: ${preview.contextVerified}\n` + - `Original:\n${preview.originalContent}\n` + - `New:\n${preview.newContent}\n` - ).join('\n---\n'); - + const previewText = result.map(preview => preview.preview).join('\n\n'); return { content: [{ type: "text", text: `Edit preview:\n${previewText}` }], }; From da0ef8106740069b77876843f22570aa870a80df Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Tue, 3 Dec 2024 07:21:59 -0800 Subject: [PATCH 15/63] update readme --- src/filesystem/README.md | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/filesystem/README.md b/src/filesystem/README.md index 99337d3c..f0e34cd0 100644 --- a/src/filesystem/README.md +++ b/src/filesystem/README.md @@ -37,33 +37,19 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio - `content` (string): File content - **edit_file** - - Make selective edits to files with advanced pattern matching + - Make selective edits using search and replace - Features: - - Multiple positioning modes: - - Line-based: Specify exact line numbers - - Pattern-based: Find positions using anchor text - - Context-aware: Verify surrounding content - - Insert modes: 'replace', 'before', or 'after' content - - Dry run preview of changes - - Cross-platform line ending support (CRLF/LF) - - Git-friendly content verification + - Simple substring matching for finding text + - Git-style preview format for changes + - Preview changes with dry run mode + - Preserves original file formatting and indentation - Inputs: - `path` (string): File to edit - `edits` (array): List of edit operations - - `startLine?` (number): Line number for edit (optional) - - `findAnchor?` (string): Text to locate edit position (optional) - - `anchorOffset` (number): Lines to offset from anchor (default: 0) - - `oldText` (string): Content to replace/verify - - `newText` (string): New content to insert - - `insertMode` (string): 'replace', 'before', or 'after' (default: 'replace') - - `beforeContext?` (string): Expected content before edit point (optional) - - `afterContext?` (string): Expected content after edit point (optional) - - `contextRadius` (number): Lines to check for context (default: 3) - - `verifyState` (boolean): Verify content matches before editing (default: true) - - `readBeforeEdit` (boolean): Refresh file state between edits (default: false) - - `dryRun` (boolean): Preview changes without applying them (default: false) + - `oldText` (string): Text to search for (can be substring) + - `newText` (string): Text to replace with + - `dryRun` (boolean): Preview changes without applying (default: false) - Returns preview information for dry runs, otherwise applies changes - - Preserves original line endings and handles Git auto CRLF/LF - **create_directory** - Create new directory or ensure it exists @@ -127,4 +113,4 @@ Add this to your `claude_desktop_config.json`: ## License -This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository. +This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository. \ No newline at end of file From de4976903408f72e7c1a7f2af442526bf4a63642 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Tue, 3 Dec 2024 08:51:01 -0800 Subject: [PATCH 16/63] limitations added to readme --- src/filesystem/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/filesystem/README.md b/src/filesystem/README.md index f0e34cd0..31995d8f 100644 --- a/src/filesystem/README.md +++ b/src/filesystem/README.md @@ -42,7 +42,11 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio - Simple substring matching for finding text - Git-style preview format for changes - Preview changes with dry run mode - - Preserves original file formatting and indentation + - Preserves consistent indentation patterns + - Limitations: + - Intended for content changes, not code formatting + - Mixed tabs/spaces can cause pattern matching issues + - Use code formatters (e.g., Prettier, ESLint) before content edits - Inputs: - `path` (string): File to edit - `edits` (array): List of edit operations From 506eabab398353a587f28dd5c022810ab3fd53dc Mon Sep 17 00:00:00 2001 From: Jerad Bitner Date: Tue, 3 Dec 2024 13:21:00 -0800 Subject: [PATCH 17/63] fix: update listIssues and updateIssue function signatures --- src/github/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/github/index.ts b/src/github/index.ts index f3c35e86..d861cbbb 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -473,7 +473,7 @@ async function createRepository( async function listIssues( owner: string, repo: string, - options: z.infer + options: Omit, 'owner' | 'repo'> ): Promise { const url = new URL(`https://api.github.com/repos/${owner}/${repo}/issues`); @@ -505,7 +505,7 @@ async function updateIssue( owner: string, repo: string, issueNumber: number, - options: z.infer + options: Omit, 'owner' | 'repo' | 'issue_number'> ): Promise { const response = await fetch( `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`, From dc9f56720feb4edc15d6dbd7d51b8c4ddd6ec92c Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Tue, 3 Dec 2024 16:45:04 -0800 Subject: [PATCH 18/63] same compare for edit and dry run --- src/filesystem/index.ts | 62 +++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index ff113afe..bf433596 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -111,13 +111,13 @@ const EditOperation = z.object({ oldText: z.string().describe('Text to search for - can be a substring of the target'), // The new text to replace with newText: z.string().describe('Text to replace the found text with'), - // Optional: preview changes without applying them - dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') }); const EditFileArgsSchema = z.object({ path: z.string(), edits: z.array(EditOperation), + // Optional: preview changes without applying them + dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') }); const CreateDirectoryArgsSchema = z.object({ @@ -225,7 +225,7 @@ interface EditPreview { } // File editing utilities -async function applyFileEdits(filePath: string, edits: z.infer[]): Promise { +async function applyFileEdits(filePath: string, edits: Array<{oldText: string, newText: string}>, dryRun: boolean = false): Promise { let content = await fs.readFile(filePath, 'utf-8'); const previews: EditPreview[] = []; @@ -237,38 +237,29 @@ async function applyFileEdits(filePath: string, edits: z.infer>>>>>> MODIFIED' + ].join('\n'); - if (edit.dryRun) { - // Create git-style diff preview - const preview = [ - `@@ line ${lineNumber} @@`, - '<<<<<<< ORIGINAL', - edit.oldText, - '=======', - edit.newText, - '>>>>>>> MODIFIED' - ].join('\n'); - - previews.push({ - original: edit.oldText, - modified: edit.newText, - lineNumber, - preview - }); - continue; + previews.push({ + original: edit.oldText, + modified: edit.newText, + lineNumber, + preview + }); + + if (!dryRun) { + content = content.slice(0, pos) + edit.newText + content.slice(pos + edit.oldText.length); } - - // Apply the edit - content = content.slice(0, pos) + edit.newText + content.slice(pos + edit.oldText.length); } - if (edits.some(e => e.dryRun)) { - return previews; - } - - return content; + return dryRun ? previews : content; } // Tool handlers @@ -430,18 +421,17 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { throw new Error(`Invalid arguments for edit_file: ${parsed.error}`); } const validPath = await validatePath(parsed.data.path); - const result = await applyFileEdits(validPath, parsed.data.edits); + const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun); // If it's a dry run, format the previews - if (Array.isArray(result)) { - const previewText = result.map(preview => preview.preview).join('\n\n'); + if (parsed.data.dryRun) { + const previewText = (result as EditPreview[]).map(preview => preview.preview).join('\n\n'); return { content: [{ type: "text", text: `Edit preview:\n${previewText}` }], }; } - - // Otherwise write the changes - await fs.writeFile(validPath, result, "utf-8"); + + await fs.writeFile(validPath, result as string, "utf-8"); return { content: [{ type: "text", text: `Successfully applied edits to ${parsed.data.path}` }], }; From 44f68efbdcdf8edaf30594f6319810d2a12d030c Mon Sep 17 00:00:00 2001 From: Himanshu Ladia Date: Wed, 4 Dec 2024 14:58:47 +0530 Subject: [PATCH 19/63] add capability to list commits of a branch --- src/github/index.ts | 48 ++++++++++++++++++++++++++++++++++++++++++- src/github/schemas.ts | 9 ++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/github/index.ts b/src/github/index.ts index 800bce83..06cdc7d4 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -41,7 +41,8 @@ import { CreateIssueSchema, CreatePullRequestSchema, ForkRepositorySchema, - CreateBranchSchema + CreateBranchSchema, + ListCommitsSchema } from './schemas.js'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; @@ -467,6 +468,40 @@ async function createRepository( return GitHubRepositorySchema.parse(await response.json()); } +async function listCommits( + owner: string, + repo: string, + page: number = 1, + perPage: number = 30, + sha?: string, +): Promise { + const url = new URL(`https://api.github.com/repos/${owner}/${repo}/commits`); + url.searchParams.append("page", page.toString()); + url.searchParams.append("per_page", perPage.toString()); + if (sha) { + url.searchParams.append("sha", sha); + } + + const response = await fetch( + url.toString(), + { + method: "GET", + headers: { + "Authorization": `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + "Accept": "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + "Content-Type": "application/json" + }, + } + ); + + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + + return GitHubCommitSchema.array().parse(await response.json()); +} + server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ @@ -514,6 +549,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { name: "create_branch", description: "Create a new branch in a GitHub repository", inputSchema: zodToJsonSchema(CreateBranchSchema) + }, + { + name: "list_commits", + description: "Get list of commits of a branch in a GitHub repository", + inputSchema: zodToJsonSchema(ListCommitsSchema) } ] }; @@ -623,6 +663,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }] }; } + case "list_commits": { + const args = ListCommitsSchema.parse(request.params.arguments); + const results = await listCommits(args.owner, args.repo, args.page, args.perPage, args.sha); + return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; + } + default: throw new Error(`Unknown tool: ${request.params.name}`); } diff --git a/src/github/schemas.ts b/src/github/schemas.ts index 213458eb..defc2569 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -308,6 +308,15 @@ export const SearchRepositoriesSchema = z.object({ perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)") }); +export const ListCommitsSchema = z.object({ + owner: z.string().describe("Repository owner (username or organization)"), + repo: z.string().describe("Repository name"), + page: z.number().optional().describe("Page number for pagination (default: 1)"), + perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)"), + sha: z.string().optional() + .describe("SHA of the file being replaced (required when updating existing files)") +}); + export const CreateRepositorySchema = z.object({ name: z.string().describe("Repository name"), description: z.string().optional().describe("Repository description"), From c31f00f54fb70222dd9e8e8c4b17466151414718 Mon Sep 17 00:00:00 2001 From: Himanshu Ladia Date: Wed, 4 Dec 2024 17:29:56 +0530 Subject: [PATCH 20/63] fix contract --- src/github/index.ts | 8 +++++--- src/github/schemas.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/github/index.ts b/src/github/index.ts index 06cdc7d4..66cae6a1 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -18,6 +18,7 @@ import { GitHubSearchResponseSchema, GitHubTreeSchema, GitHubCommitSchema, + GitHubListCommitsSchema, CreateRepositoryOptionsSchema, CreateIssueOptionsSchema, CreatePullRequestOptionsSchema, @@ -42,7 +43,8 @@ import { CreatePullRequestSchema, ForkRepositorySchema, CreateBranchSchema, - ListCommitsSchema + ListCommitsSchema, + GitHubListCommits } from './schemas.js'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; @@ -474,7 +476,7 @@ async function listCommits( page: number = 1, perPage: number = 30, sha?: string, -): Promise { +): Promise { const url = new URL(`https://api.github.com/repos/${owner}/${repo}/commits`); url.searchParams.append("page", page.toString()); url.searchParams.append("per_page", perPage.toString()); @@ -499,7 +501,7 @@ async function listCommits( throw new Error(`GitHub API error: ${response.statusText}`); } - return GitHubCommitSchema.array().parse(await response.json()); + return GitHubListCommitsSchema.parse(await response.json()); } server.setRequestHandler(ListToolsRequestSchema, async () => { diff --git a/src/github/schemas.ts b/src/github/schemas.ts index defc2569..ad9f30c8 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -93,6 +93,25 @@ export const GitHubTreeSchema = z.object({ truncated: z.boolean() }); +export const GitHubListCommitsSchema = z.array(z.object({ + sha: z.string(), + node_id: z.string(), + commit: z.object({ + author: GitHubAuthorSchema, + committer: GitHubAuthorSchema, + message: z.string(), + tree: z.object({ + sha: z.string(), + url: z.string() + }), + url: z.string(), + comment_count: z.number(), + }), + url: z.string(), + html_url: z.string(), + comments_url: z.string() +})); + export const GitHubCommitSchema = z.object({ sha: z.string(), node_id: z.string(), @@ -378,6 +397,7 @@ export type GitHubContent = z.infer; export type FileOperation = z.infer; export type GitHubTree = z.infer; export type GitHubCommit = z.infer; +export type GitHubListCommits = z.infer; export type GitHubReference = z.infer; export type CreateRepositoryOptions = z.infer; export type CreateIssueOptions = z.infer; From 215574f511fa05d5bf9393bbcfe2b9df03eb0d40 Mon Sep 17 00:00:00 2001 From: Himanshu Ladia Date: Wed, 4 Dec 2024 18:16:23 +0530 Subject: [PATCH 21/63] update read me --- src/github/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/github/README.md b/src/github/README.md index cfd268a8..de29874c 100644 --- a/src/github/README.md +++ b/src/github/README.md @@ -102,6 +102,16 @@ MCP Server for the GitHub API, enabling file operations, repository management, - `from_branch` (optional string): Source branch (defaults to repo default) - Returns: Created branch reference +10. `list_commits` + - Gets commits of a branch in a repository + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `page` (optional string): page number + - `per_page` (optional string): number of record per page + - `sha` (optional string): branch name + - Returns: List of commits + ## Setup ### Personal Access Token From 1ec75e87fc6ab1e843e866ac4fffa8cd4cd535af Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 07:27:02 -0800 Subject: [PATCH 22/63] improve multiline text editing reliability by tracking positions and applying edits in reverse order --- src/filesystem/index.ts | 55 ++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index bf433596..e736b1c1 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -216,6 +216,29 @@ async function searchFiles( return results; } +interface Position { + start: number; + end: number; + lineNumber: number; +} + +function findTextPosition(content: string, searchText: string): Position { + // Handle different line endings + const normalized = content.replace(/\r\n/g, '\n'); + const searchNormalized = searchText.replace(/\r\n/g, '\n'); + + const pos = normalized.indexOf(searchNormalized); + if (pos === -1) { + throw new Error(`Text not found:\n${searchText}`); + } + + return { + start: pos, + end: pos + searchText.length, + lineNumber: normalized.slice(0, pos).split('\n').length + }; +} + // Edit preview type interface EditPreview { original: string; @@ -225,37 +248,39 @@ interface EditPreview { } // File editing utilities -async function applyFileEdits(filePath: string, edits: Array<{oldText: string, newText: string}>, dryRun: boolean = false): Promise { +async function applyFileEdits(filePath: string, edits: Array<{oldText: string, newText: string}>, dryRun = false): Promise { let content = await fs.readFile(filePath, 'utf-8'); const previews: EditPreview[] = []; - for (const edit of edits) { - const pos = content.indexOf(edit.oldText); - if (pos === -1) { - throw new Error( - `Search text not found in ${filePath}:\n${edit.oldText}` - ); - } - - const lineNumber = content.slice(0, pos).split(/\r?\n/).length; + // Find all positions first + const positions = edits.map(edit => ({ + edit, + position: findTextPosition(content, edit.oldText) + })); + + // Sort by position in reverse order + positions.sort((a, b) => b.position.start - a.position.start); + + // Apply edits from end to start + for (const {edit, position} of positions) { const preview = [ - `@@ line ${lineNumber} @@`, + `@@ line ${position.lineNumber} @@`, '<<<<<<< ORIGINAL', edit.oldText, '=======', edit.newText, - '>>>>>>> MODIFIED' + '>>>>>>> MODIFIED' ].join('\n'); previews.push({ original: edit.oldText, modified: edit.newText, - lineNumber, + lineNumber: position.lineNumber, preview }); - + if (!dryRun) { - content = content.slice(0, pos) + edit.newText + content.slice(pos + edit.oldText.length); + content = content.slice(0, position.start) + edit.newText + content.slice(position.end); } } From bb7925fe11e3500dad6fc1d4baf5e20925fc2358 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 07:35:12 -0800 Subject: [PATCH 23/63] improve whitespace sensitivity in multiline text matching --- src/filesystem/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index e736b1c1..12dde55d 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -231,10 +231,14 @@ function findTextPosition(content: string, searchText: string): Position { if (pos === -1) { throw new Error(`Text not found:\n${searchText}`); } + + // Map back to original content position + const originalPos = content.slice(0, pos).replace(/[ \t]+/g, ' ').length; + const originalEnd = originalPos + searchText.length; return { start: pos, - end: pos + searchText.length, + end: originalEnd, lineNumber: normalized.slice(0, pos).split('\n').length }; } From 789219ddf9ac72d627229efd06e826c674a0359e Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Wed, 4 Dec 2024 16:37:14 +0000 Subject: [PATCH 24/63] Make `merge_commit_sha` nullable in GitHub server Fixes #227. --- src/github/schemas.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/github/schemas.ts b/src/github/schemas.ts index 213458eb..83bf3736 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -281,7 +281,7 @@ export const GitHubPullRequestSchema = z.object({ updated_at: z.string(), closed_at: z.string().nullable(), merged_at: z.string().nullable(), - merge_commit_sha: z.string(), + merge_commit_sha: z.string().nullable(), assignee: GitHubIssueAssigneeSchema.nullable(), assignees: z.array(GitHubIssueAssigneeSchema), head: GitHubPullRequestHeadSchema, @@ -375,4 +375,4 @@ export type CreateIssueOptions = z.infer; export type CreatePullRequestOptions = z.infer; export type CreateBranchOptions = z.infer; export type GitHubCreateUpdateFileResponse = z.infer; -export type GitHubSearchResponse = z.infer; \ No newline at end of file +export type GitHubSearchResponse = z.infer; From 02ff589f5803c8412eb50d4e80691acd5979d35d Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 19:21:04 -0800 Subject: [PATCH 25/63] user aider inspired diff approach --- src/filesystem/index.ts | 200 ++++++++++++++++++++++++++-------------- 1 file changed, 133 insertions(+), 67 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 12dde55d..3306f315 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -216,79 +216,146 @@ async function searchFiles( return results; } -interface Position { - start: number; - end: number; +interface DiffLine { + type: 'context' | 'addition' | 'deletion'; + content: string; lineNumber: number; } -function findTextPosition(content: string, searchText: string): Position { - // Handle different line endings - const normalized = content.replace(/\r\n/g, '\n'); - const searchNormalized = searchText.replace(/\r\n/g, '\n'); +function createUnifiedDiff(originalLines: string[], newLines: string[], contextSize: number = 3): string { + const differ = new Array(); + let lineNumber = 1; - const pos = normalized.indexOf(searchNormalized); - if (pos === -1) { - throw new Error(`Text not found:\n${searchText}`); + // Helper to add context lines + function addContext(lines: string[], start: number, count: number) { + for (let i = 0; i < count && start + i < lines.length; i++) { + differ.push({ + type: 'context', + content: lines[start + i], + lineNumber: start + i + 1 + }); + } } - // Map back to original content position - const originalPos = content.slice(0, pos).replace(/[ \t]+/g, ' ').length; - const originalEnd = originalPos + searchText.length; + // Find the differences using longest common subsequence + const changes: Array<{type: 'context' | 'addition' | 'deletion', line: string, index: number}> = []; + let i = 0, j = 0; - return { - start: pos, - end: originalEnd, - lineNumber: normalized.slice(0, pos).split('\n').length - }; -} + while (i < originalLines.length || j < newLines.length) { + if (i < originalLines.length && j < newLines.length && originalLines[i] === newLines[j]) { + changes.push({type: 'context', line: originalLines[i], index: i}); + i++; + j++; + } else { + if (i < originalLines.length) { + changes.push({type: 'deletion', line: originalLines[i], index: i}); + i++; + } + if (j < newLines.length) { + changes.push({type: 'addition', line: newLines[j], index: j}); + j++; + } + } + } -// Edit preview type -interface EditPreview { - original: string; - modified: string; - lineNumber: number; - preview: string; // Git-style diff format -} + // Group changes into hunks with context + let currentHunk: DiffLine[] = []; + let hunks: DiffLine[][] = []; + let lastChangeIndex = -1; -// File editing utilities -async function applyFileEdits(filePath: string, edits: Array<{oldText: string, newText: string}>, dryRun = false): Promise { - let content = await fs.readFile(filePath, 'utf-8'); - const previews: EditPreview[] = []; - - // Find all positions first - const positions = edits.map(edit => ({ - edit, - position: findTextPosition(content, edit.oldText) - })); - - // Sort by position in reverse order - positions.sort((a, b) => b.position.start - a.position.start); - - // Apply edits from end to start - for (const {edit, position} of positions) { - const preview = [ - `@@ line ${position.lineNumber} @@`, - '<<<<<<< ORIGINAL', - edit.oldText, - '=======', - edit.newText, - '>>>>>>> MODIFIED' - ].join('\n'); + for (let i = 0; i < changes.length; i++) { + const change = changes[i]; - previews.push({ - original: edit.oldText, - modified: edit.newText, - lineNumber: position.lineNumber, - preview - }); - - if (!dryRun) { - content = content.slice(0, position.start) + edit.newText + content.slice(position.end); + if (change.type !== 'context' || + (lastChangeIndex >= 0 && i - lastChangeIndex <= contextSize * 2)) { + if (change.type !== 'context') { + lastChangeIndex = i; + } + currentHunk.push({ + type: change.type, + content: change.line, + lineNumber: change.index + 1 + }); + } else { + if (currentHunk.length > 0) { + hunks.push(currentHunk); + currentHunk = []; + } } } - return dryRun ? previews : content; + if (currentHunk.length > 0) { + hunks.push(currentHunk); + } + + // Format the diff output + let diffOutput = ''; + + for (const hunk of hunks) { + const startLine = hunk[0].lineNumber; + const endLine = hunk[hunk.length - 1].lineNumber; + + diffOutput += `@@ -${startLine},${endLine} @@\n`; + + for (const line of hunk) { + const prefix = line.type === 'addition' ? '+' : + line.type === 'deletion' ? '-' : ' '; + diffOutput += `${prefix}${line.content}\n`; + } + + diffOutput += '\n'; + } + + return diffOutput; +} + +// File editing utilities +async function applyFileEdits( + filePath: string, + edits: Array<{oldText: string, newText: string}>, + dryRun = false +): Promise { + let content = await fs.readFile(filePath, 'utf-8'); + const originalLines = content.split('\n'); + let modifiedContent = content; + + // First, validate all edits can be applied + const positions = edits.map(edit => { + const pos = modifiedContent.indexOf(edit.oldText); + if (pos === -1) { + throw new Error(`Text not found:\n${edit.oldText}`); + } + return { + edit, + position: pos, + length: edit.oldText.length + }; + }); + + // Sort positions in reverse order to apply from end to start + positions.sort((a, b) => b.position - a.position); + + if (dryRun) { + // For dry run, create a unified diff preview + for (const {edit, position} of positions) { + modifiedContent = + modifiedContent.slice(0, position) + + edit.newText + + modifiedContent.slice(position + edit.oldText.length); + } + + const modifiedLines = modifiedContent.split('\n'); + return createUnifiedDiff(originalLines, modifiedLines); + } else { + // Apply the edits + for (const {edit, position} of positions) { + modifiedContent = + modifiedContent.slice(0, position) + + edit.newText + + modifiedContent.slice(position + edit.oldText.length); + } + return modifiedContent; + } } // Tool handlers @@ -325,9 +392,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { { name: "edit_file", description: - "Make selective edits to a text file using simple search and replace with git-style preview format. " + - "Finds text to replace using substring matching and shows changes in a familiar git-diff format. " + - "Use dry run mode to preview changes before applying them. " + + "Make selective edits to a text file using search and replace with unified diff previews. " + + "Shows changes in standard unified diff format with context lines, similar to git diff. " + + "Use dry run mode to preview changes in patch format before applying them. " + "Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, }, @@ -452,15 +519,14 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { const validPath = await validatePath(parsed.data.path); const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun); - // If it's a dry run, format the previews + // If it's a dry run, show the unified diff if (parsed.data.dryRun) { - const previewText = (result as EditPreview[]).map(preview => preview.preview).join('\n\n'); return { - content: [{ type: "text", text: `Edit preview:\n${previewText}` }], + content: [{ type: "text", text: `Edit preview:\n${result}` }], }; } - await fs.writeFile(validPath, result as string, "utf-8"); + await fs.writeFile(validPath, result, "utf-8"); return { content: [{ type: "text", text: `Successfully applied edits to ${parsed.data.path}` }], }; From b6e052946a091cb053ff08c418dd65d0498926e5 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 20:13:58 -0800 Subject: [PATCH 26/63] use the diff package, aider inspired search --- src/filesystem/index.ts | 357 +++++++++++++++++++++++------------- src/filesystem/package.json | 4 +- 2 files changed, 229 insertions(+), 132 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 3306f315..88f68ab3 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -12,6 +12,7 @@ import path from "path"; import os from 'os'; import { z } from "zod"; import { zodToJsonSchema } from "zod-to-json-schema"; +import { diffLines, createTwoFilesPatch } from 'diff'; // Command line argument parsing const args = process.argv.slice(2); @@ -216,146 +217,238 @@ async function searchFiles( return results; } -interface DiffLine { - type: 'context' | 'addition' | 'deletion'; - content: string; - lineNumber: number; +// file editing and diffing utilities +function createUnifiedDiff(originalContent: string, newContent: string, filepath: string = 'file'): string { + return createTwoFilesPatch( + filepath, + filepath, + originalContent, + newContent, + 'original', + 'modified' + ); } -function createUnifiedDiff(originalLines: string[], newLines: string[], contextSize: number = 3): string { - const differ = new Array(); - let lineNumber = 1; - - // Helper to add context lines - function addContext(lines: string[], start: number, count: number) { - for (let i = 0; i < count && start + i < lines.length; i++) { - differ.push({ - type: 'context', - content: lines[start + i], - lineNumber: start + i + 1 - }); - } - } - - // Find the differences using longest common subsequence - const changes: Array<{type: 'context' | 'addition' | 'deletion', line: string, index: number}> = []; - let i = 0, j = 0; - - while (i < originalLines.length || j < newLines.length) { - if (i < originalLines.length && j < newLines.length && originalLines[i] === newLines[j]) { - changes.push({type: 'context', line: originalLines[i], index: i}); - i++; - j++; - } else { - if (i < originalLines.length) { - changes.push({type: 'deletion', line: originalLines[i], index: i}); - i++; - } - if (j < newLines.length) { - changes.push({type: 'addition', line: newLines[j], index: j}); - j++; - } - } - } - - // Group changes into hunks with context - let currentHunk: DiffLine[] = []; - let hunks: DiffLine[][] = []; - let lastChangeIndex = -1; - - for (let i = 0; i < changes.length; i++) { - const change = changes[i]; - - if (change.type !== 'context' || - (lastChangeIndex >= 0 && i - lastChangeIndex <= contextSize * 2)) { - if (change.type !== 'context') { - lastChangeIndex = i; - } - currentHunk.push({ - type: change.type, - content: change.line, - lineNumber: change.index + 1 - }); - } else { - if (currentHunk.length > 0) { - hunks.push(currentHunk); - currentHunk = []; - } - } - } - - if (currentHunk.length > 0) { - hunks.push(currentHunk); - } - - // Format the diff output - let diffOutput = ''; - - for (const hunk of hunks) { - const startLine = hunk[0].lineNumber; - const endLine = hunk[hunk.length - 1].lineNumber; - - diffOutput += `@@ -${startLine},${endLine} @@\n`; - - for (const line of hunk) { - const prefix = line.type === 'addition' ? '+' : - line.type === 'deletion' ? '-' : ' '; - diffOutput += `${prefix}${line.content}\n`; - } - - diffOutput += '\n'; - } - - return diffOutput; +// Utility functions for text normalization and matching +function normalizeLineEndings(text: string): string { + return text.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); } -// File editing utilities -async function applyFileEdits( - filePath: string, - edits: Array<{oldText: string, newText: string}>, - dryRun = false -): Promise { - let content = await fs.readFile(filePath, 'utf-8'); - const originalLines = content.split('\n'); - let modifiedContent = content; +function normalizeWhitespace(text: string, preserveIndentation: boolean = true): string { + if (!preserveIndentation) { + // Collapse all whitespace to single spaces if not preserving indentation + return text.replace(/\s+/g, ' '); + } - // First, validate all edits can be applied - const positions = edits.map(edit => { - const pos = modifiedContent.indexOf(edit.oldText); - if (pos === -1) { - throw new Error(`Text not found:\n${edit.oldText}`); - } + // Preserve line structure but normalize inline whitespace + return text.split('\n').map(line => { + // Preserve leading whitespace + const indent = line.match(/^[\s\t]*/)?.[0] || ''; + // Normalize rest of line + const content = line.slice(indent.length).trim().replace(/\s+/g, ' '); + return indent + content; + }).join('\n'); +} + +interface EditOptions { + preserveIndentation?: boolean; + normalizeWhitespace?: boolean; + partialMatch?: boolean; +} + +interface EditMatch { + start: number; + end: number; + confidence: number; +} + +function findBestMatch(content: string, searchText: string, options: EditOptions): EditMatch | null { + const normalizedContent = normalizeLineEndings(content); + const normalizedSearch = normalizeLineEndings(searchText); + + // Try exact match first + const exactPos = normalizedContent.indexOf(normalizedSearch); + if (exactPos !== -1) { return { - edit, - position: pos, - length: edit.oldText.length + start: exactPos, + end: exactPos + searchText.length, + confidence: 1.0 }; - }); - - // Sort positions in reverse order to apply from end to start - positions.sort((a, b) => b.position - a.position); - - if (dryRun) { - // For dry run, create a unified diff preview - for (const {edit, position} of positions) { - modifiedContent = - modifiedContent.slice(0, position) + - edit.newText + - modifiedContent.slice(position + edit.oldText.length); + } + + // If whitespace normalization is enabled, try that next + if (options.normalizeWhitespace) { + const normContent = normalizeWhitespace(normalizedContent, options.preserveIndentation); + const normSearch = normalizeWhitespace(normalizedSearch, options.preserveIndentation); + const normPos = normContent.indexOf(normSearch); + + if (normPos !== -1) { + // Find the corresponding position in original text + const beforeMatch = normContent.slice(0, normPos); + const originalPos = findOriginalPosition(content, beforeMatch); + return { + start: originalPos, + end: originalPos + searchText.length, + confidence: 0.9 + }; + } + } + + // If partial matching is enabled, try to find the best partial match + if (options.partialMatch) { + const lines = normalizedContent.split('\n'); + const searchLines = normalizedSearch.split('\n'); + + let bestMatch: EditMatch | null = null; + let bestScore = 0; + + // Sliding window search through the content + for (let i = 0; i < lines.length - searchLines.length + 1; i++) { + let matchScore = 0; + let matchLength = 0; + + for (let j = 0; j < searchLines.length; j++) { + const contentLine = options.normalizeWhitespace + ? normalizeWhitespace(lines[i + j], options.preserveIndentation) + : lines[i + j]; + const searchLine = options.normalizeWhitespace + ? normalizeWhitespace(searchLines[j], options.preserveIndentation) + : searchLines[j]; + + const similarity = calculateSimilarity(contentLine, searchLine); + matchScore += similarity; + matchLength += lines[i + j].length + 1; // +1 for newline + } + + const averageScore = matchScore / searchLines.length; + if (averageScore > bestScore && averageScore > 0.7) { // Threshold for minimum match quality + bestScore = averageScore; + const start = lines.slice(0, i).reduce((acc, line) => acc + line.length + 1, 0); + bestMatch = { + start, + end: start + matchLength, + confidence: averageScore + }; + } } - const modifiedLines = modifiedContent.split('\n'); - return createUnifiedDiff(originalLines, modifiedLines); - } else { - // Apply the edits - for (const {edit, position} of positions) { - modifiedContent = - modifiedContent.slice(0, position) + - edit.newText + - modifiedContent.slice(position + edit.oldText.length); - } - return modifiedContent; + return bestMatch; } + + return null; +} + +function calculateSimilarity(str1: string, str2: string): number { + const len1 = str1.length; + const len2 = str2.length; + const matrix: number[][] = Array(len1 + 1).fill(null).map(() => Array(len2 + 1).fill(0)); + + for (let i = 0; i <= len1; i++) matrix[i][0] = i; + for (let j = 0; j <= len2; j++) matrix[0][j] = j; + + for (let i = 1; i <= len1; i++) { + for (let j = 1; j <= len2; j++) { + const cost = str1[i - 1] === str2[j - 1] ? 0 : 1; + matrix[i][j] = Math.min( + matrix[i - 1][j] + 1, + matrix[i][j - 1] + 1, + matrix[i - 1][j - 1] + cost + ); + } + } + + const maxLength = Math.max(len1, len2); + return maxLength === 0 ? 1 : (maxLength - matrix[len1][len2]) / maxLength; +} + +function findOriginalPosition(original: string, normalizedPrefix: string): number { + let origPos = 0; + let normPos = 0; + + while (normPos < normalizedPrefix.length && origPos < original.length) { + if (normalizeWhitespace(original[origPos], true) === normalizedPrefix[normPos]) { + normPos++; + } + origPos++; + } + + return origPos; +} + +async function applyFileEdits( + filePath: string, + edits: Array<{oldText: string, newText: string}>, + dryRun = false, + options: EditOptions = { + preserveIndentation: true, + normalizeWhitespace: true, + partialMatch: true + } +): Promise { + const content = await fs.readFile(filePath, 'utf-8'); + let modifiedContent = content; + const failedEdits: Array<{edit: typeof edits[0], error: string}> = []; + const successfulEdits: Array<{edit: typeof edits[0], match: EditMatch}> = []; + + // Sort edits by position (if found) to apply them in order + for (const edit of edits) { + const match = findBestMatch(modifiedContent, edit.oldText, options); + + if (!match) { + failedEdits.push({ + edit, + error: 'No suitable match found' + }); + continue; + } + + // For low confidence matches in non-dry-run mode, we might want to throw + if (!dryRun && match.confidence < 0.8) { + failedEdits.push({ + edit, + error: `Match confidence too low: ${(match.confidence * 100).toFixed(1)}%` + }); + continue; + } + + successfulEdits.push({ edit, match }); + } + + // Sort successful edits by position (reverse order to maintain positions) + successfulEdits.sort((a, b) => b.match.start - a.match.start); + + // Apply successful edits + for (const { edit, match } of successfulEdits) { + modifiedContent = + modifiedContent.slice(0, match.start) + + edit.newText + + modifiedContent.slice(match.end); + } + + if (dryRun) { + let report = createUnifiedDiff(content, modifiedContent, filePath); + + if (failedEdits.length > 0) { + report += '\nFailed edits:\n' + failedEdits.map(({ edit, error }) => + `- Error: ${error}\n Old text: ${edit.oldText.split('\n')[0]}...\n` + ).join('\n'); + } + + if (successfulEdits.length > 0) { + report += '\nSuccessful edits:\n' + successfulEdits.map(({ edit, match }) => + `- Match confidence: ${(match.confidence * 100).toFixed(1)}%\n Position: ${match.start}-${match.end}\n` + ).join('\n'); + } + + return report; + } + + if (failedEdits.length > 0) { + const errors = failedEdits.map(({ error }) => error).join('\n'); + throw new Error(`Some edits failed:\n${errors}`); + } + + return modifiedContent; } // Tool handlers @@ -392,8 +485,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { { name: "edit_file", description: - "Make selective edits to a text file using search and replace with unified diff previews. " + + "Make selective edits to a text file using line-based pattern matching and replacement. " + + "Handles both single-line and multi-line edits, with smart positioning to handle multiple edits simultaneously. " + "Shows changes in standard unified diff format with context lines, similar to git diff. " + + "Provides detailed diff output for failed matches to aid debugging. " + "Use dry run mode to preview changes in patch format before applying them. " + "Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, diff --git a/src/filesystem/package.json b/src/filesystem/package.json index 581ad818..8229e0d5 100644 --- a/src/filesystem/package.json +++ b/src/filesystem/package.json @@ -20,12 +20,14 @@ }, "dependencies": { "@modelcontextprotocol/sdk": "0.5.0", + "diff": "^5.1.0", "glob": "^10.3.10", "zod-to-json-schema": "^3.23.5" }, "devDependencies": { + "@types/diff": "^5.0.9", "@types/node": "^20.11.0", "shx": "^0.3.4", "typescript": "^5.3.3" } -} +} \ No newline at end of file From b04c9334bc6abef848816080c3526ff7f43cdfaf Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 20:45:43 -0800 Subject: [PATCH 27/63] schema def issues --- src/filesystem/index.ts | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 88f68ab3..a3ce7f04 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -114,13 +114,23 @@ const EditOperation = z.object({ newText: z.string().describe('Text to replace the found text with'), }); +const EditOptions = z.object({ + preserveIndentation: z.boolean().default(true).describe('Preserve existing indentation patterns in the file'), + normalizeWhitespace: z.boolean().default(true).describe('Normalize whitespace while preserving structure'), + partialMatch: z.boolean().default(true).describe('Enable fuzzy matching with confidence scoring') +}); + const EditFileArgsSchema = z.object({ path: z.string(), edits: z.array(EditOperation), // Optional: preview changes without applying them - dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') + dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format'), + // Optional: configure matching and formatting behavior + options: EditOptions.default({}) }); + + const CreateDirectoryArgsSchema = z.object({ path: z.string(), }); @@ -250,19 +260,13 @@ function normalizeWhitespace(text: string, preserveIndentation: boolean = true): }).join('\n'); } -interface EditOptions { - preserveIndentation?: boolean; - normalizeWhitespace?: boolean; - partialMatch?: boolean; -} - interface EditMatch { start: number; end: number; confidence: number; } -function findBestMatch(content: string, searchText: string, options: EditOptions): EditMatch | null { +function findBestMatch(content: string, searchText: string, options: z.infer): EditMatch | null { const normalizedContent = normalizeLineEndings(content); const normalizedSearch = normalizeLineEndings(searchText); @@ -379,11 +383,7 @@ async function applyFileEdits( filePath: string, edits: Array<{oldText: string, newText: string}>, dryRun = false, - options: EditOptions = { - preserveIndentation: true, - normalizeWhitespace: true, - partialMatch: true - } + options: z.infer = EditOptions.parse({}) ): Promise { const content = await fs.readFile(filePath, 'utf-8'); let modifiedContent = content; @@ -485,12 +485,17 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { { name: "edit_file", description: - "Make selective edits to a text file using line-based pattern matching and replacement. " + - "Handles both single-line and multi-line edits, with smart positioning to handle multiple edits simultaneously. " + - "Shows changes in standard unified diff format with context lines, similar to git diff. " + - "Provides detailed diff output for failed matches to aid debugging. " + - "Use dry run mode to preview changes in patch format before applying them. " + - "Only works within allowed directories.", + "Make selective edits to a text file using advanced pattern matching and smart formatting preservation. Features include:\n" + + "- Line-based and multi-line content matching\n" + + "- Whitespace normalization with indentation preservation\n" + + "- Fuzzy matching with confidence scoring\n" + + "- Multiple simultaneous edits with correct positioning\n" + + "- Indentation style detection and preservation\n" + + "- Detailed diff output with context in git format\n" + + "- Dry run mode for previewing changes\n" + + "- Failed match debugging with match confidence scores\n\n" + + "Configure behavior with options.preserveIndentation, options.normalizeWhitespace, and options.partialMatch. " + + "See schema for detailed option descriptions. Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, }, { @@ -612,7 +617,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { throw new Error(`Invalid arguments for edit_file: ${parsed.error}`); } const validPath = await validatePath(parsed.data.path); - const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun); + const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun, parsed.data.options); // If it's a dry run, show the unified diff if (parsed.data.dryRun) { From 7417d4dc075a702d7fc61eae55a540c8521dd171 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Wed, 4 Dec 2024 20:51:39 -0800 Subject: [PATCH 28/63] update read me for current impl --- src/filesystem/README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/filesystem/README.md b/src/filesystem/README.md index 31995d8f..37bc290f 100644 --- a/src/filesystem/README.md +++ b/src/filesystem/README.md @@ -37,23 +37,28 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio - `content` (string): File content - **edit_file** - - Make selective edits using search and replace + - Make selective edits using advanced pattern matching and formatting - Features: - - Simple substring matching for finding text - - Git-style preview format for changes + - Line-based and multi-line content matching + - Whitespace normalization with indentation preservation + - Fuzzy matching with confidence scoring + - Multiple simultaneous edits with correct positioning + - Indentation style detection and preservation + - Git-style diff output with context - Preview changes with dry run mode - - Preserves consistent indentation patterns - - Limitations: - - Intended for content changes, not code formatting - - Mixed tabs/spaces can cause pattern matching issues - - Use code formatters (e.g., Prettier, ESLint) before content edits + - Failed match debugging with confidence scores - Inputs: - `path` (string): File to edit - `edits` (array): List of edit operations - `oldText` (string): Text to search for (can be substring) - `newText` (string): Text to replace with - - `dryRun` (boolean): Preview changes without applying (default: false) - - Returns preview information for dry runs, otherwise applies changes + - `dryRun` (boolean): Preview changes without applying (default: false) + - `options` (object): Optional formatting settings + - `preserveIndentation` (boolean): Keep existing indentation (default: true) + - `normalizeWhitespace` (boolean): Normalize spaces while preserving structure (default: true) + - `partialMatch` (boolean): Enable fuzzy matching (default: true) + - Returns detailed diff and match information for dry runs, otherwise applies changes + - Best Practice: Always use dryRun first to preview changes before applying them - **create_directory** - Create new directory or ensure it exists From b477af5c0404bf53d6643f73fda1e126dd27a935 Mon Sep 17 00:00:00 2001 From: Marc Goodner Date: Thu, 5 Dec 2024 00:33:49 -0800 Subject: [PATCH 29/63] seriously, like aider --- src/filesystem/index.ts | 308 ++++++++++------------------------------ 1 file changed, 76 insertions(+), 232 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index a3ce7f04..23d989d0 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -108,29 +108,16 @@ const WriteFileArgsSchema = z.object({ }); const EditOperation = z.object({ - // The text to search for - oldText: z.string().describe('Text to search for - can be a substring of the target'), - // The new text to replace with - newText: z.string().describe('Text to replace the found text with'), -}); - -const EditOptions = z.object({ - preserveIndentation: z.boolean().default(true).describe('Preserve existing indentation patterns in the file'), - normalizeWhitespace: z.boolean().default(true).describe('Normalize whitespace while preserving structure'), - partialMatch: z.boolean().default(true).describe('Enable fuzzy matching with confidence scoring') + oldText: z.string().describe('Text to search for - must match exactly'), + newText: z.string().describe('Text to replace with') }); const EditFileArgsSchema = z.object({ path: z.string(), edits: z.array(EditOperation), - // Optional: preview changes without applying them - dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format'), - // Optional: configure matching and formatting behavior - options: EditOptions.default({}) + dryRun: z.boolean().default(false).describe('Preview changes using git-style diff format') }); - - const CreateDirectoryArgsSchema = z.object({ path: z.string(), }); @@ -228,227 +215,101 @@ async function searchFiles( } // file editing and diffing utilities +function normalizeLineEndings(text: string): string { + return text.replace(/\r\n/g, '\n'); +} + function createUnifiedDiff(originalContent: string, newContent: string, filepath: string = 'file'): string { + // Ensure consistent line endings for diff + const normalizedOriginal = normalizeLineEndings(originalContent); + const normalizedNew = normalizeLineEndings(newContent); + return createTwoFilesPatch( filepath, filepath, - originalContent, - newContent, + normalizedOriginal, + normalizedNew, 'original', 'modified' ); } -// Utility functions for text normalization and matching -function normalizeLineEndings(text: string): string { - return text.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); -} - -function normalizeWhitespace(text: string, preserveIndentation: boolean = true): string { - if (!preserveIndentation) { - // Collapse all whitespace to single spaces if not preserving indentation - return text.replace(/\s+/g, ' '); - } - - // Preserve line structure but normalize inline whitespace - return text.split('\n').map(line => { - // Preserve leading whitespace - const indent = line.match(/^[\s\t]*/)?.[0] || ''; - // Normalize rest of line - const content = line.slice(indent.length).trim().replace(/\s+/g, ' '); - return indent + content; - }).join('\n'); -} - -interface EditMatch { - start: number; - end: number; - confidence: number; -} - -function findBestMatch(content: string, searchText: string, options: z.infer): EditMatch | null { - const normalizedContent = normalizeLineEndings(content); - const normalizedSearch = normalizeLineEndings(searchText); - - // Try exact match first - const exactPos = normalizedContent.indexOf(normalizedSearch); - if (exactPos !== -1) { - return { - start: exactPos, - end: exactPos + searchText.length, - confidence: 1.0 - }; - } - - // If whitespace normalization is enabled, try that next - if (options.normalizeWhitespace) { - const normContent = normalizeWhitespace(normalizedContent, options.preserveIndentation); - const normSearch = normalizeWhitespace(normalizedSearch, options.preserveIndentation); - const normPos = normContent.indexOf(normSearch); - - if (normPos !== -1) { - // Find the corresponding position in original text - const beforeMatch = normContent.slice(0, normPos); - const originalPos = findOriginalPosition(content, beforeMatch); - return { - start: originalPos, - end: originalPos + searchText.length, - confidence: 0.9 - }; - } - } - - // If partial matching is enabled, try to find the best partial match - if (options.partialMatch) { - const lines = normalizedContent.split('\n'); - const searchLines = normalizedSearch.split('\n'); - - let bestMatch: EditMatch | null = null; - let bestScore = 0; - - // Sliding window search through the content - for (let i = 0; i < lines.length - searchLines.length + 1; i++) { - let matchScore = 0; - let matchLength = 0; - - for (let j = 0; j < searchLines.length; j++) { - const contentLine = options.normalizeWhitespace - ? normalizeWhitespace(lines[i + j], options.preserveIndentation) - : lines[i + j]; - const searchLine = options.normalizeWhitespace - ? normalizeWhitespace(searchLines[j], options.preserveIndentation) - : searchLines[j]; - - const similarity = calculateSimilarity(contentLine, searchLine); - matchScore += similarity; - matchLength += lines[i + j].length + 1; // +1 for newline - } - - const averageScore = matchScore / searchLines.length; - if (averageScore > bestScore && averageScore > 0.7) { // Threshold for minimum match quality - bestScore = averageScore; - const start = lines.slice(0, i).reduce((acc, line) => acc + line.length + 1, 0); - bestMatch = { - start, - end: start + matchLength, - confidence: averageScore - }; - } - } - - return bestMatch; - } - - return null; -} - -function calculateSimilarity(str1: string, str2: string): number { - const len1 = str1.length; - const len2 = str2.length; - const matrix: number[][] = Array(len1 + 1).fill(null).map(() => Array(len2 + 1).fill(0)); - - for (let i = 0; i <= len1; i++) matrix[i][0] = i; - for (let j = 0; j <= len2; j++) matrix[0][j] = j; - - for (let i = 1; i <= len1; i++) { - for (let j = 1; j <= len2; j++) { - const cost = str1[i - 1] === str2[j - 1] ? 0 : 1; - matrix[i][j] = Math.min( - matrix[i - 1][j] + 1, - matrix[i][j - 1] + 1, - matrix[i - 1][j - 1] + cost - ); - } - } - - const maxLength = Math.max(len1, len2); - return maxLength === 0 ? 1 : (maxLength - matrix[len1][len2]) / maxLength; -} - -function findOriginalPosition(original: string, normalizedPrefix: string): number { - let origPos = 0; - let normPos = 0; - - while (normPos < normalizedPrefix.length && origPos < original.length) { - if (normalizeWhitespace(original[origPos], true) === normalizedPrefix[normPos]) { - normPos++; - } - origPos++; - } - - return origPos; -} - async function applyFileEdits( filePath: string, edits: Array<{oldText: string, newText: string}>, - dryRun = false, - options: z.infer = EditOptions.parse({}) + dryRun = false ): Promise { - const content = await fs.readFile(filePath, 'utf-8'); + // Read file content and normalize line endings + const content = normalizeLineEndings(await fs.readFile(filePath, 'utf-8')); + + // Apply edits sequentially let modifiedContent = content; - const failedEdits: Array<{edit: typeof edits[0], error: string}> = []; - const successfulEdits: Array<{edit: typeof edits[0], match: EditMatch}> = []; - - // Sort edits by position (if found) to apply them in order for (const edit of edits) { - const match = findBestMatch(modifiedContent, edit.oldText, options); + const normalizedOld = normalizeLineEndings(edit.oldText); + const normalizedNew = normalizeLineEndings(edit.newText); - if (!match) { - failedEdits.push({ - edit, - error: 'No suitable match found' - }); + // If exact match exists, use it + if (modifiedContent.includes(normalizedOld)) { + modifiedContent = modifiedContent.replace(normalizedOld, normalizedNew); continue; } - // For low confidence matches in non-dry-run mode, we might want to throw - if (!dryRun && match.confidence < 0.8) { - failedEdits.push({ - edit, - error: `Match confidence too low: ${(match.confidence * 100).toFixed(1)}%` + // Otherwise, try line-by-line matching with flexibility for whitespace + const oldLines = normalizedOld.split('\n'); + const contentLines = modifiedContent.split('\n'); + let matchFound = false; + + for (let i = 0; i <= contentLines.length - oldLines.length; i++) { + const potentialMatch = contentLines.slice(i, i + oldLines.length); + + // Compare lines with normalized whitespace + const isMatch = oldLines.every((oldLine, j) => { + const contentLine = potentialMatch[j]; + return oldLine.trim() === contentLine.trim(); }); - continue; + + if (isMatch) { + // Preserve original indentation of first line + const originalIndent = contentLines[i].match(/^\s*/)?.[0] || ''; + const newLines = normalizedNew.split('\n').map((line, j) => { + if (j === 0) return originalIndent + line.trimStart(); + // For subsequent lines, try to preserve relative indentation + const oldIndent = oldLines[j]?.match(/^\s*/)?.[0] || ''; + const newIndent = line.match(/^\s*/)?.[0] || ''; + if (oldIndent && newIndent) { + const relativeIndent = newIndent.length - oldIndent.length; + return originalIndent + ' '.repeat(Math.max(0, relativeIndent)) + line.trimStart(); + } + return line; + }); + + contentLines.splice(i, oldLines.length, ...newLines); + modifiedContent = contentLines.join('\n'); + matchFound = true; + break; + } } - successfulEdits.push({ edit, match }); - } - - // Sort successful edits by position (reverse order to maintain positions) - successfulEdits.sort((a, b) => b.match.start - a.match.start); - - // Apply successful edits - for (const { edit, match } of successfulEdits) { - modifiedContent = - modifiedContent.slice(0, match.start) + - edit.newText + - modifiedContent.slice(match.end); - } - - if (dryRun) { - let report = createUnifiedDiff(content, modifiedContent, filePath); - - if (failedEdits.length > 0) { - report += '\nFailed edits:\n' + failedEdits.map(({ edit, error }) => - `- Error: ${error}\n Old text: ${edit.oldText.split('\n')[0]}...\n` - ).join('\n'); + if (!matchFound) { + throw new Error(`Could not find exact match for edit:\n${edit.oldText}`); } - - if (successfulEdits.length > 0) { - report += '\nSuccessful edits:\n' + successfulEdits.map(({ edit, match }) => - `- Match confidence: ${(match.confidence * 100).toFixed(1)}%\n Position: ${match.start}-${match.end}\n` - ).join('\n'); - } - - return report; } - if (failedEdits.length > 0) { - const errors = failedEdits.map(({ error }) => error).join('\n'); - throw new Error(`Some edits failed:\n${errors}`); + // Create unified diff + const diff = createUnifiedDiff(content, modifiedContent, filePath); + + // Format diff with appropriate number of backticks + let numBackticks = 3; + while (diff.includes('`'.repeat(numBackticks))) { + numBackticks++; + } + const formattedDiff = `${'`'.repeat(numBackticks)}diff\n${diff}${'`'.repeat(numBackticks)}\n\n`; + + if (!dryRun) { + await fs.writeFile(filePath, modifiedContent, 'utf-8'); } - return modifiedContent; + return formattedDiff; } // Tool handlers @@ -485,17 +346,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { { name: "edit_file", description: - "Make selective edits to a text file using advanced pattern matching and smart formatting preservation. Features include:\n" + - "- Line-based and multi-line content matching\n" + - "- Whitespace normalization with indentation preservation\n" + - "- Fuzzy matching with confidence scoring\n" + - "- Multiple simultaneous edits with correct positioning\n" + - "- Indentation style detection and preservation\n" + - "- Detailed diff output with context in git format\n" + - "- Dry run mode for previewing changes\n" + - "- Failed match debugging with match confidence scores\n\n" + - "Configure behavior with options.preserveIndentation, options.normalizeWhitespace, and options.partialMatch. " + - "See schema for detailed option descriptions. Only works within allowed directories.", + "Make line-based edits to a text file. Each edit replaces exact line sequences " + + "with new content. Returns a git-style diff showing the changes made. " + + "Only works within allowed directories.", inputSchema: zodToJsonSchema(EditFileArgsSchema) as ToolInput, }, { @@ -617,18 +470,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { throw new Error(`Invalid arguments for edit_file: ${parsed.error}`); } const validPath = await validatePath(parsed.data.path); - const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun, parsed.data.options); - - // If it's a dry run, show the unified diff - if (parsed.data.dryRun) { - return { - content: [{ type: "text", text: `Edit preview:\n${result}` }], - }; - } - - await fs.writeFile(validPath, result, "utf-8"); + const result = await applyFileEdits(validPath, parsed.data.edits, parsed.data.dryRun); return { - content: [{ type: "text", text: `Successfully applied edits to ${parsed.data.path}` }], + content: [{ type: "text", text: result }], }; } From 3b71d48f65939d322f44edf7a98dd5ab153a7987 Mon Sep 17 00:00:00 2001 From: Raduan77 Date: Thu, 5 Dec 2024 11:37:51 +0100 Subject: [PATCH 30/63] address comment --- src/github/schemas.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/github/schemas.ts b/src/github/schemas.ts index f6b98727..b9c81a15 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -537,10 +537,6 @@ export const SearchCodeSchema = z.object({ .describe( "Search query. See GitHub code search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code" ), - sort: z - .enum(["", "indexed"]) - .optional() - .describe("Sort field. Only 'indexed' is supported"), order: z .enum(["asc", "desc"]) .optional() From e8f08ac4794f9f5946adf301b20ab86f4b8dc6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hor=C3=A1k?= <162463026+jhhxgn@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:33:11 +0100 Subject: [PATCH 31/63] Fixed Readme link to sequential thinking server --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78f569f1..f4706613 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ These servers aim to demonstrate MCP features and the Typescript and Python SDK. - **[PostgreSQL](src/postgres)** - Read-only database access with schema inspection - **[Puppeteer](src/puppeteer)** - Browser automation and web scraping - **[Sentry](src/sentry)** - Retrieving and analyzing issues from Sentry.io -- **[Sequential Thinking](src/sequential-thinking)** - Dynamic and reflective problem-solving through thought sequences +- **[Sequential Thinking](src/sequentialthinking)** - Dynamic and reflective problem-solving through thought sequences - **[Slack](src/slack)** - Channel management and messaging capabilities - **[Sqlite](src/sqlite)** - Database interaction and business intelligence capabilities From 852aebf30bc98516768b7b417416d82c12b3d4b5 Mon Sep 17 00:00:00 2001 From: AP Date: Thu, 5 Dec 2024 14:03:51 -0800 Subject: [PATCH 32/63] browserbase readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 822ab053..e5f41461 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ These servers aim to demonstrate MCP features and the Typescript and Python SDK. Official integrations are maintained by companies building production ready MCP servers for their platforms. +- Browserbase Logo **[Browserbase](https://github.com/browserbase/mcp-server-browserbase)** - Automate browser interactions in the cloud (e.g. web navigation, data extraction, form filling, and more) - **[Cloudflare](https://github.com/cloudflare/mcp-server-cloudflare)** - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1) - **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Interact with your crash reporting and real using monitoring data on your Raygun account - E2B Logo **[E2B](https://github.com/e2b-dev/mcp-server)** - Run code in secure sandboxes hosted by [E2B](https://e2b.dev) From 75e7fcea5824ab062077b158ebda353261b312ed Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 5 Dec 2024 22:55:41 +0000 Subject: [PATCH 33/63] `npm install` --- package-lock.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package-lock.json b/package-lock.json index c73f44ee..e06112f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4001,8 +4001,10 @@ "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "1.0.1", + "@types/node": "^20.11.0", "@types/node-fetch": "^2.6.12", "node-fetch": "^3.3.2", + "zod": "^3.22.4", "zod-to-json-schema": "^3.23.5" }, "bin": { @@ -4023,6 +4025,14 @@ "zod": "^3.23.8" } }, + "src/github/node_modules/@types/node": { + "version": "20.17.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.9.tgz", + "integrity": "sha512-0JOXkRyLanfGPE2QRCwgxhzlBAvaRdCNMcvbd7jFfpmD4eEXll7LRwy5ymJmyeZqk7Nh7eD2LeUyQ68BbndmXw==", + "dependencies": { + "undici-types": "~6.19.2" + } + }, "src/github/node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", From f7da6f41de04bf864de97470fb2422760a35c0d4 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 5 Dec 2024 23:15:48 +0000 Subject: [PATCH 34/63] `npm install` --- package-lock.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b0b19b05..fa9ec691 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1523,6 +1523,12 @@ "@types/node": "*" } }, + "node_modules/@types/diff": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.2.3.tgz", + "integrity": "sha512-K0Oqlrq3kQMaO2RhfrNQX5trmt+XLyom88zS0u84nnIcLvFnRUMRRHmrGny5GSM+kNO9IZLARsdQHDzkhAgmrQ==", + "dev": true + }, "node_modules/@types/express": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.0.tgz", @@ -2258,6 +2264,14 @@ "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1367902.tgz", "integrity": "sha512-XxtPuC3PGakY6PD7dG66/o8KwJ/LkH2/EKe19Dcw58w53dv4/vSQEkn/SzuyhHE2q4zPgCkxQBxus3VV4ql+Pg==" }, + "node_modules/diff": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", + "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/dotenv": { "version": "16.4.6", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.6.tgz", @@ -4983,6 +4997,7 @@ } }, "src/aws-kb-retrieval-server": { + "name": "@modelcontextprotocol/server-aws-kb-retrieval", "version": "0.6.2", "license": "MIT", "dependencies": { @@ -5167,7 +5182,8 @@ "version": "0.6.2", "license": "MIT", "dependencies": { - "@modelcontextprotocol/sdk": "1.0.1", + "@modelcontextprotocol/sdk": "0.5.0", + "diff": "^5.1.0", "glob": "^10.3.10", "zod-to-json-schema": "^3.23.5" }, @@ -5175,6 +5191,7 @@ "mcp-server-filesystem": "dist/index.js" }, "devDependencies": { + "@types/diff": "^5.0.9", "@types/node": "^20.11.0", "shx": "^0.3.4", "typescript": "^5.3.3" From 937df8818f9cbab794ba1f3597ad56bd459ce202 Mon Sep 17 00:00:00 2001 From: vrknetha Date: Fri, 6 Dec 2024 15:24:03 +0530 Subject: [PATCH 35/63] docs: add FireCrawl to community servers section --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e5f41461..b75d419f 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[FireCrawl](https://github.com/vrknetha/mcp-server-firecrawl)** - Advanced web scraping with JavaScript rendering, PDF support, and smart rate limiting ## 📚 Resources From ba301c4a66a35587075aa74c20113dcbe4fe05ed Mon Sep 17 00:00:00 2001 From: monkeydaichan Date: Sat, 7 Dec 2024 01:25:33 +0900 Subject: [PATCH 36/63] feat(git): add git_diff tool for branch comparison Added new git_diff tool to allow comparison between branches or commits. This adds the ability to compare branches directly through the MCP interface. --- src/git/README.md | 23 +++++++++++++++++------ src/git/src/mcp_server_git/server.py | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/git/README.md b/src/git/README.md index caf01294..c7862502 100644 --- a/src/git/README.md +++ b/src/git/README.md @@ -26,34 +26,41 @@ Please note that mcp-server-git is currently in early development. The functiona - `repo_path` (string): Path to Git repository - Returns: Diff output of staged changes -4. `git_commit` +4. `git_diff` + - Shows differences between branches or commits + - Inputs: + - `repo_path` (string): Path to Git repository + - `target` (string): Target branch or commit to compare with + - Returns: Diff output comparing current state with target + +5. `git_commit` - Records changes to the repository - Inputs: - `repo_path` (string): Path to Git repository - `message` (string): Commit message - Returns: Confirmation with new commit hash -5. `git_add` +6. `git_add` - Adds file contents to the staging area - Inputs: - `repo_path` (string): Path to Git repository - `files` (string[]): Array of file paths to stage - Returns: Confirmation of staged files -6. `git_reset` +7. `git_reset` - Unstages all staged changes - Input: - `repo_path` (string): Path to Git repository - Returns: Confirmation of reset operation -7. `git_log` +8. `git_log` - Shows the commit logs - Inputs: - `repo_path` (string): Path to Git repository - `max_count` (number, optional): Maximum number of commits to show (default: 10) - Returns: Array of commit entries with hash, author, date, and message -8. `git_create_branch` +9. `git_create_branch` - Creates a new branch - Inputs: - `repo_path` (string): Path to Git repository @@ -66,7 +73,7 @@ Please note that mcp-server-git is currently in early development. The functiona ### Using uv (recommended) When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will -use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *mcp-server-git*. +use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run _mcp-server-git_. ### Using PIP @@ -99,6 +106,7 @@ Add this to your `claude_desktop_config.json`: } } ``` +
@@ -112,6 +120,7 @@ Add this to your `claude_desktop_config.json`: } } ``` +
### Usage with [Zed](https://github.com/zed-industries/zed) @@ -131,6 +140,7 @@ Add to your Zed settings.json: } ], ``` +
@@ -146,6 +156,7 @@ Add to your Zed settings.json: } }, ``` +
## Debugging diff --git a/src/git/src/mcp_server_git/server.py b/src/git/src/mcp_server_git/server.py index 02fae584..ded3d41d 100644 --- a/src/git/src/mcp_server_git/server.py +++ b/src/git/src/mcp_server_git/server.py @@ -24,6 +24,10 @@ class GitDiffUnstaged(BaseModel): class GitDiffStaged(BaseModel): repo_path: str +class GitDiff(BaseModel): + repo_path: str + target: str + class GitCommit(BaseModel): repo_path: str message: str @@ -48,6 +52,7 @@ class GitTools(str, Enum): STATUS = "git_status" DIFF_UNSTAGED = "git_diff_unstaged" DIFF_STAGED = "git_diff_staged" + DIFF = "git_diff" COMMIT = "git_commit" ADD = "git_add" RESET = "git_reset" @@ -63,6 +68,9 @@ def git_diff_unstaged(repo: git.Repo) -> str: def git_diff_staged(repo: git.Repo) -> str: return repo.git.diff("--cached") +def git_diff(repo: git.Repo, target: str) -> str: + return repo.git.diff(target) + def git_commit(repo: git.Repo, message: str) -> str: commit = repo.index.commit(message) return f"Changes committed successfully with hash {commit.hexsha}" @@ -127,6 +135,11 @@ async def serve(repository: Path | None) -> None: description="Shows changes that are staged for commit", inputSchema=GitDiffStaged.schema(), ), + Tool( + name=GitTools.DIFF, + description="Shows differences between branches or commits", + inputSchema=GitDiff.schema(), + ), Tool( name=GitTools.COMMIT, description="Records changes to the repository", @@ -210,6 +223,13 @@ async def serve(repository: Path | None) -> None: text=f"Staged changes:\n{diff}" )] + case GitTools.DIFF: + diff = git_diff(repo, arguments["target"]) + return [TextContent( + type="text", + text=f"Diff with {arguments['target']}:\n{diff}" + )] + case GitTools.COMMIT: result = git_commit(repo, arguments["message"]) return [TextContent( @@ -254,4 +274,4 @@ async def serve(repository: Path | None) -> None: options = server.create_initialization_options() async with stdio_server() as (read_stream, write_stream): - await server.run(read_stream, write_stream, options, raise_exceptions=True) + await server.run(read_stream, write_stream, options, raise_exceptions=True) \ No newline at end of file From 4502810ac82091d87fe03b8b0cbbe76131094ea3 Mon Sep 17 00:00:00 2001 From: monkeydaichan Date: Sat, 7 Dec 2024 01:30:31 +0900 Subject: [PATCH 38/63] docs(git): fix README formatting Fixed unintended formatting changes in the git server README while keeping the new git_diff tool documentation. --- src/git/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/git/README.md b/src/git/README.md index c7862502..41fa0f26 100644 --- a/src/git/README.md +++ b/src/git/README.md @@ -106,7 +106,6 @@ Add this to your `claude_desktop_config.json`: } } ``` -
@@ -120,7 +119,6 @@ Add this to your `claude_desktop_config.json`: } } ``` -
### Usage with [Zed](https://github.com/zed-industries/zed) @@ -140,7 +138,6 @@ Add to your Zed settings.json: } ], ``` -
@@ -156,7 +153,6 @@ Add to your Zed settings.json: } }, ``` -
## Debugging From 768a5af80c7f02d8dbe82564a116514d7aa3786c Mon Sep 17 00:00:00 2001 From: monkeydaichan Date: Sat, 7 Dec 2024 01:32:46 +0900 Subject: [PATCH 39/63] docs(git): restore original README formatting and add git_diff doc Restored the original formatting while adding documentation for the new git_diff tool. No changes were made to the existing documentation structure. --- src/git/README.md | 2 +- src/git/src/mcp_server_git/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/git/README.md b/src/git/README.md index 41fa0f26..e7956f1f 100644 --- a/src/git/README.md +++ b/src/git/README.md @@ -73,7 +73,7 @@ Please note that mcp-server-git is currently in early development. The functiona ### Using uv (recommended) When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will -use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run _mcp-server-git_. +use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *mcp-server-git*. ### Using PIP diff --git a/src/git/src/mcp_server_git/server.py b/src/git/src/mcp_server_git/server.py index ded3d41d..fd802eaa 100644 --- a/src/git/src/mcp_server_git/server.py +++ b/src/git/src/mcp_server_git/server.py @@ -274,4 +274,4 @@ async def serve(repository: Path | None) -> None: options = server.create_initialization_options() async with stdio_server() as (read_stream, write_stream): - await server.run(read_stream, write_stream, options, raise_exceptions=True) \ No newline at end of file + await server.run(read_stream, write_stream, options, raise_exceptions=True) From d7c7d992372fc4493cbd62d31ed7138c445902b8 Mon Sep 17 00:00:00 2001 From: Cesar Alvernaz Date: Fri, 6 Dec 2024 18:57:07 +0000 Subject: [PATCH 40/63] alphavantage mcp server community --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45899a32..dffa14a8 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ A growing set of community-developed and maintained servers demonstrates various > **Note:** Community servers are **untested** and should be used at **your own risk**. They are not affiliated with or endorsed by Anthropic. - **[MCP Installer](https://github.com/anaisbetts/mcp-installer)** - This server is a server that installs other MCP servers for you. -- **[Spotify MCP](https://github.com/varunneal/spotify-mcp)** - This MCP allows an LLM to play and use Spotify. +- **[Spotify MCP](https://github.com/varunneal/spotify-mcp)** - This MCP allows an LLM to play and use Spotify. - **[Inoyu](https://github.com/sergehuber/inoyu-mcp-unomi-server)** - Interact with an Apache Unomi CDP customer data platform to retrieve and update customer profiles - **[MySQL](https://github.com/designcomputer/mysql_mcp_server)** - MySQL database integration with configurable access controls and schema inspection - **[BigQuery](https://github.com/LucasHild/mcp-server-bigquery)** (by LucasHild) - This server enables LLMs to inspect database schemas and execute queries on BigQuery. @@ -65,6 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[AlphaVantage](https://github.com/calvernaz/alphavantage)** - MCP server for AlphaVantage stock market data [API](https://www.alphavantage.co) ## 📚 Resources From a1627751f5495d940082d2fffd16e1e13cd1ec11 Mon Sep 17 00:00:00 2001 From: Cesar Alvernaz Date: Fri, 6 Dec 2024 19:00:27 +0000 Subject: [PATCH 41/63] alphavantage mcp server community --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dffa14a8..d1865238 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ A growing set of community-developed and maintained servers demonstrates various > **Note:** Community servers are **untested** and should be used at **your own risk**. They are not affiliated with or endorsed by Anthropic. - **[MCP Installer](https://github.com/anaisbetts/mcp-installer)** - This server is a server that installs other MCP servers for you. -- **[Spotify MCP](https://github.com/varunneal/spotify-mcp)** - This MCP allows an LLM to play and use Spotify. +- **[Spotify MCP](https://github.com/varunneal/spotify-mcp)** - This MCP allows an LLM to play and use Spotify. - **[Inoyu](https://github.com/sergehuber/inoyu-mcp-unomi-server)** - Interact with an Apache Unomi CDP customer data platform to retrieve and update customer profiles - **[MySQL](https://github.com/designcomputer/mysql_mcp_server)** - MySQL database integration with configurable access controls and schema inspection - **[BigQuery](https://github.com/LucasHild/mcp-server-bigquery)** (by LucasHild) - This server enables LLMs to inspect database schemas and execute queries on BigQuery. From 6d7a8f2267ba571bb590d1b51add95173e5a659f Mon Sep 17 00:00:00 2001 From: Aschent89 Date: Fri, 6 Dec 2024 14:03:12 -0500 Subject: [PATCH 42/63] feat: add get_issue endpoint to retrieve single issue details Adds functionality to fetch details of a specific GitHub issue by number. This includes: - New GetIssueSchema for input validation - Implementation of getIssue function using GitHub API - Addition of get_issue tool to available tools list - Handler for get_issue in CallToolRequestSchema This allows users to retrieve complete issue information including: - Issue metadata (title, body, state) - Associated data (labels, assignees, milestone) - Timestamps (created, updated, closed) --- src/github/index.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/github/schemas.ts | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/src/github/index.ts b/src/github/index.ts index 287cfdcb..3759e8b5 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -20,6 +20,7 @@ import { CreateRepositorySchema, ForkRepositorySchema, GetFileContentsSchema, + GetIssueSchema, GitHubCommitSchema, GitHubContentSchema, GitHubCreateUpdateFileResponseSchema, @@ -691,6 +692,29 @@ async function searchUsers( return SearchUsersResponseSchema.parse(await response.json()); } +async function getIssue( + owner: string, + repo: string, + issueNumber: number +): Promise { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`, + { + headers: { + Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`, + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-mcp-server", + }, + } +); + + if (!response.ok) { + throw new Error(`Github API error: ${response.statusText}`); + } + + return GitHubIssueSchema.parse(await response.json()); +} + server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ @@ -778,6 +802,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { description: "Search for users on GitHub", inputSchema: zodToJsonSchema(SearchUsersSchema), }, + { + name: "get_issue", + description: "Get details of a specific issue in a GitHub repository.", + inputSchema: zodToJsonSchema(GetIssueSchema) + } ], }; }); @@ -972,6 +1001,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } + case "get_issue": { + const args = z.object({ + owner: z.string(), + repo: z.string(), + issue_number: z.number() + }).parse(request.params.arguments); + const issue = await getIssue(args.owner, args.repo, args.issue_number); + return { toolResult: issue }; + } + default: throw new Error(`Unknown tool: ${request.params.name}`); } diff --git a/src/github/schemas.ts b/src/github/schemas.ts index bd0d8618..cefdc1d1 100644 --- a/src/github/schemas.ts +++ b/src/github/schemas.ts @@ -677,6 +677,12 @@ export const IssueCommentSchema = z.object({ body: z.string() }); +export const GetIssueSchema = z.object({ + owner: z.string().describe("Repository owner (username or organization)"), + repo: z.string().describe("Repository name"), + issue_number: z.number().describe("Issue number") +}); + // Export types export type GitHubAuthor = z.infer; export type GitHubFork = z.infer; From 90380945895480a556fc2f9dfa035d20776461cf Mon Sep 17 00:00:00 2001 From: Aschent89 Date: Fri, 6 Dec 2024 14:08:01 -0500 Subject: [PATCH 43/63] Update the github-server readme to outline 'get_issue' --- src/github/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/github/README.md b/src/github/README.md index cc0a09c3..1898f9e1 100644 --- a/src/github/README.md +++ b/src/github/README.md @@ -180,6 +180,14 @@ MCP Server for the GitHub API, enabling file operations, repository management, - `sha` (optional string): branch name - Returns: List of commits +17. `get_issue` + - Gets the contents of an issue within a repository + - Inputs: + - `owner` (string): Repository owner + - `repo` (string): Repository name + - `issue_number` (number): Issue number to retrieve + - Returns: Github Issue object & details + ## Search Query Syntax ### Code Search From b0ffed3f5ce75c8328a37a0098d0ebb3363d5ba4 Mon Sep 17 00:00:00 2001 From: Frank Fiegel <108313943+punkpeye@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:14:14 -0600 Subject: [PATCH 44/63] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..c092c726 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Additional resources on MCP. - **[Awesome MCP Servers by punkpeye](https://github.com/punkpeye/awesome-mcp-servers)** - A curated list of MCP servers by **[Frank Fiegel](https://github.com/punkpeye)** - **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** - A curated list of MCP servers by **[wong2](https://github.com/wong2)** - **[Awesome MCP Servers by appcypher](https://github.com/appcypher/awesome-mcp-servers)** - A curated list of MCP servers by **[Stephen Akinyemi](https://github.com/appcypher)** +- **[Discord Server](https://glama.ai/mcp/discord)** – A community discord server dedicated to MCP by **[Frank Fiegel](https://github.com/punkpeye)** - **[mcp-get](https://mcp-get.com)** - Command line tool for installing and managing MCP servers by **[Michael Latman](https://github.com/michaellatman)** - **[mcp-cli](https://github.com/wong2/mcp-cli)** - A CLI inspector for the Model Context Protocol by **[wong2](https://github.com/wong2)** From 508ab7caf5d0ece6eeef4e0119d2621cfa0d3560 Mon Sep 17 00:00:00 2001 From: Frank Fiegel <108313943+punkpeye@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:16:36 -0600 Subject: [PATCH 45/63] Add r/mcp Reddit community --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..c890ea9e 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Additional resources on MCP. - **[Awesome MCP Servers by appcypher](https://github.com/appcypher/awesome-mcp-servers)** - A curated list of MCP servers by **[Stephen Akinyemi](https://github.com/appcypher)** - **[mcp-get](https://mcp-get.com)** - Command line tool for installing and managing MCP servers by **[Michael Latman](https://github.com/michaellatman)** - **[mcp-cli](https://github.com/wong2/mcp-cli)** - A CLI inspector for the Model Context Protocol by **[wong2](https://github.com/wong2)** +- **[r/mcp](https://www.reddit.com/r/mcp)** – A Reddit community dedicated to MCP by **[Frank Fiegel](https://github.com/punkpeye)** ## 🚀 Getting Started From b32d1d7e5f34eea97d57d7c79cb722c52a3bec52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Fri, 6 Dec 2024 21:31:18 +0100 Subject: [PATCH 46/63] README: add Axiom official MCP server --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..a4e91d05 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ These servers aim to demonstrate MCP features and the Typescript and Python SDK. Official integrations are maintained by companies building production ready MCP servers for their platforms. +- Axiom Logo **[Axiom](https://github.com/axiomhq/mcp-server-axiom)** - Query and analyze your Axiom logs, traces and all other event data in natural language - Browserbase Logo **[Browserbase](https://github.com/browserbase/mcp-server-browserbase)** - Automate browser interactions in the cloud (e.g. web navigation, data extraction, form filling, and more) - **[Cloudflare](https://github.com/cloudflare/mcp-server-cloudflare)** - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1) - **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Interact with your crash reporting and real using monitoring data on your Raygun account From b09b3610a1f76d249d9a257a2d99fe4a18120f60 Mon Sep 17 00:00:00 2001 From: datawiz168 Date: Sun, 8 Dec 2024 00:46:29 +0800 Subject: [PATCH 47/63] Add Snowflake MCP server to community servers list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..c91007c5 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[MCP Installer](https://github.com/anaisbetts/mcp-installer)** - This server is a server that installs other MCP servers for you. - **[Spotify MCP](https://github.com/varunneal/spotify-mcp)** - This MCP allows an LLM to play and use Spotify. - **[Inoyu](https://github.com/sergehuber/inoyu-mcp-unomi-server)** - Interact with an Apache Unomi CDP customer data platform to retrieve and update customer profiles +- **[Snowflake](https://github.com/datawiz168/mcp-snowflake-service)** - This MCP server enables LLMs to interact with Snowflake databases, allowing for secure and controlled data operations. - **[MySQL](https://github.com/designcomputer/mysql_mcp_server)** - MySQL database integration with configurable access controls and schema inspection - **[BigQuery](https://github.com/LucasHild/mcp-server-bigquery)** (by LucasHild) - This server enables LLMs to inspect database schemas and execute queries on BigQuery. - **[BigQuery](https://github.com/ergut/mcp-bigquery-server)** (by ergut) - Server implementation for Google BigQuery integration that enables direct BigQuery database access and querying capabilities From 88cfbfc97a71c4e8d15463960f38414bedc8b377 Mon Sep 17 00:00:00 2001 From: Christian Kreiling Date: Sat, 7 Dec 2024 12:45:02 -0500 Subject: [PATCH 48/63] README: add a community Docker MCP server --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..429c0df3 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[Docker](https://github.com/ckreiling/mcp-server-docker/tree/main)** - Integrate with Docker to manage containers, images, volumes, and networks. ## 📚 Resources From d2180886a9a7134668cad54d2e70fbe0194c119a Mon Sep 17 00:00:00 2001 From: Christian Kreiling Date: Sat, 7 Dec 2024 12:53:44 -0500 Subject: [PATCH 49/63] Point to the repository root instead of tree/main --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 429c0df3..33e93f6a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). -- **[Docker](https://github.com/ckreiling/mcp-server-docker/tree/main)** - Integrate with Docker to manage containers, images, volumes, and networks. +- **[Docker](https://github.com/ckreiling/mcp-server-docker)** - Integrate with Docker to manage containers, images, volumes, and networks. ## 📚 Resources From 14a3c5c553d55eda5079ac5f2273b63e14e1b56a Mon Sep 17 00:00:00 2001 From: Suyog Sonwalkar Date: Sat, 7 Dec 2024 21:36:00 -0800 Subject: [PATCH 50/63] Adding MCP Server Kubernetes --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..19f72d26 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[Kubernetes](https://github.com/Flux159/mcp-server-kubernetes)** - Connect to Kubernetes cluster and manage pods, deployments, and services. ## 📚 Resources From 4aa34d058c2bdaae8a05c749cd3672b4cb3eb950 Mon Sep 17 00:00:00 2001 From: Snaggle AI Date: Sun, 8 Dec 2024 17:01:29 +0100 Subject: [PATCH 51/63] Added openapi-mcp-server to community servers in README.md openapi-mcp-server allows connections to any server that has an open api spec. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..41c392e5 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[OpenAPI](https://github.com/snaggle-ai/openapi-mcp-server)** - Interact with [OpenAPI](https://www.openapis.org/) APIs. ## 📚 Resources From 71f1c450424bcc6af691c8c49f41f2c5f214d9c5 Mon Sep 17 00:00:00 2001 From: Cesar Alvernaz Date: Sun, 8 Dec 2024 20:58:08 +0000 Subject: [PATCH 52/63] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1865238..526b9e1f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). -- **[AlphaVantage](https://github.com/calvernaz/alphavantage)** - MCP server for AlphaVantage stock market data [API](https://www.alphavantage.co) +- **[AlphaVantage](https://github.com/calvernaz/alphavantage)** - MCP server for stock market data API [AlphaVantage](https://www.alphavantage.co) ## 📚 Resources From 8562a813c142472ae7801cb6de3817d12b472ba4 Mon Sep 17 00:00:00 2001 From: Vivek Vellaiyappan Date: Sun, 8 Dec 2024 16:57:47 -0600 Subject: [PATCH 53/63] feat: Added mcp-pandoc to enable seamless content conversions when using claude --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45899a32..84e85690 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). +- **[Pandoc](https://github.com/vivekVells/mcp-pandoc)** - This MCP Server enables seamless document format conversion between Markdown, HTML, and text (with other format supports like PDF, docx, csv in development) using Pandoc. ## 📚 Resources From f0dbe403c3916d1e00efd022e42ae53d464ca26b Mon Sep 17 00:00:00 2001 From: Vivek Vellaiyappan Date: Sun, 8 Dec 2024 17:09:22 -0600 Subject: [PATCH 54/63] worded better --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84e85690..ac4c5f5e 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Any Chat Completions](https://github.com/pyroprompts/any-chat-completions-mcp)** - Interact with any OpenAI SDK Compatible Chat Completions API like OpenAI, Perplexity, Groq, xAI and many more. - **[Windows CLI](https://github.com/SimonB97/win-cli-mcp-server)** - MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells. - **[OpenRPC](https://github.com/shanejonas/openrpc-mpc-server)** - Interact with and discover JSON-RPC APIs via [OpenRPC](https://open-rpc.org). -- **[Pandoc](https://github.com/vivekVells/mcp-pandoc)** - This MCP Server enables seamless document format conversion between Markdown, HTML, and text (with other format supports like PDF, docx, csv in development) using Pandoc. +- **[Pandoc](https://github.com/vivekVells/mcp-pandoc)** - MCP server for seamless document format conversion using Pandoc, supporting Markdown, HTML, and plain text, with other formats like PDF, csv and docx in development. ## 📚 Resources From d877690dce006932bce45b426334a973c2968181 Mon Sep 17 00:00:00 2001 From: wong2 Date: Mon, 9 Dec 2024 16:07:53 +0800 Subject: [PATCH 55/63] Add website of awesome-mcp-servers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45899a32..6e89692f 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ A growing set of community-developed and maintained servers demonstrates various Additional resources on MCP. - **[Awesome MCP Servers by punkpeye](https://github.com/punkpeye/awesome-mcp-servers)** - A curated list of MCP servers by **[Frank Fiegel](https://github.com/punkpeye)** -- **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** - A curated list of MCP servers by **[wong2](https://github.com/wong2)** +- **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** - **[website](https://mcpservers.org)** - A curated list of MCP servers by **[wong2](https://github.com/wong2)** - **[Awesome MCP Servers by appcypher](https://github.com/appcypher/awesome-mcp-servers)** - A curated list of MCP servers by **[Stephen Akinyemi](https://github.com/appcypher)** - **[mcp-get](https://mcp-get.com)** - Command line tool for installing and managing MCP servers by **[Michael Latman](https://github.com/michaellatman)** - **[mcp-cli](https://github.com/wong2/mcp-cli)** - A CLI inspector for the Model Context Protocol by **[wong2](https://github.com/wong2)** From 858086b250bbe581e218d403bb34bcfdc0f62abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Mon, 9 Dec 2024 09:59:23 +0000 Subject: [PATCH 56/63] Update README.md Co-authored-by: Mano Toth <71388581+tothmano@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4e91d05..c74e7121 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ These servers aim to demonstrate MCP features and the Typescript and Python SDK. Official integrations are maintained by companies building production ready MCP servers for their platforms. -- Axiom Logo **[Axiom](https://github.com/axiomhq/mcp-server-axiom)** - Query and analyze your Axiom logs, traces and all other event data in natural language +- Axiom Logo **[Axiom](https://github.com/axiomhq/mcp-server-axiom)** - Query and analyze your Axiom logs, traces, and all other event data in natural language - Browserbase Logo **[Browserbase](https://github.com/browserbase/mcp-server-browserbase)** - Automate browser interactions in the cloud (e.g. web navigation, data extraction, form filling, and more) - **[Cloudflare](https://github.com/cloudflare/mcp-server-cloudflare)** - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1) - **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Interact with your crash reporting and real using monitoring data on your Raygun account From ef0ca6ab7bdf2faab1659748de75079b76ca9f2b Mon Sep 17 00:00:00 2001 From: wong2 Date: Mon, 9 Dec 2024 21:34:41 +0800 Subject: [PATCH 57/63] Update README.md Co-authored-by: Justin Spahr-Summers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e89692f..1181c793 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ A growing set of community-developed and maintained servers demonstrates various Additional resources on MCP. - **[Awesome MCP Servers by punkpeye](https://github.com/punkpeye/awesome-mcp-servers)** - A curated list of MCP servers by **[Frank Fiegel](https://github.com/punkpeye)** -- **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** - **[website](https://mcpservers.org)** - A curated list of MCP servers by **[wong2](https://github.com/wong2)** +- **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** (**[website](https://mcpservers.org)**) - A curated list of MCP servers by **[wong2](https://github.com/wong2)** - **[Awesome MCP Servers by appcypher](https://github.com/appcypher/awesome-mcp-servers)** - A curated list of MCP servers by **[Stephen Akinyemi](https://github.com/appcypher)** - **[mcp-get](https://mcp-get.com)** - Command line tool for installing and managing MCP servers by **[Michael Latman](https://github.com/michaellatman)** - **[mcp-cli](https://github.com/wong2/mcp-cli)** - A CLI inspector for the Model Context Protocol by **[wong2](https://github.com/wong2)** From acc3ba2740416339ef753b4e46f87d677a1c633b Mon Sep 17 00:00:00 2001 From: Rakesh Goyal Date: Mon, 9 Dec 2024 19:47:36 +0530 Subject: [PATCH 58/63] Replaced hyphen with underscore in the tool names --- src/sqlite/src/mcp_server_sqlite/server.py | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/sqlite/src/mcp_server_sqlite/server.py b/src/sqlite/src/mcp_server_sqlite/server.py index 1b97a6a4..05cd117b 100644 --- a/src/sqlite/src/mcp_server_sqlite/server.py +++ b/src/sqlite/src/mcp_server_sqlite/server.py @@ -27,12 +27,12 @@ Resources: This server exposes one key resource: "memo://insights", which is a business insights memo that gets automatically updated throughout the analysis process. As users analyze the database and discover insights, the memo resource gets updated in real-time to reflect new findings. Resources act as living documents that provide context to the conversation. Tools: This server provides several SQL-related tools: -"read-query": Executes SELECT queries to read data from the database -"write-query": Executes INSERT, UPDATE, or DELETE queries to modify data -"create-table": Creates new tables in the database -"list-tables": Shows all existing tables -"describe-table": Shows the schema for a specific table -"append-insight": Adds a new business insight to the memo resource +"read_query": Executes SELECT queries to read data from the database +"write_query": Executes INSERT, UPDATE, or DELETE queries to modify data +"create_table": Creates new tables in the database +"list_tables": Shows all existing tables +"describe_table": Shows the schema for a specific table +"append_insight": Adds a new business insight to the memo resource You are an AI assistant tasked with generating a comprehensive business scenario based on a given topic. @@ -68,7 +68,7 @@ a. Present 1 additional multiple-choice query options to the user. Its important b. Explain the purpose of each query option. c. Wait for the user to select one of the query options. d. After each query be sure to opine on the results. -e. Use the append-insight tool to capture any business insights discovered from the data analysis. +e. Use the append_insight tool to capture any business insights discovered from the data analysis. 7. Generate a dashboard: a. Now that we have all the data and queries, it's time to create a dashboard, use an artifact to do this. @@ -233,7 +233,7 @@ async def main(db_path: str): """List available tools""" return [ types.Tool( - name="read-query", + name="read_query", description="Execute a SELECT query on the SQLite database", inputSchema={ "type": "object", @@ -244,7 +244,7 @@ async def main(db_path: str): }, ), types.Tool( - name="write-query", + name="write_query", description="Execute an INSERT, UPDATE, or DELETE query on the SQLite database", inputSchema={ "type": "object", @@ -255,7 +255,7 @@ async def main(db_path: str): }, ), types.Tool( - name="create-table", + name="create_table", description="Create a new table in the SQLite database", inputSchema={ "type": "object", @@ -266,7 +266,7 @@ async def main(db_path: str): }, ), types.Tool( - name="list-tables", + name="list_tables", description="List all tables in the SQLite database", inputSchema={ "type": "object", @@ -274,7 +274,7 @@ async def main(db_path: str): }, ), types.Tool( - name="describe-table", + name="describe_table", description="Get the schema information for a specific table", inputSchema={ "type": "object", @@ -285,7 +285,7 @@ async def main(db_path: str): }, ), types.Tool( - name="append-insight", + name="append_insight", description="Add a business insight to the memo", inputSchema={ "type": "object", @@ -303,13 +303,13 @@ async def main(db_path: str): ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """Handle tool execution requests""" try: - if name == "list-tables": + if name == "list_tables": results = db._execute_query( "SELECT name FROM sqlite_master WHERE type='table'" ) return [types.TextContent(type="text", text=str(results))] - elif name == "describe-table": + elif name == "describe_table": if not arguments or "table_name" not in arguments: raise ValueError("Missing table_name argument") results = db._execute_query( @@ -317,7 +317,7 @@ async def main(db_path: str): ) return [types.TextContent(type="text", text=str(results))] - elif name == "append-insight": + elif name == "append_insight": if not arguments or "insight" not in arguments: raise ValueError("Missing insight argument") @@ -332,19 +332,19 @@ async def main(db_path: str): if not arguments: raise ValueError("Missing arguments") - if name == "read-query": + if name == "read_query": if not arguments["query"].strip().upper().startswith("SELECT"): - raise ValueError("Only SELECT queries are allowed for read-query") + raise ValueError("Only SELECT queries are allowed for read_query") results = db._execute_query(arguments["query"]) return [types.TextContent(type="text", text=str(results))] - elif name == "write-query": + elif name == "write_query": if arguments["query"].strip().upper().startswith("SELECT"): - raise ValueError("SELECT queries are not allowed for write-query") + raise ValueError("SELECT queries are not allowed for write_query") results = db._execute_query(arguments["query"]) return [types.TextContent(type="text", text=str(results))] - elif name == "create-table": + elif name == "create_table": if not arguments["query"].strip().upper().startswith("CREATE TABLE"): raise ValueError("Only CREATE TABLE statements are allowed") db._execute_query(arguments["query"]) From 50ab31a76077819c3e3fcf83b9279d453483a0ab Mon Sep 17 00:00:00 2001 From: Rakesh Goyal Date: Mon, 9 Dec 2024 19:57:28 +0530 Subject: [PATCH 59/63] Replaced hyphen with underscore in the sentry server.. --- src/sentry/src/mcp_server_sentry/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sentry/src/mcp_server_sentry/server.py b/src/sentry/src/mcp_server_sentry/server.py index 1760311c..9f885bbc 100644 --- a/src/sentry/src/mcp_server_sentry/server.py +++ b/src/sentry/src/mcp_server_sentry/server.py @@ -223,7 +223,7 @@ async def serve(auth_token: str) -> Server: async def handle_list_tools() -> list[types.Tool]: return [ types.Tool( - name="get-sentry-issue", + name="get_sentry_issue", description="""Retrieve and analyze a Sentry issue by ID or URL. Use this tool when you need to: - Investigate production errors and crashes - Access detailed stacktraces from Sentry @@ -247,7 +247,7 @@ async def serve(auth_token: str) -> Server: async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: - if name != "get-sentry-issue": + if name != "get_sentry_issue": raise ValueError(f"Unknown tool: {name}") if not arguments or "issue_id_or_url" not in arguments: From bca13a0ffea3b5a7bb0424fcb5908df33d365e64 Mon Sep 17 00:00:00 2001 From: Rakesh Goyal Date: Mon, 9 Dec 2024 20:02:41 +0530 Subject: [PATCH 60/63] Update README.md for sqlite.. --- src/sqlite/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sqlite/README.md b/src/sqlite/README.md index 5f211c41..2b2bea80 100644 --- a/src/sqlite/README.md +++ b/src/sqlite/README.md @@ -22,26 +22,26 @@ The server provides a demonstration prompt: The server offers six core tools: #### Query Tools -- `read-query` +- `read_query` - Execute SELECT queries to read data from the database - Input: - `query` (string): The SELECT SQL query to execute - Returns: Query results as array of objects -- `write-query` +- `write_query` - Execute INSERT, UPDATE, or DELETE queries - Input: - `query` (string): The SQL modification query - Returns: `{ affected_rows: number }` -- `create-table` +- `create_table` - Create new tables in the database - Input: - `query` (string): CREATE TABLE SQL statement - Returns: Confirmation of table creation #### Schema Tools -- `list-tables` +- `list_tables` - Get a list of all tables in the database - No input required - Returns: Array of table names @@ -53,7 +53,7 @@ The server offers six core tools: - Returns: Array of column definitions with names and types #### Analysis Tools -- `append-insight` +- `append_insight` - Add new business insights to the memo resource - Input: - `insight` (string): Business insight discovered from data analysis From 63a7fe99d763028485819ebed9e67ffdab691fc2 Mon Sep 17 00:00:00 2001 From: Rakesh Goyal Date: Mon, 9 Dec 2024 20:03:33 +0530 Subject: [PATCH 61/63] Update README.md for sentry.. --- src/sentry/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/README.md b/src/sentry/README.md index 34a1feb5..aae44568 100644 --- a/src/sentry/README.md +++ b/src/sentry/README.md @@ -6,7 +6,7 @@ A Model Context Protocol server for retrieving and analyzing issues from Sentry. ### Tools -1. `get-sentry-issue` +1. `get_sentry_issue` - Retrieve and analyze a Sentry issue by ID or URL - Input: - `issue_id_or_url` (string): Sentry issue ID or URL to analyze From 522abeacd197fd8a4abc4d4bf4935a96eee37570 Mon Sep 17 00:00:00 2001 From: Frank Fiegel <108313943+punkpeye@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:55:55 -0600 Subject: [PATCH 62/63] Add website version of awesome-mcp-servers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 605465e4..15c1ce56 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ A growing set of community-developed and maintained servers demonstrates various Additional resources on MCP. -- **[Awesome MCP Servers by punkpeye](https://github.com/punkpeye/awesome-mcp-servers)** - A curated list of MCP servers by **[Frank Fiegel](https://github.com/punkpeye)** +- **[Awesome MCP Servers by punkpeye](https://github.com/punkpeye/awesome-mcp-servers)** (**[website](https://glama.ai/mcp/servers)**) - A curated list of MCP servers by **[Frank Fiegel](https://github.com/punkpeye)** - **[Awesome MCP Servers by wong2](https://github.com/wong2/awesome-mcp-servers)** (**[website](https://mcpservers.org)**) - A curated list of MCP servers by **[wong2](https://github.com/wong2)** - **[Awesome MCP Servers by appcypher](https://github.com/appcypher/awesome-mcp-servers)** - A curated list of MCP servers by **[Stephen Akinyemi](https://github.com/appcypher)** - **[mcp-get](https://mcp-get.com)** - Command line tool for installing and managing MCP servers by **[Michael Latman](https://github.com/michaellatman)** From 28ac6f6c75d0b4203ff3864f47a74f1dfbb9c7e9 Mon Sep 17 00:00:00 2001 From: Aekanun Thongtae Date: Mon, 9 Dec 2024 22:57:20 +0700 Subject: [PATCH 63/63] just add my repo to your readme.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index db71c819..3dc4777a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ A growing set of community-developed and maintained servers demonstrates various - **[Inoyu](https://github.com/sergehuber/inoyu-mcp-unomi-server)** - Interact with an Apache Unomi CDP customer data platform to retrieve and update customer profiles - **[Snowflake](https://github.com/datawiz168/mcp-snowflake-service)** - This MCP server enables LLMs to interact with Snowflake databases, allowing for secure and controlled data operations. - **[MySQL](https://github.com/designcomputer/mysql_mcp_server)** - MySQL database integration with configurable access controls and schema inspection +- **[MSSQL](https://github.com/aekanun2020/mcp-server/)** - MSSQL database integration with configurable access controls and schema inspection - **[BigQuery](https://github.com/LucasHild/mcp-server-bigquery)** (by LucasHild) - This server enables LLMs to inspect database schemas and execute queries on BigQuery. - **[BigQuery](https://github.com/ergut/mcp-bigquery-server)** (by ergut) - Server implementation for Google BigQuery integration that enables direct BigQuery database access and querying capabilities - **[Todoist](https://github.com/abhiz123/todoist-mcp-server)** - Interact with Todoist to manage your tasks.