Skip to content

Conversation

rlorenzo
Copy link
Contributor

@rlorenzo rlorenzo commented Aug 4, 2025

I was looking for an MCP server to use in my project to generate art assets and found your project. I couldn't get it to work out of the box, so here's a patch that got it working for me.

Some highlights:

  • Update environment variables to provider-namespaced format (PROVIDERS____)
  • Switch Gemini provider from Generative AI API to Vertex AI (to support Imagen-4)
  • Fix gpt-image-1 model capabilities (remove unsupported style parameter)
  • Add Claude Code MCP integration with start-mcp.sh script
  • Add .gitignore file with Python, IDE, and build artifacts exclusions
  • Fixed all failing tests and linting issues

rlorenzo and others added 2 commits August 3, 2025 09:39
- Add .gitignore file with Python, IDE, and build artifacts exclusions
- Improve code formatting and linting compliance across all modules
- Fixed failing tests
- Removing API key logging
- Update environment variables to provider-namespaced format (PROVIDERS__*__*)
- Switch Gemini provider from Generative AI API to Vertex AI with service account auth
- Fix gpt-image-1 model capabilities (remove unsupported style parameter)
- Add Claude Code MCP integration with start-mcp.sh script
- Update Docker configuration and documentation with Vertex AI setup instructions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 01:49
Copilot

This comment was marked as outdated.

@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 01:58
Copilot

This comment was marked as outdated.

@rlorenzo rlorenzo force-pushed the fix-tests-linting branch from 4f7d59f to f3b63d6 Compare August 4, 2025 02:05
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 02:05
Copilot

This comment was marked as outdated.

…prove flexibility

**Fix invalid test data creation**
- Replace corrupted image data (bytes * 1000) with proper PIL-generated PNG images
- Add create_larger_test_image() helper with comprehensive test coverage

**Enhance image format detection**
- Add _detect_image_format() function using byte signature analysis
- Replace hardcoded PNG assumption with actual format detection

**Optimize storage cleanup performance**
- Replace O(n²) directory scanning with O(n) incremental size tracking
- Calculate total size once, then decrement as files are deleted

**Make provider validation more flexible**
- Only validate providers that are actually enabled (not both required)
- ImageGenerationTool works with any enabled provider combination
- Update tests for new flexible validation behavior

All 104 tests passing with improved performance and correctness.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo rlorenzo force-pushed the fix-tests-linting branch from f3b63d6 to 5b03c6c Compare August 4, 2025 02:19
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 02:19
Copilot

This comment was marked as outdated.

- Add defensive hasattr checks in ImageEditingTool constructor with detailed error message
- Extract PNG signature to module constant in test_storage.py
- Extract image format magic numbers to named constants in validators.py
- Improve storage directory error messages with specific paths and solutions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 02:27
Copilot

This comment was marked as outdated.

- Improve comment clarity about MagicMock vs AsyncMock usage in test_tools.py
- Move inline import statements to top of test methods in test_storage.py
- Improve WebP signature detection readability with extracted is_webp variable
- Add comprehensive test suite for image format detection with magic numbers
- Verify environment variable names are already correct in image_generation.py

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 02:36
Copilot

This comment was marked as outdated.

…feedback

- Remove unnecessary parentheses in test assertion for cleaner code style
- Clarify size limit comment with explicit GB to MB conversion in test_storage.py
- Use double quotes consistently throughout conftest.py for string literals
- Extract WebP format detection to separate _is_webp_format() helper function
- Add comprehensive tests for WebP format detection helper function
- Update store_image() docstring to mark as deprecated with clearer guidance
- Extract OpenAI settings validation to _validate_openai_settings() helper method
- Add dedicated test for OpenAI settings validation helper method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 14:16
Copilot

This comment was marked as outdated.

- Simplify WebP return statement to single line for better readability
- Enhance deprecation notice with timeline (v1.5.0, Q4 2024) and migration examples
- Extract OpenAI validation to robust static method with comprehensive error handling
- Add extensive test coverage for static validation method with edge cases
- Fix critical package name mismatch in pyproject.toml (image-gen-mcp → gpt_image_mcp)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo rlorenzo requested a review from Copilot August 4, 2025 19:13
Copy link

@Copilot 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

This PR addresses multiple critical issues to make the image generation MCP server production-ready, focusing on fixing failing tests, updating environment variable formats, enhancing provider support, and improving development tooling.

Key Changes

  • Environment variables updated to provider-namespaced format (PROVIDERS__*__*)
  • Switch from Gemini Generative AI API to Vertex AI with support for Imagen-4
  • Fixed all failing tests and linting issues across the test suite

Reviewed Changes

Copilot reviewed 41 out of 50 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/test_utils.py Fixed imports, added image format detection tests, improved test structure
tests/unit/test_tools.py Complete rewrite with proper mocking and updated to new provider system
tests/unit/test_storage.py Added helper functions for larger test images, fixed async patterns
tests/unit/test_config.py Updated environment variable format and improved validation tests
tests/integration/test_server_integration.py Fixed integration tests with proper provider mocking
tests/conftest.py Added helper functions and improved fixture organization
start-mcp.sh New script for Claude Desktop integration with environment loading
scripts/dev.py Updated to use new environment variable format
run.sh Updated environment variable references
pyproject.toml Added new dependencies and proper package configuration
gpt_image_mcp/utils/validators.py Added image format detection with magic number signatures
gpt_image_mcp/utils/path_utils.py Improved formatting and type hints
gpt_image_mcp/utils/openai_client.py Enhanced error handling and cost estimation
gpt_image_mcp/utils/cache.py Improved type hints and statistics handling
gpt_image_mcp/types/models.py Simplified field definitions and improved formatting
gpt_image_mcp/types/enums.py Added BLACK background type, improved descriptions
gpt_image_mcp/types/init.py Reordered imports for consistency
gpt_image_mcp/tools/image_generation.py Major refactor for new provider system with better error handling
gpt_image_mcp/tools/image_editing.py Enhanced validation and improved OpenAI client integration
gpt_image_mcp/tools/init.py Reordered imports for consistency
gpt_image_mcp/storage/manager.py Added comprehensive storage management with cleanup and compatibility methods

…nd test patterns

- Use specific Union[bytes, str] type instead of Any for image_data parameter
- Update deprecation notice with specific version and date
- Simplify WebP format detection return statement for better readability
- Replace __new__ pattern with direct static method testing in tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rlorenzo
Copy link
Contributor Author

@lansespirit, is there any chance these changes can be merged in? I have been using this project in an app recently, and it has been working out great. I hope that others will find it helpful as well.

@lansespirit lansespirit merged commit 1c5b672 into lansespirit:main Aug 27, 2025
@lansespirit
Copy link
Owner

@rlorenzo Thanks for your work, good job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants