-
Notifications
You must be signed in to change notification settings - Fork 394
feat: Add debugging functionality to MCP #7616
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
base: main
Are you sure you want to change the base?
Conversation
bc6b704
to
5b76d63
Compare
This is a pretty big feature, nice work! Were you able to actually get an agent to use the workflow? |
91bb0a7
to
9ac0354
Compare
@tgodzik I changed the implementation approach and the PR is smaller now. |
1606db7
to
a6910d3
Compare
469af24
to
7c4d2dc
Compare
12965e3
to
e85732d
Compare
f5f2fad
to
47d7ef4
Compare
@tgodzik the feature is becoming usable now, feel free to give it a try! |
// for JSON formatted doctor | ||
"com.lihaoyi" %% "ujson" % "4.2.1", | ||
// For MCP communication | ||
"com.github.andyglow" %% "scala-jsonschema-circe-json" % "0.7.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under which conditions is it ok to introduce a new dependency?
The MetalsMcpServer
became quite large with the set of new tools, so I used this library to generate the JSON Schema for the tools and did a few other refactorings to reduce the amount of boilerplate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually try to minimize the amount of dependencies, so if it's not 100% needed we don't add it. I would rather avoid it if possible. We can easily separate the tools into traits and then just have one class to create them all
441234c
to
f723d42
Compare
This refactor eliminates code duplication in the MCP (Model Context Protocol) server implementation by introducing shared type definitions and helper methods. Summary - Added circe JSON schema dependency - Introduces scala-jsonschema-circe-json for automatic schema generation - Created reusable type-safe tool creation helper - New createAsyncTool[T] method with automatic schema generation from case classes - Introduced trait-based parameter validation - HasOptionalFileInFocus, HasFileInFocus, and HasFqcn traits for consistent parameter handling - Replaced manual JSON schema strings - All MCP tools now use generated schemas from case class definitions - Added utility for Java object to Circe JSON conversion - javaObjectToJson helper method Key Changes 1. Type Safety: Each MCP tool now has a corresponding case class with proper Circe decoders and JSON schema generation 2. Code Reduction: Eliminated ~500 lines of duplicate schema definitions and argument parsing code 3. Consistency: All tools now follow the same pattern for parameter validation and error handling 4. Maintainability: Schema changes only require updating case class definitions instead of manual JSON strings Technical Details - Uses com.github.andyglow.jsonschema.AsCirce for automatic schema generation - Implements proper type-safe parameter extraction with compile-time validation - Maintains backward compatibility with existing MCP tool contracts - Improves error handling with consistent error message formatting
- `fileInFocus` (string, optional): Current file for context | ||
|
||
#### typed-glob-search | ||
Searches for symbols by their type signatures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this is not like hoogle or inquire, which might also be useful. The type here is whether it's a method/object etc.
// for JSON formatted doctor | ||
"com.lihaoyi" %% "ujson" % "4.2.1", | ||
// For MCP communication | ||
"com.github.andyglow" %% "scala-jsonschema-circe-json" % "0.7.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually try to minimize the amount of dependencies, so if it's not 100% needed we don't add it. I would rather avoid it if possible. We can easily separate the tools into traits and then just have one class to create them all
This PR adds debugging functionality to Metals' MCP
integration, enabling AI tools to interact with and monitor Scala debug sessions.
New MCP debugging tools
Launching, listing, stopping debugging sessions
debug-main
- Start a debug session for a main class with optional arguments, environment variables, and initial breakpointsdebug-test
- Start a debug session for a test suite with optional test method filtering and initial breakpointsdebug-attach
- Attach to a remote JVM debug port (default 5005) with hostname and module specificationdebug-sessions
- List active debug sessions, optionally including historical sessions from past runsdebug-terminate
- Terminate a debug session and clean up resourcesInspecting
debug-threads
- List all threads in a debug session with their current statesdebug-stack-trace
- Get the call stack for a specific thread showing method names and source locationsdebug-evaluate
- Evaluate expressions in the current debug context and return results with type informationdebug-variables
- Get all variables in the current debug scope, organized by scope namedebug-output
- Retrieve stdout/stderr output from debug sessions with filtering by type, regex patterns, and line limitsStepping
debug-pause
- Pause execution in a specific debug session and threaddebug-continue
- Continue execution in a paused debug sessiondebug-step
- Step execution (in/out/over) for a specific thread in a debug sessiondebug-breakpoints
- Set or clear breakpoints in source files for a debug sessionImplementation
MetalsMcpServer
acts like a DAP client (connects to a socket and sends/receives DAP messages)DebugOutputManager
stores and retrieves current and historical debug session outputs with in-memory caching and optional disk persistenceDebugStateManager
- tracks session state and events