@cyanheads/git-mcp-server 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-^5.8.3-blue?style=flat-square)](https://www.typescriptlang.org/)
8
8
  [![Model Context Protocol SDK](https://img.shields.io/badge/MCP%20SDK-^1.17.0-green?style=flat-square)](https://github.com/modelcontextprotocol/typescript-sdk)
9
9
  [![MCP Spec Version](https://img.shields.io/badge/MCP%20Spec-2025--06--18-lightgrey?style=flat-square)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-06-18/changelog.mdx)
10
- [![Version](https://img.shields.io/badge/Version-2.2.3-blue?style=flat-square)](./CHANGELOG.md)
10
+ [![Version](https://img.shields.io/badge/Version-2.2.4-blue?style=flat-square)](./CHANGELOG.md)
11
11
  [![Coverage](https://img.shields.io/badge/Coverage-0.0%25-red?style=flat-square)](./vitest.config.ts)
12
12
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
13
13
  [![Status](https://img.shields.io/badge/Status-Stable-green?style=flat-square)](https://github.com/cyanheads/git-mcp-server/issues)
@@ -182,6 +182,14 @@ See the current file tree in [docs/tree.md](docs/tree.md) or generate it dynamic
182
182
  npm run tree
183
183
  ```
184
184
 
185
+ ## 📦 Resources
186
+
187
+ In addition to tools, the server provides resources that offer contextual information about the Git environment.
188
+
189
+ | Resource URI | Description |
190
+ | :------------------------ | :--------------------------------------------------------------------------------------------------------- |
191
+ | `git://working-directory` | Returns the currently configured working directory for the session as a JSON object. Shows `NOT_SET` if unset. |
192
+
185
193
  ## 🧩 Extending the System
186
194
 
187
195
  The canonical pattern for adding new tools is defined in the [.clinerules](.clinerules) file. It mandates a strict separation of concerns:
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @fileoverview Barrel file for the git working directory resource.
3
+ * @module src/mcp-server/resources/gitWorkingDir/index
4
+ */
5
+ export * from "./registration.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @fileoverview Defines the core logic for the git working directory resource.
3
+ * @module src/mcp-server/resources/gitWorkingDir/logic
4
+ */
5
+ import { logger } from "../../../utils/index.js";
6
+ /**
7
+ * Retrieves the current working directory for the session.
8
+ * @param context The request context for logging and tracing.
9
+ * @param getWorkingDirectory Function to get the session's working directory.
10
+ * @param sessionId The ID of the current session.
11
+ * @returns The current working directory path or 'NOT_SET'.
12
+ */
13
+ export function getGitWorkingDirLogic(context, getWorkingDirectory, sessionId) {
14
+ logger.debug("Executing getGitWorkingDirLogic...", { ...context, sessionId });
15
+ const workingDir = getWorkingDirectory(sessionId);
16
+ return workingDir ?? "NOT_SET";
17
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @fileoverview Handles registration for the git working directory resource.
3
+ * @module src/mcp-server/resources/gitWorkingDir/registration
4
+ */
5
+ import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
6
+ import { logger, requestContextService } from "../../../utils/index.js";
7
+ import { getGitWorkingDirLogic } from "./logic.js";
8
+ import { ErrorHandler } from "../../../utils/index.js";
9
+ import { BaseErrorCode } from "../../../types-global/errors.js";
10
+ const RESOURCE_URI = "git://working-directory";
11
+ const RESOURCE_NAME = "git_working_directory";
12
+ const RESOURCE_DESCRIPTION = "A resource that returns the currently configured working directory for the Git session as a JSON object. Returns 'NOT_SET' if no directory is configured.";
13
+ /**
14
+ * Registers the Git Working Directory resource with the MCP server instance.
15
+ * @param server The MCP server instance.
16
+ * @param getWorkingDirectory Function to get the session's working directory.
17
+ * @param getSessionId Function to get the session ID from context.
18
+ */
19
+ export const registerGitWorkingDirResource = async (server, getWorkingDirectory, getSessionId) => {
20
+ const operation = "registerGitWorkingDirResource";
21
+ const context = requestContextService.createRequestContext({ operation });
22
+ await ErrorHandler.tryCatch(async () => {
23
+ const template = new ResourceTemplate(RESOURCE_URI, {
24
+ list: async () => ({ resources: [] }),
25
+ });
26
+ server.resource(RESOURCE_NAME, template, {
27
+ name: "Current Git Working Directory",
28
+ description: RESOURCE_DESCRIPTION,
29
+ mimeType: "application/json",
30
+ }, async (uri, params, callContext) => {
31
+ const handlerContext = requestContextService.createRequestContext({
32
+ parentRequestId: context.requestId,
33
+ operation: "HandleResourceRead",
34
+ resourceUri: uri.href,
35
+ inputParams: params,
36
+ });
37
+ try {
38
+ const sessionId = getSessionId(handlerContext);
39
+ const workingDir = getGitWorkingDirLogic(handlerContext, getWorkingDirectory, sessionId);
40
+ const responseData = { workingDirectory: workingDir };
41
+ return {
42
+ contents: [{
43
+ uri: uri.href,
44
+ text: JSON.stringify(responseData),
45
+ mimeType: "application/json",
46
+ }],
47
+ };
48
+ }
49
+ catch (error) {
50
+ throw ErrorHandler.handleError(error, {
51
+ operation: "gitWorkingDirReadHandler",
52
+ context: handlerContext,
53
+ input: { uri: uri.href, params },
54
+ });
55
+ }
56
+ });
57
+ logger.info(`Resource '${RESOURCE_NAME}' registered successfully.`, context);
58
+ }, {
59
+ operation: `RegisteringResource_${RESOURCE_NAME}`,
60
+ context: context,
61
+ errorCode: BaseErrorCode.INITIALIZATION_FAILED,
62
+ critical: true,
63
+ });
64
+ };
@@ -36,6 +36,8 @@ import { registerGitStatusTool } from "./tools/gitStatus/index.js";
36
36
  import { registerGitTagTool } from "./tools/gitTag/index.js";
37
37
  import { registerGitWorktreeTool } from "./tools/gitWorktree/index.js";
38
38
  import { registerGitWrapupInstructionsTool } from "./tools/gitWrapupInstructions/index.js";
39
+ // Import registration functions for ALL resources
40
+ import { registerGitWorkingDirResource } from "./resources/gitWorkingDir/index.js";
39
41
  // Import transport setup functions
40
42
  import { startHttpTransport } from "./transports/http/index.js";
41
43
  import { startStdioTransport } from "./transports/stdio/index.js";
@@ -103,6 +105,9 @@ async function createMcpServerInstance() {
103
105
  await registerGitWorktreeTool(server, getWorkingDirectory, getSessionIdFromContext);
104
106
  await registerGitWrapupInstructionsTool(server, getWorkingDirectory, getSessionIdFromContext);
105
107
  logger.info("Git tools registered successfully", context);
108
+ logger.debug("Registering Git resources...", context);
109
+ await registerGitWorkingDirResource(server, getWorkingDirectory, getSessionIdFromContext);
110
+ logger.info("Git resources registered successfully", context);
106
111
  }
107
112
  catch (err) {
108
113
  logger.error("Failed to register resources/tools", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyanheads/git-mcp-server",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "An MCP (Model Context Protocol) server enabling LLMs and AI agents to interact with Git repositories. Provides tools for comprehensive Git operations including clone, commit, branch, diff, log, status, push, pull, merge, rebase, worktree, tag management, and more, via the MCP standard. STDIO & HTTP.",
5
5
  "main": "dist/index.js",
6
6
  "files": [