Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions cmd/mcpcurl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,11 @@ func main() {
_, _ = fmt.Fprintf(os.Stderr, "Error getting pretty flag: %v\n", err)
os.Exit(1)
}
// Get server command

// Get server command and load tools
serverCmd, err := rootCmd.Flags().GetString("stdio-server-cmd")
if err == nil && serverCmd != "" {
// Fetch schema from server
jsonRequest, err := buildJSONRPCRequest("tools/list", "", nil)
if err == nil {
response, err := executeServerCommand(serverCmd, jsonRequest)
if err == nil {
// Parse the schema response
var schemaResp SchemaResponse
if err := json.Unmarshal([]byte(response), &schemaResp); err == nil {
// Add all the generated commands as subcommands of tools
for _, tool := range schemaResp.Result.Tools {
addCommandFromTool(toolsCmd, &tool, prettyPrint)
}
}
}
}
loadToolsFromServer(serverCmd, prettyPrint)
}

// Execute
Expand All @@ -201,6 +188,28 @@ func main() {
}
}

// loadToolsFromServer fetches the schema from the MCP server and registers tool commands
func loadToolsFromServer(serverCmd string, prettyPrint bool) {
jsonRequest, err := buildJSONRPCRequest("tools/list", "", nil)
if err != nil {
return
}

response, err := executeServerCommand(serverCmd, jsonRequest)
if err != nil {
return
}

var schemaResp SchemaResponse
if err := json.Unmarshal([]byte(response), &schemaResp); err != nil {
return
}

for _, tool := range schemaResp.Result.Tools {
addCommandFromTool(toolsCmd, &tool, prettyPrint)
}
}

// addCommandFromTool creates a cobra command from a tool schema
func addCommandFromTool(toolsCmd *cobra.Command, tool *Tool, prettyPrint bool) {
// Create command from tool
Expand Down
12 changes: 8 additions & 4 deletions pkg/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/mark3labs/mcp-go/server"
)

const (
refsHeadsPrefix = "refs/heads/"
)

func GetCommit(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("get_commit",
mcp.WithDescription(t("TOOL_GET_COMMITS_DESCRIPTION", "Get details for a commit from a GitHub repository")),
Expand Down Expand Up @@ -752,7 +756,7 @@ func DeleteFile(getClient GetClientFn, t translations.TranslationHelperFunc) (to
}

// Get the reference for the branch
ref, resp, err := client.Git.GetRef(ctx, owner, repo, "refs/heads/"+branch)
ref, resp, err := client.Git.GetRef(ctx, owner, repo, refsHeadsPrefix+branch)
if err != nil {
return nil, fmt.Errorf("failed to get branch reference: %w", err)
}
Expand Down Expand Up @@ -931,7 +935,7 @@ func CreateBranch(getClient GetClientFn, t translations.TranslationHelperFunc) (
}

// Get SHA of source branch
ref, resp, err := client.Git.GetRef(ctx, owner, repo, "refs/heads/"+fromBranch)
ref, resp, err := client.Git.GetRef(ctx, owner, repo, refsHeadsPrefix+fromBranch)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get reference",
Expand All @@ -943,7 +947,7 @@ func CreateBranch(getClient GetClientFn, t translations.TranslationHelperFunc) (

// Create new branch
newRef := &github.Reference{
Ref: github.Ptr("refs/heads/" + branch),
Ref: github.Ptr(refsHeadsPrefix + branch),
Object: &github.GitObject{SHA: ref.Object.SHA},
}

Expand Down Expand Up @@ -1041,7 +1045,7 @@ func PushFiles(getClient GetClientFn, t translations.TranslationHelperFunc) (too
}

// Get the reference for the branch
ref, resp, err := client.Git.GetRef(ctx, owner, repo, "refs/heads/"+branch)
ref, resp, err := client.Git.GetRef(ctx, owner, repo, refsHeadsPrefix+branch)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get branch reference",
Expand Down