mcp-perforce-server 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iPraBhu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,205 @@
1
+ # MCP Perforce Server Configuration Examples
2
+
3
+ ## Silent Operation Configuration
4
+
5
+ To prevent VS Code from asking for approval on every command and to hide terminal execution:
6
+
7
+ **Key Settings:**
8
+ - `"alwaysAllow": ["p4.*"]` or `"alwaysAllow": true` - Auto-approve all p4 commands
9
+ - `"LOG_LEVEL": "error"` - Minimize console output (only show errors)
10
+ - `"disabled": false` - Ensure server is enabled
11
+
12
+ ## VS Code with Claude Dev/Cline
13
+
14
+ ### Option 1: Using .p4config file (Recommended)
15
+ Create a `.p4config` file in your project root, then:
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "perforce": {
20
+ "command": "mcp-perforce-server",
21
+ "args": [],
22
+ "env": {
23
+ "P4_READONLY_MODE": "false",
24
+ "P4_DISABLE_DELETE": "true",
25
+ "LOG_LEVEL": "error"
26
+ },
27
+ "alwaysAllow": ["p4.*"],
28
+ "disabled": false
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### Option 2: Direct configuration in MCP config
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "perforce": {
39
+ "command": "mcp-perforce-server",
40
+ "args": [],
41
+ "env": {
42
+ "P4PORT": "perforce-server:1666",
43
+ "P4USER": "your-username",
44
+ "P4CLIENT": "your-workspace-name",
45
+ "P4CHARSET": "utf8",
46
+ "P4_READONLY_MODE": "false",
47
+ "P4_DISABLE_DELETE": "true",
48
+ "LOG_LEVEL": "error"
49
+ },
50
+ "alwaysAllow": ["p4.*"],
51
+ "disabled": false
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## Cursor IDE
58
+
59
+ ### Option 1: Using .p4config file (Recommended)
60
+ ```json
61
+ {
62
+ "mcp": {
63
+ "servers": {
64
+ "perforce": {
65
+ "command": "mcp-perforce-server",
66
+ "args": [],
67
+ "env": {
68
+ "P4_READONLY_MODE": "false",
69
+ "P4_DISABLE_DELETE": "true",
70
+ "LOG_LEVEL": "error"
71
+ },
72
+ "alwaysAllow": true
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Option 2: Direct configuration in MCP config
80
+ ```json
81
+ {
82
+ "mcp": {
83
+ "servers": {
84
+ "perforce": {
85
+ "command": "mcp-perforce-server",
86
+ "args": [],
87
+ "env": {
88
+ "P4PORT": "perforce-server:1666",
89
+ "P4USER": "your-username",
90
+ "P4CLIENT": "your-workspace-name",
91
+ "P4_READONLY_MODE": "false",
92
+ "P4_DISABLE_DELETE": "true",
93
+ "LOG_LEVEL": "error"
94
+ },
95
+ "alwaysAllow": true
96
+ }
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Claude Desktop
103
+
104
+ ### macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
105
+ ### Windows: %APPDATA%\Claude\claude_desktop_config.json
106
+
107
+ ### Option 1: Using .p4config file (Recommended)
108
+ ```json
109
+ {
110
+ "mcpServers": {
111
+ "perforce": {
112
+ "command": "mcp-perforce-server",
113
+ "args": [],
114
+ "env": {
115
+ "P4_READONLY_MODE": "false",
116
+ "P4_DISABLE_DELETE": "true",
117
+ "LOG_LEVEL": "error"
118
+ },
119
+ "alwaysAllow": ["p4.*"]
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ ### Option 2: Direct configuration in MCP config
126
+ ```json
127
+ {
128
+ "mcpServers": {
129
+ "perforce": {
130
+ "command": "mcp-perforce-server",
131
+ "args": [],
132
+ "env": {
133
+ "P4PORT": "perforce-server:1666",
134
+ "P4USER": "your-username",
135
+ "P4CLIENT": "your-workspace-name",
136
+ "P4_READONLY_MODE": "false",
137
+ "P4_DISABLE_DELETE": "true",
138
+ "LOG_LEVEL": "error"
139
+ },
140
+ "alwaysAllow": ["p4.*"]
141
+ }
142
+ }
143
+ }
144
+ ```
145
+
146
+ ## Local Development Setup (if not globally installed)
147
+
148
+ Replace the "command" field with the full path to your built server:
149
+
150
+ ```json
151
+ {
152
+ "command": "node",
153
+ "args": ["/full/path/to/your/mcp-perforce-server/dist/server.js"]
154
+ }
155
+ ```
156
+
157
+ ## Safety Configuration Levels
158
+
159
+ ### Maximum Safety (Default)
160
+ ```json
161
+ {
162
+ "env": {
163
+ "P4_READONLY_MODE": "true",
164
+ "P4_DISABLE_DELETE": "true"
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Write-enabled, Delete Protected
170
+ ```json
171
+ {
172
+ "env": {
173
+ "P4_READONLY_MODE": "false",
174
+ "P4_DISABLE_DELETE": "true"
175
+ }
176
+ }
177
+ ```
178
+
179
+ ## Configuration Notes
180
+
181
+ ### Silent Operation
182
+ - `"alwaysAllow": ["p4.*"]` - Auto-approves all p4 commands, preventing VS Code approval prompts
183
+ - `"alwaysAllow": true` - Auto-approves all commands (Cursor)
184
+ - `"LOG_LEVEL": "error"` - Reduces console output to errors only
185
+ - `"disabled": false` - Ensures the server is active
186
+
187
+ ### Security Levels
188
+ - **Safe**: `P4_READONLY_MODE=true, P4_DISABLE_DELETE=true` (read-only)
189
+ - **Recommended**: `P4_READONLY_MODE=false, P4_DISABLE_DELETE=true` (write, no delete)
190
+ - **Full Access**: `P4_READONLY_MODE=false, P4_DISABLE_DELETE=false` (use with caution)
191
+
192
+ ### Troubleshooting
193
+ - If commands still show approval prompts, ensure `alwaysAllow` is configured
194
+ - If you see terminal output, set `LOG_LEVEL` to `"error"`
195
+ - Commands execute silently in the background without terminal windows
196
+
197
+ ### Full Access (Use with Caution)
198
+ ```json
199
+ {
200
+ "env": {
201
+ "P4_READONLY_MODE": "false",
202
+ "P4_DISABLE_DELETE": "false"
203
+ }
204
+ }
205
+ ```
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # MCP Perforce Server
2
+
3
+ [![npm version](https://badge.fury.io/js/mcp-perforce-server.svg)](https://www.npmjs.com/package/mcp-perforce-server)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
7
+
8
+ Enterprise-grade MCP (Model Context Protocol) server providing secure, non-interactive Perforce operations for AI-assisted development workflows with Claude, ChatGPT, VS Code, and Cursor IDE.
9
+
10
+ > **Created by [Pratik Bhuite](https://github.com/iPraBhu)** using vibe coding to solve real-world Perforce automation challenges. Open source, community-driven, and ready for customization!
11
+
12
+ ## Overview
13
+
14
+ Production-ready server that exposes Perforce VCS operations through the Model Context Protocol, enabling AI assistants and code editors to interact with Perforce repositories safely and efficiently. Perfect for DevOps automation, enterprise development workflows, and AI-powered version control management.
15
+
16
+ **Key Features:**
17
+ - 🔒 **Enterprise Security** - Read-only defaults with configurable access controls
18
+ - 🌐 **Cross-platform Support** - Windows, macOS, Linux compatibility
19
+ - 🤖 **AI Integration** - Works with Claude, ChatGPT, VS Code, Cursor, and other AI assistants
20
+ - ⚡ **Non-interactive Operations** - Automated Perforce commands with comprehensive error handling
21
+ - 📁 **Multi-project Support** - Automatic `.p4config` detection with upward directory search
22
+ - 🛡️ **Production Ready** - Structured JSON responses with standardized error codes
23
+ - 🔧 **Developer Friendly** - TypeScript support with comprehensive documentation
24
+ - 🚀 **Zero Configuration** - Works out-of-the-box with sensible defaults
25
+
26
+ ## Why Choose MCP Perforce Server?
27
+
28
+ **Alternative to:**
29
+ - Manual Perforce CLI operations in AI workflows
30
+ - Custom Git-to-Perforce bridges for AI assistants
31
+ - Unsafe direct P4 command execution in development environments
32
+ - Complex Perforce API integrations for code assistants
33
+
34
+ **Perfect for:**
35
+ - Enterprise teams using Perforce with AI development tools
36
+ - DevOps automation with Anthropic Claude or OpenAI ChatGPT
37
+ - VS Code and Cursor IDE users working with Perforce repositories
38
+ - Secure version control operations in AI-assisted coding workflows
39
+
40
+ ## Origin Story
41
+
42
+ This project was born from a real need! I ([Pratik Bhuite](https://github.com/iPraBhu)) was facing challenges integrating Perforce with AI development tools and decided to solve it using **vibe coding** - building something that just works, feels right, and solves real problems.
43
+
44
+ **🤝 Community Welcome**
45
+ - ✅ **Use freely** - This is open source, use it however you need
46
+ - 🐛 **Report issues** - Found a bug? Please let me know!
47
+ - 🔧 **Customize** - Fork it, modify it, make it yours
48
+ - 💡 **Contribute** - Ideas, PRs, and feedback are always welcome
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install -g mcp-perforce-server
54
+ ```
55
+
56
+ ## Quick Start
57
+
58
+ 1. **Prerequisites:** Perforce CLI (`p4`) installed and in PATH
59
+
60
+ 2. **Configuration:** Choose one method:
61
+
62
+ **Method A: .p4config file** (Recommended)
63
+ ```
64
+ P4PORT=your-perforce-server:1666
65
+ P4USER=your-username
66
+ P4CLIENT=your-workspace-name
67
+ ```
68
+
69
+ **Method B: MCP Environment Variables**
70
+ ```json
71
+ {
72
+ "mcpServers": {
73
+ "perforce": {
74
+ "command": "mcp-perforce-server",
75
+ "env": {
76
+ "P4PORT": "your-perforce-server:1666",
77
+ "P4USER": "your-username",
78
+ "P4CLIENT": "your-workspace-name"
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ 3. **Verification:**
86
+ ```bash
87
+ mcp-perforce-server --help
88
+ ```
89
+
90
+ ## Security Configuration
91
+
92
+ **Default Security Posture:**
93
+ - `P4_READONLY_MODE=true` - Read-only operations only
94
+ - `P4_DISABLE_DELETE=true` - Delete operations disabled
95
+
96
+ **Production Environments:**
97
+ ```bash
98
+ # Read-only mode (safest)
99
+ P4_READONLY_MODE=true P4_DISABLE_DELETE=true
100
+
101
+ # Write-enabled, delete-protected (recommended)
102
+ P4_READONLY_MODE=false P4_DISABLE_DELETE=true
103
+
104
+ # Full access (use with caution)
105
+ P4_READONLY_MODE=false P4_DISABLE_DELETE=false
106
+ ```
107
+
108
+ ## Supported Operations
109
+
110
+ ### Repository Operations
111
+ - `p4.info` - Server and client information
112
+ - `p4.status` - Workspace status
113
+ - `p4.sync` - Sync from depot
114
+ - `p4.opened` - List opened files
115
+
116
+ ### File Operations
117
+ - `p4.add` - Add files to Perforce
118
+ - `p4.edit` - Open files for edit
119
+ - `p4.delete` - Mark files for deletion
120
+ - `p4.revert` - Revert changes
121
+ - `p4.diff` - Show file differences
122
+
123
+ ### Changelist Operations
124
+ - `p4.changelist.create` - Create new changelist
125
+ - `p4.changelist.update` - Update changelist
126
+ - `p4.changelist.submit` - Submit changelist
127
+ - `p4.submit` - Submit default changelist
128
+
129
+ ### Utilities
130
+ - `p4.filelog` - File history
131
+ - `p4.clients` - List workspaces
132
+ - `p4.config.detect` - Configuration diagnostics
133
+
134
+ ## Integration
135
+
136
+ ### VS Code / Cursor
137
+ For silent operation without approval prompts, add these settings:
138
+ ```json
139
+ {
140
+ "mcpServers": {
141
+ "perforce": {
142
+ "command": "mcp-perforce-server",
143
+ "env": {
144
+ "P4_READONLY_MODE": "false",
145
+ "LOG_LEVEL": "error"
146
+ },
147
+ "alwaysAllow": ["p4.*"],
148
+ "disabled": false
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ See [MCP_CONFIG_EXAMPLES.md](MCP_CONFIG_EXAMPLES.md) for IDE-specific configuration.
155
+
156
+ ### Claude Desktop
157
+ Add to `claude_desktop_config.json`:
158
+ ```json
159
+ {
160
+ "mcpServers": {
161
+ "perforce": {
162
+ "command": "mcp-perforce-server",
163
+ "env": {
164
+ "P4_READONLY_MODE": "false"
165
+ }
166
+ }
167
+ }
168
+ }
169
+ ```
170
+
171
+ ## Environment Variables
172
+
173
+ | Variable | Description | Default |
174
+ |----------|-------------|---------|
175
+ | `P4_READONLY_MODE` | Enable read-only mode | `true` |
176
+ | `P4_DISABLE_DELETE` | Disable delete operations | `true` |
177
+ | `P4_PATH` | Path to p4 executable | `p4` |
178
+ | `P4CONFIG` | Config file name | `.p4config` |
179
+ | `LOG_LEVEL` | Logging level | `warn` |
180
+
181
+ ## Error Handling
182
+
183
+ Standardized error codes for reliable error handling:
184
+ - `P4_NOT_FOUND` - Perforce executable not found
185
+ - `P4_AUTH_FAILED` - Authentication failure
186
+ - `P4_CLIENT_UNKNOWN` - Unknown workspace
187
+ - `P4_CONNECTION_FAILED` - Server connection failed
188
+ - `P4_READONLY_MODE` - Operation blocked by read-only mode
189
+ - `P4_DELETE_DISABLED` - Delete operation blocked
190
+
191
+ ## Development
192
+
193
+ ```bash
194
+ # Local development
195
+ git clone https://github.com/iPraBhu/mcp-perforce-server.git
196
+ cd mcp-perforce-server
197
+ npm install
198
+ npm run build
199
+
200
+ # Run tests
201
+ npm test
202
+
203
+ # Development mode
204
+ npm run watch
205
+ ```
206
+
207
+ ## Contributing
208
+
209
+ This project was created with ❤️ by [Pratik Bhuite](https://github.com/iPraBhu) to solve real Perforce automation challenges.
210
+
211
+ **Ways to contribute:**
212
+ - 🐛 **Report bugs** - Open an issue if something's not working
213
+ - 💡 **Suggest features** - Have an idea? Let's discuss it!
214
+ - 🔧 **Submit PRs** - Code contributions are welcome
215
+ - 📖 **Improve docs** - Help make the documentation better
216
+ - ⭐ **Star the repo** - Show your support!
217
+
218
+ **Found this useful?** Consider giving it a star ⭐ and sharing with others who might benefit!
219
+
220
+ ## License
221
+
222
+ MIT License - Feel free to use, modify, and distribute as needed. See [LICENSE](LICENSE) for details.
223
+
224
+ **TL;DR:** Use it however you want, just keep the license notice. Built for the community! 🚀
@@ -0,0 +1,67 @@
1
+ export interface P4ConfigResult {
2
+ found: boolean;
3
+ configPath?: string;
4
+ projectRoot?: string;
5
+ config: Record<string, string>;
6
+ environment: Record<string, string>;
7
+ }
8
+ export interface P4ServerConfig {
9
+ readOnlyMode: boolean;
10
+ disableDelete: boolean;
11
+ }
12
+ export declare class P4Config {
13
+ private static readonly DEFAULT_CONFIG_NAME;
14
+ /**
15
+ * Find .p4config file by searching upward from the given directory
16
+ */
17
+ findConfig(startPath?: string): Promise<P4ConfigResult>;
18
+ /**
19
+ * Search upward through parent directories for config file
20
+ */
21
+ private searchUpward;
22
+ /**
23
+ * Parse .p4config file content
24
+ */
25
+ private parseConfigFile;
26
+ /**
27
+ * Build environment variables from config
28
+ */
29
+ private buildEnvironment;
30
+ /**
31
+ * Get project root directory from workspace path
32
+ */
33
+ getProjectRoot(workspacePath?: string): Promise<string>;
34
+ /**
35
+ * Setup environment and working directory for p4 command
36
+ */
37
+ setupForCommand(workspacePath?: string): Promise<{
38
+ cwd: string;
39
+ env: Record<string, string>;
40
+ configResult: P4ConfigResult;
41
+ }>;
42
+ /**
43
+ * Validate that Perforce environment is properly configured
44
+ */
45
+ validateEnvironment(configResult: P4ConfigResult): {
46
+ valid: boolean;
47
+ errors: string[];
48
+ };
49
+ /**
50
+ * Get server configuration from environment variables
51
+ */
52
+ getServerConfig(): P4ServerConfig;
53
+ /**
54
+ * Extract MCP-provided Perforce environment variables
55
+ */
56
+ private getMcpEnvironment;
57
+ /**
58
+ * Create a minimal .p4config file template
59
+ */
60
+ static createTemplate(options?: {
61
+ port?: string;
62
+ user?: string;
63
+ client?: string;
64
+ charset?: string;
65
+ }): string;
66
+ }
67
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/p4/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAe;IAE1D;;OAEG;IACG,UAAU,CAAC,SAAS,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;IAiC5E;;OAEG;YACW,YAAY;IAgC1B;;OAEG;YACW,eAAe;IA4B7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;OAEG;IACG,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAW7D;;OAEG;IACG,eAAe,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QACrD,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5B,YAAY,EAAE,cAAc,CAAC;KAC9B,CAAC;IAgBF;;OAEG;IACH,mBAAmB,CAAC,YAAY,EAAE,cAAc,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IA4BvF;;OAEG;IACH,eAAe,IAAI,cAAc;IAOjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,GAAE;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;KACb,GAAG,MAAM;CAyBhB"}