Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Latest commit

 

History

History
176 lines (147 loc) · 4.03 KB

File metadata and controls

176 lines (147 loc) · 4.03 KB

Testing the MCP Plugin Locally

Since we're having build issues with the full plugin integration (due to Spin dependencies), here's how the plugin will work once properly built:

1. Plugin Installation (Future)

# Build the plugin
cargo build --release

# Package it
spin pluginify

# Install locally
spin pluginify --install

2. Example MCP Server Structure

The example weather tool demonstrates a complete MCP implementation:

Component Structure:

examples/mcp-weather-tool/
├── Cargo.toml          # Rust dependencies
├── spin.toml           # Spin application manifest  
├── src/
│   └── lib.rs          # MCP implementation
└── wit/
    ├── spin-mcp.wit    # MCP protocol definition
    └── world.wit       # Component world

Key Implementation Points:

  1. WIT Interface (spin-mcp.wit):

    • Defines full MCP protocol with tools, resources, and prompts
    • Uses proper JSON-RPC structure
    • Type-safe request/response handling
  2. Component Implementation (src/lib.rs):

    • Implements handle_request for MCP methods
    • Provides two example tools: get_weather and get_forecast
    • Shows proper error handling
    • Includes prompt templates
  3. Spin Configuration (spin.toml):

    [[trigger.mcp]]
    component = "weather-service"
    route = "/weather"

3. Testing the Server (Once Built)

# Start the MCP server
spin up

# List available tools
curl -X POST http://localhost:3000/weather \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "tools/list",
    "id": 1
  }'

# Expected response:
{
  "jsonrpc": "2.0",
  "result": {
    "tools": [
      {
        "name": "get_weather",
        "description": "Get current weather information for a location",
        "inputSchema": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city or location to get weather for"
            },
            "units": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"],
              "description": "Temperature units (default: fahrenheit)",
              "default": "fahrenheit"
            }
          },
          "required": ["location"]
        }
      },
      {
        "name": "get_forecast",
        "description": "Get weather forecast for the next 5 days",
        "inputSchema": { ... }
      }
    ]
  },
  "id": 1
}

# Call a tool
curl -X POST http://localhost:3000/weather \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "tools/call",
    "params": {
      "name": "get_weather",
      "arguments": {
        "location": "San Francisco",
        "units": "celsius"
      }
    },
    "id": 2
  }'

# Expected response:
{
  "jsonrpc": "2.0",
  "result": {
    "content": {
      "location": "San Francisco",
      "temperature": 22,
      "unit": "C",
      "conditions": "Partly cloudy",
      "humidity": 65,
      "wind_speed": 12,
      "wind_direction": "NW"
    }
  },
  "id": 2
}

4. Claude Desktop Integration

Once the server is running, configure Claude Desktop:

{
  "mcpServers": {
    "weather": {
      "command": "spin",
      "args": ["up", "--from", "/path/to/mcp-weather-tool/spin.toml"]
    }
  }
}

Current Status

The plugin structure is complete with:

  • ✅ Full MCP protocol implementation in WIT
  • ✅ Complete trigger implementation supporting all MCP methods
  • ✅ Example weather tool showing best practices
  • ✅ Documentation and templates
  • ⏳ Build issues due to local Spin workspace dependencies

Next Steps for Production

  1. Standalone Build: When you push to GitHub, update Cargo.toml to use published Spin crates:

    spin-app = "3.0"
    spin-core = "3.0"
    # etc...
  2. GitHub Actions: Set up CI/CD to build and release the plugin

  3. Plugin Registry: Submit to the Spin plugin registry for easy installation

The plugin architecture is solid and ready for deployment once built independently!