Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexei-led
Copy link
Owner

Summary

  • Add MCP server functionality to enable AI assistant integration
  • Implement comprehensive spot instance search and region listing tools
  • Optimize and simplify Makefile for better maintainability

Key Features

  • MCP Server Mode: Run spotinfo as MCP server with --mcp flag
  • AI Integration: Works with Claude Desktop and other MCP clients
  • Two MCP Tools:
    • find_spot_instances: Search spots by requirements (region, type, pricing, etc.)
    • list_spot_regions: Get available AWS regions
  • Comprehensive Documentation: Setup guides and API reference

Technical Changes

  • New MCP server implementation in internal/mcp/
  • Enhanced CLI with MCP mode detection
  • Comprehensive test coverage with mocks
  • Optimized Makefile (reduced from 157 to 129 lines)
  • Removed fmt dependency from test targets

Test Plan

  • All existing functionality works unchanged
  • MCP server starts and responds correctly
  • Tools return valid JSON responses
  • Integration with Claude Desktop verified
  • Cross-platform builds successful
  • All tests pass including new MCP tests

- 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
@alexei-led alexei-led requested a review from Copilot June 29, 2025 08:07
@alexei-led alexei-led added the enhancement New feature or request label Jun 29, 2025
@alexei-led alexei-led self-assigned this Jun 29, 2025
Copy link

Copilot AI left a 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_instances and list_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, and regions_searched but doesn’t assert data_freshness. Add an assertion like assert.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",
Copy link

Copilot AI Jun 29, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 81 to 82
@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
Copy link

Copilot AI Jun 29, 2025

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.

Suggested change
@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

Copilot uses AI. Check for mistakes.
- 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%
@alexei-led alexei-led merged commit 6dde388 into master Jun 29, 2025
3 checks passed
@alexei-led alexei-led deleted the feature/mcp-server branch June 29, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants