Skip to content

Add denied tools command line option - #549

Closed
colinmollenhour wants to merge 2 commits into
getsentry:mainfrom
colinmollenhour:main
Closed

colinmollenhour wants to merge 2 commits into
getsentry:mainfrom
colinmollenhour:main

Conversation

@colinmollenhour

Copy link
Copy Markdown

Adds tool filtering functionality to reduce context bloat for AI agents. Tools matching a regex pattern are completely hidden from the MCP server response.

Fixes #196

(authored using Claude Code)

Key Changes

  • Added SENTRY_DENIED_TOOLS_REGEX environment variable for tool filtering
  • Added --denied-tools=<regex> CLI argument with precedence over environment variable
  • Updated homepage to dynamically show filtered tools based on server configuration
  • Comprehensive error handling for invalid regex patterns
  • Updated help text and README with usage examples
  • Maintains backward compatibility with existing functionality

Usage

# Environment variable approach
export SENTRY_DENIED_TOOLS_REGEX="^search_"
pnpm start:stdio --access-token=TOKEN --host=sentry.io

# Command line argument approach (CLI takes precedence)
pnpm start:stdio --access-token=TOKEN --host=sentry.io --denied-tools="^search_"

# Hide all but a specific set of tools
pnpm start:stdio --access-token=TOKEN --denied-tools="^(?!(?:find_projects|get_issue_details)$).*$"

# Hide specific tools
pnpm start:stdio --access-token=TOKEN --denied-tools="^(whoami|get_doc)$"

Technical Details

  • Tools are filtered at the MCP protocol level, ensuring they don't appear in server responses
  • Invalid regex patterns log warnings but don't crash the server
  • Web interface dynamically reflects filtered tool lists for authenticated users
  • Filtering function handles edge cases and provides clear error messages

cursor[bot]

This comment was marked as outdated.

@dcramer

dcramer commented Sep 18, 2025

Copy link
Copy Markdown
Member

I'm not opposed to this, but it becomes CLI only and CLI is unlikely to be the future of this service (stdio exists primarily to service self-hosted installations).

I'm also entirely certain that tool selection is likely to become an upstream problem, and already is controlled by many clients like VSCode where you can choose which tools are active.

So that begs the question is: do we need to do this or can we ignore the problem and let upstream providers resolve it?

@colinmollenhour

Copy link
Copy Markdown
Author

do we need to do this or can we ignore the problem and let upstream providers resolve it?

By the common definition of "need" as it relates to the necessity of specific features in software projects, I think the need has been demonstrated adequately by the fact that most other major MCPs support a similar feature and the reasons I've given for it being beneficial.

Will it be solved upstream? Possibly in a year or so.. or maybe not.. I don't see any obvious solutions for it being developed currently.

I would reframe the question as to merge this PR or not as: The PR is already written and solves the problem. What harm will come of merging it, given it does not break backwards compatibility in any way? 🙂

@dcramer

dcramer commented Sep 18, 2025

Copy link
Copy Markdown
Member

@colinmollenhour there are already gateways, and as mentioned tools like vscode already implement selection. i do not think we're 1-2 years off, i just think folks havent adopted the tech yet (and it probably needs some refinement.

merging requires intent, it requires maintenance, and now it requires cognitive load to explain why the stdio (which is not the preferred way to use this package) has features that, useful today, cannot be replicated with the remote service (which is what almost everyone uses)

anyways let me give this some thought, my main concern is less about maintenance and more about it muddies the story. we're not trying to promote folks using stdio as it requires pinning an access token, so I dont love stdio-only behaviors. i just dont know an obvious solution to make this work for the remote connection today without some complicated settings page (which I wanted to do, but it SUPER non trivial).

@colinmollenhour

Copy link
Copy Markdown
Author

cannot be replicated with the remote service

I think it could by using a query parameter as I mentioned on #196, and I gave an example (Brightdata). If you want me to implement the query parameter to get this PR merged I would consider it, I was just trying to stick with what I knew best and it sounds like it opens a big can of worms regarding other possible settings.. so for now it seems just adding this to stdio makes sense.

Some anecdote.. Sentry is ahead of the curve in adopting http, but pretty much all of the other MCPs I use are stdio so I guess I don't get what the resistance to keeping and supporting stdio around is all about.. My team and I are all programmers so having npx and copying and pasting an API key is just not a big deal to us. Forking is also possible - I hate forking - but if it saves a few thousand tokens for tools and descriptions that we don't use, that could be worthwhile (I literally just want to get the issue details via MCP).

Anyway, thanks for considering and providing and supporting an excellent MCP for Sentry.

@dcramer

dcramer commented Sep 18, 2025

Copy link
Copy Markdown
Member

@colinmollenhour fwiw we will probably put more support behind stdio-for-sentry.io, but IMO it needs something like #546 to make it not awful for customers (vs personal access tokens today) - i'm actually actively working on updating our core oauth provider to support 2.1 + that grant, which will allow us to drastically improve what we're doing here, and remove quite a lot of existing complexity tbqh

@colinmollenhour

Copy link
Copy Markdown
Author

Today, Sentry MCP consumes ~15k tokens when I only need one tool.. That's over 7% of the total context allowed for Sonnet 4.5 in Claude Code. Would still be nice to get this resolved for users who configure MCPs via a command line and environment variables..

@dcramer

dcramer commented Oct 28, 2025

Copy link
Copy Markdown
Member

I have an alternative solution to this that I think solves it in a much cleaner way that I'm working on (and works everywhere). Ultimately for our cloud service we really do not want to support people generating api keys and sticking them in some config to make exfiltration easy, so the stdio case for cloud isnt really desirable in the long term.

@dcramer

dcramer commented Oct 28, 2025

Copy link
Copy Markdown
Member

Here's what I have in mind: #594

@colinmollenhour

Copy link
Copy Markdown
Author

That seems like it would work, assuming the tool definitions aren't all just stuffed into one tool? I'll not dig deeper into how it works right now and trust you that it will work. My only concern is decreasing wasted context when you just want to occasionally use one or two tools of the whole set. For now I'll just toggle the MCP off when not using it, although not all agents let you do that easily. Thanks!

@dcramer

dcramer commented Oct 28, 2025

Copy link
Copy Markdown
Member

@colinmollenhour so what it does is it just exposes a single tool thats just a really lightweight agent call, and taht agent manages all the token consumpion (e.g we eat the cost vs your client)

let me get this fixed up/live and you can test it out

@dcramer

dcramer commented Oct 28, 2025

Copy link
Copy Markdown
Member

@colinmollenhour i guess one challenge here is its going to connect to a local MCP, so it means by running stdio agent mode actually is going to require you to have an openai token setup and pass that cost on

we could have it connect to our remote agent tho it makes things slower in some contexts (tho I could make it variable)

if you're interested tho i can ship a 0.20.0 that includes it

@colinmollenhour

colinmollenhour commented Oct 29, 2025 •

Copy link
Copy Markdown
Author

Thanks, I can just wait until it's live unless you'd prefer I test this use-case first - if I can configure the OpenAI compatible url I should be able to test it pretty easily.

Edit: My prompt just starts out like this:

Inspect Sentry error #$ARGUMENTS using the Sentry MCP and help me... The Sentry organization slug is "xxx" and you'll need to to get the issue details by it's Short ID.

So I'm just using search_issues and get_issue_details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable or disable list of tools (toolsets)

2 participants