Skip to content

feat: CP-1037 New MCP tool to create revision from dependency list #3706

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 4 commits into from
Aug 15, 2025

Conversation

samueld-activator
Copy link
Contributor

@samueld-activator samueld-activator commented Aug 13, 2025

Sub-taskCP-1037 New MCP tool to create revision from dependency list

Comment on lines 263 to 282
namespace, err := mcpRequest.RequireString("namespace")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient namespace is required: %s", errs.JoinMessage(err))), nil
}
name, err := mcpRequest.RequireString("name")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient name is required: %s", errs.JoinMessage(err))), nil
}
version, err := mcpRequest.RequireString("version")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient version is required: %s", errs.JoinMessage(err))), nil
}
dependencies, err := mcpRequest.RequireString("dependencies")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("the ingredient dependencies are required: %s", errs.JoinMessage(err))), nil
}
comment, err := mcpRequest.RequireString("comment")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a comment for the ingredient is required: %s", errs.JoinMessage(err))), nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary? You're already specifying mcp.Required().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doc for mcp.Required() says "Required marks a property as required in the tool's input schema. Required properties must be provided when using the tool."

I think if the LLM does not provide these required args, the MCP server will complain, so we should be safe here. Do you think we should ignore the errors in mcpRequest.RequireString() then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"RequireString returns a string argument by key, or an error if not found or not a string"

Not sure the LLM would provide something that is not a string, in which case the MCP server is probably not checking on that for us.

Copy link
Member

Choose a reason for hiding this comment

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

I'd try to verify that the library itself already handles it. Basically it should not even reach your RequireString logic if it was already required. If it does I'd consider that a pretty awkward design on the libraries part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even in the tool's examples, it suggests checking for the error. e.g. here

Do you suggest I just ignore the errors here by setting them to _?

var dependencies []inventory_models.Dependency
err := json.Unmarshal([]byte(params.dependencies), &dependencies)
if err != nil {
return fmt.Errorf("error unmarshaling dependencies, dependency JSON is in wrong format: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Please use errs.Wrap(). Goes for all the changes in this PR.

Comment on lines 62 to 70
getParams := inventory_operations.NewGetIngredientVersionRevisionsParams()
getParams.SetIngredientID(*ingredient.IngredientID)
getParams.SetIngredientVersionID(*ingredient.IngredientVersionID)

client := inventory.Get(runner.auth)
revisions, err := client.GetIngredientVersionRevisions(getParams, runner.auth.ClientAuth())
if err != nil {
return fmt.Errorf("error getting version revisions: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Please make this a function inside the model package, just like the model.GetIngredientByNameAndVersion function above.

Goes for the other requests here also. Point is to keep the controller logic concerned with control flow, not with constructing API requests.

buildScriptIDs = append(buildScriptIDs, *script.BuildScriptID)
}

// Replicate patches
Copy link
Member

Choose a reason for hiding this comment

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

Seeing a pattern here; seems these are all related to the single action of creating a new revision?

I'd suggest making that itself a function in the model package, which can itself reach out to other model functions. So you'd have something like model.CreateNewRevision(source *Ingredient, ...).

Logic here seems sound, just concerned about reusability and keeping things object oriented.

Naatan
Naatan previously approved these changes Aug 15, 2025
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Looks good! One minor nit, up to you what you do with it.

case "default":
default_optsets = append(default_optsets, *optset.IngredientOptionSetID)
case "override":
override_optsets = append(override_optsets, *optset.IngredientOptionSetID)
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding a default handler that errors out (eg. unrecognized type). Even if there are only 2, that should future proof us somewhat in the sense that if this change in the future it'll be immediately apparent that our code needs updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@samueld-activator samueld-activator merged commit 8ec8759 into master Aug 15, 2025
7 of 8 checks passed
@samueld-activator samueld-activator deleted the samueld/CP-1037 branch August 15, 2025 21:11
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