CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository.
(t translations.TranslationHelperFunc)
| 378 | |
| 379 | // CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository. |
| 380 | func CreateOrUpdateFile(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 381 | return NewTool( |
| 382 | ToolsetMetadataRepos, |
| 383 | mcp.Tool{ |
| 384 | Name: "create_or_update_file", |
| 385 | Description: t("TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION", `Create or update a single file in a GitHub repository. |
| 386 | If updating, you should provide the SHA of the file you want to update. Use this tool to create or update a file in a GitHub repository remotely; do not use it for local file operations. |
| 387 | |
| 388 | In order to obtain the SHA of original file version before updating, use the following git command: |
| 389 | git rev-parse <branch>:<path to file> |
| 390 | |
| 391 | SHA MUST be provided for existing file updates. |
| 392 | `), |
| 393 | Annotations: &mcp.ToolAnnotations{ |
| 394 | Title: t("TOOL_CREATE_OR_UPDATE_FILE_USER_TITLE", "Create or update file"), |
| 395 | ReadOnlyHint: false, |
| 396 | }, |
| 397 | InputSchema: &jsonschema.Schema{ |
| 398 | Type: "object", |
| 399 | Properties: map[string]*jsonschema.Schema{ |
| 400 | "owner": { |
| 401 | Type: "string", |
| 402 | Description: "Repository owner (username or organization)", |
| 403 | }, |
| 404 | "repo": { |
| 405 | Type: "string", |
| 406 | Description: "Repository name", |
| 407 | }, |
| 408 | "path": { |
| 409 | Type: "string", |
| 410 | Description: "Path where to create/update the file", |
| 411 | }, |
| 412 | "content": { |
| 413 | Type: "string", |
| 414 | Description: "Content of the file", |
| 415 | }, |
| 416 | "message": { |
| 417 | Type: "string", |
| 418 | Description: "Commit message", |
| 419 | }, |
| 420 | "branch": { |
| 421 | Type: "string", |
| 422 | Description: "Branch to create/update the file in", |
| 423 | }, |
| 424 | "sha": { |
| 425 | Type: "string", |
| 426 | Description: "The blob SHA of the file being replaced. Required if the file already exists.", |
| 427 | }, |
| 428 | }, |
| 429 | Required: []string{"owner", "repo", "path", "content", "message", "branch"}, |
| 430 | }, |
| 431 | }, |
| 432 | []scopes.Scope{scopes.Repo}, |
| 433 | func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 434 | owner, err := RequiredParam[string](args, "owner") |
| 435 | if err != nil { |
| 436 | return utils.NewToolResultError(err.Error()), nil, nil |
| 437 | } |