Repository navigation
feat(mcp): Serve each exposed CLI command as its own MCP tool #1922
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
Open
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3a880b1
feat(mcp): Serve CLI commands through search_sentry and the execute t…
sentry-junior[bot] 39d90f1
fix(mcp): Keep cut-off command results valid JSON
sentry-junior[bot] 9c5de1c
feat(mcp): Serve each exposed CLI command as its own MCP tool
sentry-junior[bot] 5395f34
Merge remote-tracking branch 'origin/feat/command-catalog' into feat/…
sentry-junior[bot] c358733
fix(mcp): Check every session target a command call names
sentry-junior[bot] 070593f
fix(mcp): Check the project in a three-part feedback or issue ID
sentry-junior[bot] d25d5b7
fix(mcp): Keep project sessions and cut pages from leaking
sentry-junior[bot] c8076bb
fix(mcp): Close the scope gaps Warden found in command tools
sentry-junior[bot] 8731582
fix(mcp): Accept api/0/ endpoints without a leading slash in sessions
sentry-junior[bot] de13bc4
fix(mcp): Pin sentry api and # issue references to the session project
sentry-junior[bot] 138ae47
Merge branch 'feat/command-catalog' into feat/cli-first-mcp-execute
sentry-junior[bot] 8a06e45
fix(mcp): Give each command tool a display title
sentry-junior[bot] 5e08735
Merge branch 'feat/command-catalog' into feat/cli-first-mcp-execute
sentry-junior[bot] 59a6feb
fix(mcp): Refuse absolute URLs in the sentry api tool
sentry-junior[bot] 1db2a1f
Merge remote-tracking branch 'origin/feat/cli-first-mcp-execute' into…
sentry-junior[bot] 0fa21c4
Merge branch 'feat/command-catalog' into feat/cli-first-mcp-execute
sentry-junior[bot] 0b80422
Merge remote-tracking branch 'origin/feat/cli-first-mcp-execute' into…
sentry-junior[bot] 8e4e42a
fix(mcp): Pin dashboard org words and short org/project targets
sentry-junior[bot] 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
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,66 @@ | ||
| /** | ||
| * `sentry mcp --commands`: serve each exposed CLI command as its own MCP tool | ||
| * through mcp-core's command surface. | ||
| * | ||
| * The tools come from the generated command catalog, and each call runs | ||
| * through `createSentrySDK().run()`, which loads only the top-level route the | ||
| * call runs, never the whole command tree. | ||
| * | ||
| * Loaded only in commands mode. `@sentry/mcp-server` does not bundle command | ||
| * handlers, so its bundle replaces this module with a stub. | ||
| */ | ||
|
|
||
| import { | ||
| type CommandCall, | ||
| CommandFailedError, | ||
| createCommandTools, | ||
| type ToolRegistry, | ||
| toCommandArgs, | ||
| } from "@sentry/mcp-core/command-surface"; | ||
| import { createSentrySDK, SentryError } from "../../index.js"; | ||
| import type { McpServerConfig } from "./config.js"; | ||
|
|
||
| export type CommandSurfaceSetup = { | ||
| config: McpServerConfig; | ||
| /** Where commands run, for DSN detection and project roots. */ | ||
| cwd: string; | ||
| /** The session's current token, refreshed as needed. */ | ||
| getToken: () => Promise<string>; | ||
| }; | ||
|
|
||
| /** Run one call through the CLI SDK, with JSON output and no telemetry of its own. */ | ||
| async function runCall( | ||
| setup: CommandSurfaceSetup, | ||
| call: CommandCall, | ||
| ): Promise<unknown> { | ||
| const { config } = setup; | ||
| const sdk = createSentrySDK({ | ||
| token: await setup.getToken(), | ||
| url: `${config.sentryProtocol}://${config.sentryHost}`, | ||
| org: call.org, | ||
| project: call.project, | ||
| cwd: setup.cwd, | ||
| // The MCP server owns the process's Sentry client. | ||
| telemetry: false, | ||
| }); | ||
| try { | ||
| // `run()` is typed for streaming flags too; the command surface refuses them. | ||
| return await (sdk.run(...toCommandArgs(call)) as Promise<unknown>); | ||
| } catch (error) { | ||
| if (error instanceof SentryError) { | ||
| throw new CommandFailedError(call.path.join(" "), error.message); | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** The command surface's tools, running calls through the CLI SDK. */ | ||
| export function createCliCommandTools( | ||
| setup: CommandSurfaceSetup, | ||
| ): ToolRegistry { | ||
| return createCommandTools({ | ||
| runtime: "stdio", | ||
| readOnly: setup.config.readOnly, | ||
| run: (call) => runCall(setup, call), | ||
| }); | ||
| } |
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
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.