-
Notifications
You must be signed in to change notification settings - Fork 20
feature: mcp server organization and audit scope tooling #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1730bbb
feature: add tooling for defining the audit scope
quinn-g 102d64c
fix: remove irrelevant changes to prompt from this PR
quinn-g 18ecd79
fix: change errro message to empty string in diff fail
quinn-g 959ae50
fix: Update description of audit tool, small fixes
quinn-g 7c393ca
fix: package lock jsons
quinn-g 7ecd59d
fix: move selective action prompting to top of gemini md
quinn-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { expect, describe, it, beforeAll, afterAll } from 'vitest'; | ||
| import { isGitHubRepository, getAuditScope } from './filesystem'; | ||
| import { execSync } from 'child_process'; | ||
| import * as fs from 'fs'; | ||
|
|
||
| describe('filesystem', () => { | ||
| beforeAll(() => { | ||
| execSync('git init'); | ||
| execSync('git remote add origin https://github.com/gemini-testing/gemini-test-repo.git'); | ||
| fs.writeFileSync('test.txt', 'hello'); | ||
| execSync('git add .'); | ||
| execSync('git commit -m "initial commit"'); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| fs.unlinkSync('test.txt'); | ||
| execSync('rm -rf .git'); | ||
| }); | ||
|
|
||
| it('should return true if the directory is a github repository', () => { | ||
| expect(isGitHubRepository()).toBe(true); | ||
| }); | ||
|
|
||
| it('should return a diff of the current changes', () => { | ||
| fs.writeFileSync('test.txt', 'hello world'); | ||
| const diff = getAuditScope(); | ||
| expect(diff).toContain('hello world'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { execSync } from 'node:child_process'; | ||
QuinnDACollins marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Checks if the current directory is a GitHub repository. | ||
| * @returns True if the current directory is a GitHub repository, false otherwise. | ||
| */ | ||
| export const isGitHubRepository = (): boolean => { | ||
| try { | ||
| const remotes = ( | ||
| execSync('git remote -v', { | ||
| encoding: 'utf-8', | ||
| }) || '' | ||
| ).trim(); | ||
|
|
||
| const pattern = /github\.com/; | ||
|
|
||
| return pattern.test(remotes); | ||
| } catch (_error) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Gets a changelist of the repository | ||
| */ | ||
| export function getAuditScope(): string { | ||
| let command = isGitHubRepository() ? 'git diff --merge-base origin/HEAD' : 'git diff'; | ||
| try { | ||
| const diff = ( | ||
| execSync(command, { | ||
| encoding: 'utf-8', | ||
| }) || '' | ||
| ).trim(); | ||
|
|
||
| return diff; | ||
| } catch (_error) { | ||
| return "error generating diff for audit scope"; | ||
QuinnDACollins marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; | ||
| import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; | ||
| import { z } from 'zod'; | ||
| import { promises as fs } from 'fs'; | ||
| import path from 'path'; | ||
| import { getAuditScope } from './filesystem.js'; | ||
| import { findLineNumbers } from './security.js'; | ||
|
|
||
| const server = new McpServer({ | ||
| name: 'gemini-cli-security', | ||
| version: '0.1.0', | ||
| }); | ||
|
|
||
| server.tool( | ||
| 'find_line_numbers', | ||
| 'Finds the line numbers of a code snippet in a file.', | ||
| { | ||
| filePath: z | ||
| .string() | ||
| .describe('The path to the file to with the security vulnerability.'), | ||
| snippet: z | ||
| .string() | ||
| .describe('The code snippet to search for inside the file.'), | ||
| }, | ||
| (input) => findLineNumbers(input, { fs, path }) | ||
| ); | ||
|
|
||
| server.tool( | ||
| 'get_audit_scope', | ||
| 'Checks if the current directory is a GitHub repository.', | ||
QuinnDACollins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {}, | ||
| () => { | ||
| const diff = getAuditScope(); | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: diff, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| async function startServer() { | ||
| const transport = new StdioServerTransport(); | ||
| await server.connect(transport); | ||
| } | ||
|
|
||
| startServer(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.