MCPcopy
hub / github.com/github/github-mcp-server / CreateOrUpdateFile

Function CreateOrUpdateFile

pkg/github/repositories.go:380–573  ·  view source on GitHub ↗

CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository.

(t translations.TranslationHelperFunc)

Source from the content-addressed store, hash-verified

378
379// CreateOrUpdateFile creates a tool to create or update a file in a GitHub repository.
380func 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.
386If 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
388In order to obtain the SHA of original file version before updating, use the following git command:
389git rev-parse <branch>:<path to file>
390
391SHA 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 }

Callers 2

AllToolsFunction · 0.85
Test_CreateOrUpdateFileFunction · 0.85

Calls 7

NewToolResultErrorFunction · 0.92
NewToolFunction · 0.85
MarshalledTextResultFunction · 0.85
CloseMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.45

Tested by 1

Test_CreateOrUpdateFileFunction · 0.68