Repository navigation
feat: add agent mode with use_sentry tool and in-memory MCP architecture - #594
Merged
Merged
Conversation
Implements a comprehensive agent mode feature that provides a natural language interface to all Sentry MCP tools through a single use_sentry tool. Key additions: - New use_sentry tool using in-memory MCP client-server architecture - Uses InMemoryTransport.createLinkedPair() from MCP SDK - Internal MCP server with 18 tools (excludes use_sentry itself) - Zero network overhead with full MCP protocol compliance - GPT-5 embedded agent for natural language operations - Agent mode endpoint (/mcp-agent) - Separate OAuth flow with agent-specific tools - UI toggle between standard (19 tools) and agent (use_sentry only) modes - Persisted mode preference in localStorage - CLI improvements - Renamed start:client → cli for better discoverability - Added --agent flag for testing agent mode - Defaults to http://localhost:5173 for local development - UI enhancements - Multiline textarea input with Ctrl+J for newlines - Enter to submit, Shift+Enter for newlines - Auto-resize based on content - Agent mode toggle button with visual indicator - Beta badge in header - Documentation updates - Architecture documentation for use_sentry in-memory pattern - Manual testing instructions for agent mode - Updated references from GPT-4o to GPT-5 - Added testing.mdc section for manual testing workflow 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
Removes duplicate /mcp-agent endpoint implementation. Agent mode now works
by passing ?agent=1 query parameter to the single /mcp endpoint, which
conditionally loads agent-specific tools (use_sentry only).
Changes:
- Remove /mcp-agent endpoint routing from index.ts
- Delete mcp-agent-handler.ts (duplicate implementation)
- Update test client to use /mcp?agent=1 instead of /mcp-agent
- Update documentation comments to reflect query parameter approach
- Keep existing /mcp handler which already supports ?agent=1
The mcp-handler.ts already had logic to detect the agent query parameter
(line 64: `const isAgentMode = url.searchParams.get("agent") === "1"`)
and conditionally load tools (line 120: `tools: isAgentMode ? agentTools : undefined`).
This simplifies the architecture by having a single OAuth provider and
endpoint that adapts based on the query parameter.
🤖 Generated with Claude Code
Co-Authored-By: Claude <[email protected]>
… context The use_sentry tool was receiving organizationSlug and projectSlug parameters but only using them for monitoring tags, not applying them to the internal server context constraints. This meant the embedded agent would not respect these constraints when calling tools. Changes: - Create contextWithConstraints that merges user parameters into constraints - Pass contextWithConstraints to buildServer instead of original context - Use contextWithConstraints in serverContextStorage.run for consistency This follows the same pattern used in tool-wrapper.ts where constraints are injected into tool parameters (injectConstrainedParams function). Now when a user calls: use_sentry(request="...", organizationSlug="my-org", projectSlug="my-project") The embedded agent's tool calls will automatically have these constraints applied, restricting operations to the specified org/project. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
Critical AsyncLocalStorage bug: The ServerContext was only active during server.connect(), but tool invocations happened outside that context, causing requireServerContext() to throw "No ServerContext available". The issue occurred because: 1. serverContextStorage.run() only wrapped server.connect() (lines 105-107) 2. MCP client creation and tool calls happened outside that context (lines 110-133) 3. When tools executed via MCP protocol, requireServerContext() returned null 4. This would cause runtime errors when tools tried to access the context Fix: - Wrap the entire MCP lifecycle in a single serverContextStorage.run() block: - Server connection - Client creation - Tool invocation (via embedded agent) - Cleanup (client.close(), server.close()) This ensures all async operations that need ServerContext execute within the same AsyncLocalStorage context, making requireServerContext() work correctly throughout the tool execution chain. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
Fixes CLAUDE.md requirement: "NEVER use any. Use unknown or proper types" Changes: - handler.ts: Import and use ToolCall type for formatToolCallTrace - agent.ts: Use Tool type from 'ai' SDK and ToolCall from callEmbeddedAgent - callEmbeddedAgent.ts: Use Tool type from 'ai' SDK, change args to unknown - tool-wrapper.ts: Use unknown instead of any with explanatory comments All type assertions are safe because Zod validation occurs before the assertions execute. Added comments explaining the runtime safety. Co-Authored-By: Claude Code <[email protected]>
…tter The formatToolCallTrace function was calling Object.keys() on call.args which is typed as 'unknown' (correctly mirroring the AI SDK's ToolCallPart interface). This caused a TypeScript compilation error. Added a type assertion to Record<string, unknown> which is safe because the AI SDK guarantees that args is always a JSON-serializable object that matches the tool's input schema (validated by Zod). Co-Authored-By: Claude Code <[email protected]>
Member
Author
|
Gonna ship this. Not yet documented so should let us test things. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements a comprehensive agent mode feature that provides a natural language interface to all Sentry MCP tools through a single use_sentry tool.
Key additions:
New use_sentry tool using in-memory MCP client-server architecture
Agent mode endpoint (/mcp?agent=1)
CLI improvements
UI enhancements
Documentation updates
🤖 Generated with Claude Code