MCPcopy Create free account
hub / github.com/cloudflare/agents / createGitToolProvider

Function createGitToolProvider

packages/shell/src/git/provider.ts:85–123  ·  view source on GitHub ↗
(
  gitInstance: Git,
  defaultToken?: string
)

Source from the content-addressed store, hash-verified

83const AUTH_COMMANDS = new Set(["clone", "fetch", "pull", "push"]);
84
85function createGitToolProvider(
86 gitInstance: Git,
87 defaultToken?: string
88): ToolProvider {
89 const tools: Record<
90 string,
91 { description: string; execute: (...args: unknown[]) => Promise<unknown> }
92 > = {};
93
94 for (const cmd of GIT_COMMAND_NAMES) {
95 const fn = gitInstance[cmd] as (
96 opts?: Record<string, unknown>
97 ) => Promise<unknown>;
98 tools[cmd] = {
99 description: `git.${cmd}`,
100 execute: (...args: unknown[]) => {
101 // positionalArgs mode: args may be [] (no args), [{}], or [{ url: ... }]
102 let opts = (args[0] ?? {}) as Record<string, unknown>;
103 // Auto-inject token for auth commands if not explicitly set
104 if (
105 defaultToken &&
106 AUTH_COMMANDS.has(cmd) &&
107 !opts.token &&
108 !opts.username
109 ) {
110 opts = { ...opts, token: defaultToken };
111 }
112 return fn.call(gitInstance, opts);
113 }
114 };
115 }
116
117 return {
118 name: "git",
119 tools,
120 types: GIT_TYPES,
121 positionalArgs: true
122 };
123}
124
125export interface GitToolsOptions {
126 /** Default directory for git operations. */

Callers 2

gitToolsFunction · 0.85
gitToolsFromFsFunction · 0.85

Calls 2

callMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected