-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[mcp] SDK integration with Streamable HTTP transport (Phase 1.2) #7846
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 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
612c3c0
Initial plan
Copilot 9f3474d
Add MCP SDK integration with Streamable HTTP transport
Copilot 769eb4b
Run make fmt to fix formatting
Copilot 570d4ae
Address PR review feedback: add validation, use strongly typed tools,…
Copilot c718bd5
Extract test server setup into helper function
Copilot a0d5862
Fix linter error: use net.ListenConfig with context
Copilot da6ff72
Fix ServerVersion validation and use &mcp.ServerOptions{}
Copilot ee9e328
Add test coverage for healthTool to reach 94.9%
Copilot bd233c4
fix
yurishkuro 767d0a0
Refactor version variable name from 'version' to 'ver'
Copilot 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/extension" | ||
| "go.opentelemetry.io/collector/extension/extensioncapabilities" | ||
|
|
@@ -30,6 +31,7 @@ type server struct { | |
| telset component.TelemetrySettings | ||
| httpServer *http.Server | ||
| listener net.Listener | ||
| mcpServer *mcp.Server | ||
| } | ||
|
|
||
| // newServer creates a new MCP server instance. | ||
|
|
@@ -50,25 +52,48 @@ func (*server) Dependencies() []component.ID { | |
| func (s *server) Start(_ context.Context, host component.Host) error { | ||
| s.telset.Logger.Info("Starting Jaeger MCP server", zap.String("endpoint", s.config.HTTP.Endpoint)) | ||
|
|
||
| // TODO Phase 2: Get QueryService from jaegerquery extension | ||
| // TODO Phase 2 (part 2): Get QueryService from jaegerquery extension | ||
| // This will require jaegerquery to expose QueryService through an Extension interface, | ||
| // similar to how jaegerstorage exposes storage factories. | ||
| // For now, we just verify that jaegerquery extension is available. | ||
| _ = host | ||
|
|
||
| // TODO: Initialize MCP server with Streamable HTTP transport | ||
| // This will be implemented in Phase 2 once we add the MCP SDK dependency | ||
|
|
||
| // For Phase 1, we just set up a basic HTTP server to validate the extension lifecycle | ||
| //nolint:noctx // Phase 1 temporary implementation, will be replaced with MCP SDK in Phase 2 | ||
| // Initialize MCP server with implementation details | ||
| impl := &mcp.Implementation{ | ||
| Name: s.config.ServerName, | ||
| Version: s.config.ServerVersion, | ||
| } | ||
| // Pass nil for ServerOptions to use default settings. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed from |
||
| // Custom options (e.g., logging, handlers) can be added in Phase 2 if needed. | ||
| s.mcpServer = mcp.NewServer(impl, nil) | ||
|
yurishkuro marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Register a placeholder health tool for Phase 1 Part 2 | ||
| // Actual MCP tools will be implemented in Phase 2 | ||
| mcp.AddTool(s.mcpServer, &mcp.Tool{ | ||
| Name: "health", | ||
| Description: "Check if the Jaeger MCP server is running", | ||
| }, s.healthTool) | ||
|
|
||
| // Set up TCP listener | ||
| listener, err := net.Listen("tcp", s.config.HTTP.Endpoint) | ||
|
yurishkuro marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to listen on %s: %w", s.config.HTTP.Endpoint, err) | ||
| } | ||
| s.listener = listener | ||
|
|
||
| // Create a basic HTTP server | ||
| // Create MCP streamable HTTP handler | ||
| mcpHandler := mcp.NewStreamableHTTPHandler( | ||
| func(_ *http.Request) *mcp.Server { return s.mcpServer }, | ||
| &mcp.StreamableHTTPOptions{ | ||
| JSONResponse: false, // Use SSE for streamed events | ||
| Stateless: false, // Session state management | ||
| SessionTimeout: 5 * time.Minute, | ||
| }, | ||
| ) | ||
|
|
||
| // Create HTTP server with MCP handler and health endpoint | ||
| mux := http.NewServeMux() | ||
| mux.Handle("/mcp", mcpHandler) | ||
| mux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write([]byte("MCP server is running")) | ||
|
|
@@ -86,7 +111,9 @@ func (s *server) Start(_ context.Context, host component.Host) error { | |
| } | ||
| }() | ||
|
|
||
| s.telset.Logger.Info("Jaeger MCP server started successfully", zap.String("endpoint", s.config.HTTP.Endpoint)) | ||
| s.telset.Logger.Info("Jaeger MCP server started successfully", | ||
| zap.String("endpoint", s.config.HTTP.Endpoint), | ||
| zap.String("mcp_endpoint", "http://"+s.config.HTTP.Endpoint+"/mcp")) | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -103,3 +130,24 @@ func (s *server) Shutdown(ctx context.Context) error { | |
|
|
||
| return errors.Join(errs...) | ||
| } | ||
|
|
||
| // HealthToolOutput is the strongly-typed output for the health tool. | ||
| type HealthToolOutput struct { | ||
| Status string `json:"status" jsonschema:"Server status (ok/error)"` | ||
| Server string `json:"server" jsonschema:"Server name"` | ||
| Version string `json:"version" jsonschema:"Server version"` | ||
| } | ||
|
|
||
| // healthTool is a placeholder MCP tool that checks server health. | ||
| // Actual MCP tools for trace querying will be implemented in Phase 2. | ||
| func (s *server) healthTool( | ||
| _ context.Context, | ||
| _ *mcp.CallToolRequest, | ||
| _ struct{}, | ||
| ) (*mcp.CallToolResult, HealthToolOutput, error) { | ||
| return nil, HealthToolOutput{ | ||
|
yurishkuro marked this conversation as resolved.
|
||
| Status: "ok", | ||
| Server: s.config.ServerName, | ||
| Version: s.config.ServerVersion, | ||
| }, nil | ||
| } | ||
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
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.