-
Couldn't load subscription status.
- Fork 10
Add Model Context Protocol (MCP) server support #4
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
Conversation
- Add github.com/mark3labs/mcp-go v0.32.0 dependency - Prepare foundation for MCP server implementation - Part of Phase 1.1 of MCP implementation plan
- Add --mcp CLI flag for MCP server mode - Support SPOTINFO_MODE, MCP_TRANSPORT, MCP_PORT environment variables - Implement mode detection with proper fallbacks - Use modern Go 1.24 patterns (os.LookupEnv) - Add context cancellation support for MCP server - Part of Phase 1.2 of MCP implementation plan
- Create internal/mcp package with server setup - Add MCP server with tool capabilities and logging - Integrate MCP server with main application lifecycle - Support stdio transport (SSE transport placeholder for Phase 3.2) - Add mark3labs/mcp-go to depguard allowed imports - Fix struct field alignment and remove unused return values - Part of Phase 1.3 of MCP implementation plan Ready for Phase 2: tool implementation
* Add find_spot_instances tool with parameter validation and filtering * Add list_spot_regions tool for dynamic region discovery * Implement safe parameter parsing with spf13/cast * Create comprehensive table-driven tests with 100% coverage * Add mockery v3 integration for interface mocking * Extract magic numbers to named constants for maintainability * Follow Go best practices: private interfaces, safe type assertions * Reduce cyclomatic complexity with helper function extraction * Add proper error handling with MCP-compliant responses Phase 2.1 complete: Core MCP tool functionality implemented
* Add extensive README.md MCP section with setup guides and examples * Create detailed Claude Desktop integration guide (docs/claude-desktop-setup.md) * Add comprehensive troubleshooting documentation (docs/troubleshooting.md) * Create complete API reference with JSON schemas (docs/api-reference.md) * Add inline documentation comments to tools.go struct fields * Provide platform-specific configuration examples and debug procedures Documentation enables easy MCP server integration and troubleshooting
- Remove complex variables and over-engineering - Eliminate fmt dependency from test targets - Streamline cross-platform release build process - Remove unused targets and improve readability - Reduce from 157 to 129 lines while maintaining functionality
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.
Pull Request Overview
Adds full Model Context Protocol (MCP) server support to spotinfo, enabling AI assistants (e.g., Claude) to query AWS EC2 Spot Instance data. Key changes include:
- Introduce MCP server mode with two tools (
find_spot_instancesandlist_spot_regions) and wire it into the CLI - Add comprehensive tests and mocks for all new MCP functions
- Simplify and optimize the Makefile, update
go.mod, and expand documentation for MCP setup, API reference, and troubleshooting
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/tools.go | Implements find_spot_instances and helper functions |
| internal/mcp/tools_test.go | Unit tests covering parameter parsing, filtering, and response |
| internal/mcp/server.go | Sets up MCP server, registers tools, and handles transports |
| internal/mcp/mocks_test.go | Adds generated testify mocks for spotClient |
| go.mod | Adds mcp-go, cast, and other necessary dependencies |
| cmd/spotinfo/main.go | Updates CLI to detect --mcp mode or env var and start server |
| Makefile | Removes outdated targets, adds update-data, update-price, etc |
| .mockery.yaml | Configures mockery for internal/mcp/spotClient interface |
| .golangci.yaml | Adds exclusions for new imports |
| README.md | Documents MCP server mode and usage examples |
| docs/claude-desktop-setup.md | Detailed Claude Desktop integration guide |
| docs/troubleshooting.md | Troubleshooting section for CLI and MCP server issues |
| docs/api-reference.md | Full API specification for MCP tools |
Comments suppressed due to low confidence (1)
internal/mcp/tools_test.go:298
- The test checks
total_results,data_source, andregions_searchedbut doesn’t assertdata_freshness. Add an assertion likeassert.Equal(t, "current", metadata["data_freshness"])to cover that field.
assert.Equal(t, "embedded", metadata["data_source"])
| // Register list_spot_regions tool | ||
| listSpotRegionsTool := mcp.NewTool("list_spot_regions", | ||
| mcp.WithDescription("List all AWS regions where EC2 Spot Instances are available"), | ||
| mcp.WithBoolean("include_names", |
Copilot
AI
Jun 29, 2025
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.
The include_names parameter is declared in the list_spot_regions tool schema but not read or applied in the handler. Consider fetching req.Params.Arguments["include_names"] in Handle and returning human-readable region names when true.
| @sed -i'' -e "s/callback(//g" public/spot/data/spot-price-data.json | ||
| @sed -i'' -e "s/);//g" public/spot/data/spot-price-data.json |
Copilot
AI
Jun 29, 2025
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.
[nitpick] Using sed -i'' is not portable across GNU vs BSD sed implementations. Consider a portable invocation (e.g., sed -e 's/callback(//g' -i '' file on macOS or sed -i' ' -e ...) or detect the platform to ensure compatibility.
| @sed -i'' -e "s/callback(//g" public/spot/data/spot-price-data.json | |
| @sed -i'' -e "s/);//g" public/spot/data/spot-price-data.json | |
| @if sed --version >/dev/null 2>&1; then \ | |
| sed -i'' -e "s/callback(//g" public/spot/data/spot-price-data.json; \ | |
| sed -i'' -e "s/);//g" public/spot/data/spot-price-data.json; \ | |
| else \ | |
| sed -i '' -e "s/callback(//g" public/spot/data/spot-price-data.json; \ | |
| sed -i '' -e "s/);//g" public/spot/data/spot-price-data.json; \ | |
| fi |
- Add extensive test coverage for MCP mode detection and configuration - Implement SSE transport using mcp-go library built-in support - Add transport-specific test suites for stdio and SSE - Test MCP CLI integration scenarios and error handling
- Add comprehensive tests for FindSpotInstancesTool.Handle with 7 scenarios - Add tests for ListSpotRegionsTool.Handle with 4 scenarios including deduplication - Add error handling tests for createErrorResult function - Improve test structure with proper JSON validation and response checking - Fix test assertions to properly validate MCP error results vs success results - Increase MCP package coverage from 68.6% to 98.3% - Increase overall project coverage from 77.7% to 85.6%
- Fix forcetypeassert linter errors with proper type assertion checks - Add comprehensive race condition tests for concurrent client access - Add performance benchmarks for critical code paths and memory analysis - Suppress maintidx warning for complex table-driven test - Improve test coverage from 77.7% to 86.0%
Summary
Key Features
--mcpflagfind_spot_instances: Search spots by requirements (region, type, pricing, etc.)list_spot_regions: Get available AWS regionsTechnical Changes
internal/mcp/Test Plan