MCP Perforce Server

MCP Perforce Server

Provides a clean interface for Perforce (P4) operations in Claude Desktop, wrapping P4 commands for reliable, non-interactive use with structured responses and multi-project support.

Category
访问服务器

README

MCP Perforce Server

A Model Context Protocol (MCP) server that provides a clean interface for Perforce (P4) operations in Claude Desktop. This server wraps P4 commands to make them more reliable and easier for Claude to use, eliminating issues with interactive prompts and complex state management.

Features

  • Non-interactive operations: All commands are wrapped to avoid interactive prompts
  • Structured responses: Clean, parseable output instead of raw P4 output
  • Multi-project support: Automatically uses .p4config files for per-project settings
  • Common operations: Add, edit, delete, submit, revert, sync, and more
  • Changelist management: Create and submit changelists with explicit parameters
  • Error handling: Graceful error handling with clear error messages

Installation

Prerequisites

  • Node.js 18+ installed
  • Perforce command-line client (p4) installed and in your PATH
  • .p4config files in your project directories (recommended)

Quick Install with Claude Code

# Install the package globally
npm install -g @cocoon-ai/mcp-perforce

# Add to Claude Code
claude mcp add perforce @cocoon-ai/mcp-perforce

That's it! Claude Code will automatically configure the server for you.

Manual Installation

Via NPM (when published)

npm install -g @cocoon-ai/mcp-perforce

Install from Source

git clone https://github.com/Cocoon-AI/mcp-perforce.git
cd mcp-perforce
npm install
npm run build
npm link  # Makes 'mcp-perforce' available globally

Configuration

Basic Setup

Add the server to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "perforce": {
      "command": "npx",
      "args": ["-y", "@cocoon-ai/mcp-perforce"],
      "env": {
        "P4CONFIG": ".p4config"
      }
    }
  }
}

Setting Up .p4config Files

The server uses Perforce's built-in P4CONFIG mechanism to automatically switch between different Perforce servers based on your current directory. Create a .p4config file in each project root:

# ~/projects/gamedev/.p4config
P4PORT=perforce-game.company.com:1666
P4CLIENT=gamedev-workspace
P4USER=your-username

# ~/projects/web/.p4config
P4PORT=perforce-web.company.com:1666
P4CLIENT=web-workspace
P4USER=your-username

Now the MCP server will automatically use the correct Perforce settings based on which project directory you're working in!

Available Commands

Once configured, you can ask Claude to use these P4 operations. All commands will automatically use the .p4config settings from your current project directory.

Basic File Operations

  • p4_status: Check workspace status and pending changes

    "Show me my pending P4 changes"
    "Check P4 status in the gamedev directory"
    
  • p4_add: Add files to Perforce

    "Add all .js files in the src directory to Perforce"
    
  • p4_edit: Open files for edit

    "Open config.json for editing in Perforce"
    
  • p4_delete: Mark files for deletion

    "Delete the old_module.py file from Perforce"
    
  • p4_sync: Sync files from depot

    "Sync all files in the project"
    "Force sync the src directory"
    
  • p4_revert: Revert files or entire changelists

    "Revert all files in changelist 12345"
    "Revert changes to config.json"
    
  • p4_diff: Show differences for files

    "Show me the diff for all my open files"
    

Changelist Operations

  • p4_changelist_create: Create a new changelist

    "Create a new changelist with description 'Fix login bug'"
    
  • p4_changelist_submit: Submit a changelist

    "Submit changelist 12345"
    
  • p4_move_to_changelist: Move files between changelists

    "Move all my open files to changelist 12345"
    

Stream Operations

  • p4_stream_list: List streams in a depot

    "List all streams in //depot"
    "Show me development streams matching 'feature'"
    
  • p4_stream_info: Get detailed stream information

    "Show me details about //depot/main stream"
    
  • p4_stream_switch: Switch workspace to a different stream

    "Switch to the //depot/dev stream"
    "Force switch to //depot/release-2.0"
    
  • p4_stream_create: Create a new stream

    "Create a development stream //depot/feature-xyz from //depot/main"
    
  • p4_stream_edit: Edit stream specification

    "Edit the //depot/feature-xyz stream spec"
    
  • p4_stream_graph: Show stream hierarchy

    "Show the stream hierarchy for //depot"
    

Client/Workspace Operations

  • p4_client_list: List all clients/workspaces

    "List all my Perforce workspaces"
    "Show clients for user jsmith"
    
  • p4_client_info: Get client/workspace details

    "Show me details about my current workspace"
    "Show info for client gamedev-workspace"
    
  • p4_client_create: Create a new client/workspace

    "Create a new workspace called dev-feature in /home/user/p4/feature"
    "Create a stream client for //depot/main-stream"
    
  • p4_client_edit: Edit client specification

    "Edit the view mappings for client dev-workspace"
    
  • p4_client_delete: Delete a client/workspace

    "Delete the old-feature workspace"
    "Force delete the broken-client workspace"
    
  • p4_client_switch: Switch to a different client

    "Switch to the production-client workspace"
    

Information Operations

  • p4_info: Show current Perforce configuration

    "Show me which P4 server and workspace I'm using"
    
  • mcp_perforce_version: Show MCP Perforce server version

    "What version of mcp-perforce is running?"
    

Example Usage in Claude

Here are some example conversations with Claude:

Example 1: Creating and submitting a change

You: "I've modified server.js and config.json. Create a changelist for these fixes"
Claude: I'll help you create a changelist for your changes. Let me first check the status...
[Uses p4_status, p4_changelist_create, p4_submit]

Example 2: Syncing and reviewing changes

You: "Sync the latest changes and show me what files I have open"
Claude: I'll sync your workspace and check your open files...
[Uses p4_sync, p4_status]

Troubleshooting

Server not appearing in Claude

  1. Restart Claude Desktop after modifying the configuration
  2. Check that the configuration file is valid JSON
  3. Verify the MCP server is installed: npm list -g @cocoon-ai/mcp-perforce

Perforce authentication errors

  1. Check your .p4config file exists and has the correct settings
  2. Test your connection outside Claude: p4 info
  3. Make sure you're logged in: p4 login
  4. Verify P4CONFIG is being recognized: p4 set P4CONFIG

Wrong Perforce server being used

  1. Check which directory you're in - the server uses .p4config from the current or parent directories
  2. Run p4 info to see which config is being used
  3. Use the p4_info command in Claude to debug: "Show me my P4 configuration"

Command not working as expected

  1. Check Claude's response for error messages
  2. Verify the P4 command works in your terminal from the same directory
  3. Enable debug logging (see below)

Debug Logging

To enable debug output, add to your configuration:

{
  "mcpServers": {
    "perforce": {
      "command": "npx",
      "args": ["-y", "@cocoon-ai/mcp-perforce"],
      "env": {
        "P4CONFIG": ".p4config",
        "DEBUG": "mcp:*"
      }
    }
  }
}

Development

Building from source

git clone https://github.com/Cocoon-AI/mcp-perforce.git
cd mcp-perforce
npm install
npm run build

Running tests

npm test

Adding new commands

  1. Add the tool definition in the appropriate file under src/tools/
  2. Add the handler function in the corresponding file under src/handlers/
  3. Update the switch statement in src/handlers/index.ts
  4. Follow the existing pattern for parameter validation and error handling

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-command)
  3. Commit your changes (git commit -am 'Add new P4 command')
  4. Push to the branch (git push origin feature/new-command)
  5. Create a Pull Request

License

MIT License - see LICENSE file for details

Acknowledgments

Support


Made with ❤️ for AIs struggling with P4 command-line operations

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选