AgentSkillsCN

Mcp Tool Manager

Mcp 工具管理员

SKILL.md

Skill: mcp-tool-manager

Purpose

Seamlessly switch between live and mocked external dependencies using the Model Context Protocol (MCP). This skill enables autonomous development even when external services are unavailable, rate-limited, or require authentication.

When to Use

  • When the project integrates with external APIs (Stripe, AWS, Twilio, etc.).
  • During local development and testing (use mocks).
  • During integration testing and production deployments (use live tools).

How It Works

Step 1: Configure MCP Tools in CLAUDE.md

Define both live and mock tool configurations:

markdown
## MCP Tool Configuration

### Live Tools (for production/integration)
- **Stripe**: `mcp://stripe-live`
- **AWS S3**: `mcp://aws-s3-live`
- **SendGrid**: `mcp://sendgrid-live`

### Mock Tools (for development/testing)
- **Stripe**: `mcp://stripe-mock`
- **AWS S3**: `mcp://aws-s3-mock`
- **SendGrid**: `mcp://sendgrid-mock`

### Active Mode
- **Default**: `mock`
- **Override**: Set `RALPH_MCP_MODE=live` environment variable.

Step 2: Implement Mock Tools

For each external API, create a mock MCP tool that simulates the API's behavior:

Example: Stripe Mock (mcp://stripe-mock)

json
{
  "name": "stripe-mock",
  "description": "A mock Stripe API for testing.",
  "tools": [
    {
      "name": "create_payment_intent",
      "description": "Creates a mock payment intent.",
      "input_schema": {
        "type": "object",
        "properties": {
          "amount": { "type": "integer" },
          "currency": { "type": "string" }
        }
      },
      "output": {
        "id": "pi_mock_123",
        "status": "succeeded",
        "amount": "{{amount}}",
        "currency": "{{currency}}"
      }
    }
  ]
}

Step 3: Dynamic Tool Selection in ralph.sh

Modify ralph.sh to select the correct tool set based on the environment:

bash
# In ralph.sh
MCP_MODE="${RALPH_MCP_MODE:-mock}"

if [[ "$MCP_MODE" == "live" ]]; then
  echo "Using LIVE MCP tools. Ensure credentials are configured."
  export MCP_CONFIG=".ralph/mcp_live.json"
else
  echo "Using MOCK MCP tools."
  export MCP_CONFIG=".ralph/mcp_mock.json"
fi

Step 4: Auto-Generate Mocks from OpenAPI Specs

If a mock tool does not exist, the agent can attempt to generate one:

bash
claude --print "You are an API Mock Generator. Your task is to create a mock MCP tool based on the following OpenAPI specification.

**OpenAPI Spec:**
$(cat openapi/stripe.yaml)

**Output:**
A JSON file defining the mock MCP tool with realistic sample responses for each endpoint.
"

Configuration

Add the following to your CLAUDE.md:

markdown
## MCP Tool Manager

- **Default Mode**: mock
- **Live Config**: `.ralph/mcp_live.json`
- **Mock Config**: `.ralph/mcp_mock.json`
- **Auto-Generate Mocks**: Enabled