Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Fix self-service action creation when invocationMethod is provided as JSON string#53

Merged
Matanga1-2 merged 13 commits intomainfrom
copilot/fix-52
Jul 1, 2025
Merged

Fix self-service action creation when invocationMethod is provided as JSON string#53
Matanga1-2 merged 13 commits intomainfrom
copilot/fix-52

Conversation

Copy link
Contributor

Copilot AI commented Jun 26, 2025

Problem

When using Claude via the MCP server to create self-service actions, the action creation was failing because the invocationMethod field was being passed as a JSON string instead of a proper JSON object. This caused Pydantic validation to fail since it expected one of the specific ActionInvocationMethod union types (WEBHOOK, GITHUB, GITLAB, etc.), not a string.

Example of the problematic input:

{
  "invocationMethod": "{\"type\": \"WEBHOOK\", \"url\": \"https://...\", \"method\": \"POST\"}"
}

Should be:

{
  "invocationMethod": {"type": "WEBHOOK", "url": "https://...", "method": "POST"}
}

Solution

Added field validation and model validation to the CreateActionToolSchema class that:

  1. Field Validator: Detects when invocation_method is provided as a JSON string and parses it into a dictionary
  2. Model Validator: Handles the invocationMethod alias and parses JSON strings at the model level
  3. Comprehensive Coverage: Works with all invocation method types (WEBHOOK, GITHUB, GITLAB, AZURE-DEVOPS, KAFKA)
  4. Backward Compatibility: Maintains support for existing object-based invocation methods
  5. Error Handling: Provides clear error messages for invalid JSON strings

Changes

  • Enhanced CreateActionToolSchema with @field_validator and @model_validator decorators
  • Added JSON string parsing logic that gracefully handles both string and object inputs
  • Added comprehensive test cases covering both WEBHOOK and GITHUB invocation method types
  • Ensured the fix works for both invocationMethod and invocation_method field names

Testing

Added test cases that verify:

  • ✅ String JSON invocation method parsing for WEBHOOK type
  • ✅ String JSON invocation method parsing for GITHUB type
  • ✅ Normal object invocation methods continue to work
  • ✅ Invalid JSON strings produce clear error messages

The fix is minimal and surgical - it only adds the necessary validation to handle the specific Claude integration issue without affecting any other functionality.

Fixes #52.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 26, 2025 06:44
Co-authored-by: Matanga1-2 <24847398+Matanga1-2@users.noreply.github.com>
Co-authored-by: Matanga1-2 <24847398+Matanga1-2@users.noreply.github.com>
Copilot AI changed the title [WIP] Self-service action creation sometimes fails Fix self-service action creation when invocationMethod is provided as JSON string Jun 26, 2025
Copilot AI requested a review from Matanga1-2 June 26, 2025 06:52
Copy link
Collaborator

@Matanga1-2 Matanga1-2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CleanShot 2025-06-29 at 21 46 03@2x

It works better now, as the input generated by Claude is transformed to a correct one in Port.

Please

  1. Consider if there is also a required change to prevent the AI from generating the bad input to start with (maybe in the tool description? properties?)
  2. Upsert the version in pyproject.toml and add a new changelog entry

…ring fix

Co-authored-by: Matanga1-2 <24847398+Matanga1-2@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 29, 2025

CleanShot 2025-06-29 at 21 46 03@2x

It works better now, as the input generated by Claude is transformed to a cor...

I've addressed both points:

  1. Preventive improvements: Enhanced the tool description and field descriptions to guide AI models to provide the correct JSON object format from the start. Added clear examples and warnings in the tool description.

  2. Version and changelog: Updated version to 0.2.19 in pyproject.toml (fixed duplicate entries) and added a comprehensive changelog entry documenting the fix.

Changes are in commit 2b5fb4d.

Copilot AI requested a review from Matanga1-2 June 29, 2025 18:55
@Matanga1-2 Matanga1-2 marked this pull request as ready for review July 1, 2025 07:12
@Matanga1-2 Matanga1-2 requested a review from a team as a code owner July 1, 2025 07:12
@Matanga1-2 Matanga1-2 merged commit 9275ed1 into main Jul 1, 2025
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-service action creation sometimes fails

3 participants