API Reference

Complete API documentation for MCP-RS.

Core Types

JSON-RPC Messages

All MCP-RS communication follows the JSON-RPC 2.0 specification.

Request Format

{
  "jsonrpc": "2.0",
  "method": "method_name",
  "params": { /* method parameters */ },
  "id": 1
}

Response Format

{
  "jsonrpc": "2.0",
  "result": { /* response data */ },
  "id": 1
}

Error Format

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "Error description",
    "data": { /* additional error info */ }
  },
  "id": 1
}

MCP Protocol Methods

Initialization

initialize

Establishes connection and negotiates capabilities.

Request:

{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "roots": {
        "listChanged": true
      },
      "sampling": {}
    },
    "clientInfo": {
      "name": "client-name",
      "version": "1.0.0"
    }
  },
  "id": 1
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "logging": {},
      "tools": {
        "listChanged": true
      },
      "resources": {
        "subscribe": true,
        "listChanged": true
      },
      "prompts": {
        "listChanged": true
      }
    },
    "serverInfo": {
      "name": "mcp-rs",
      "version": "0.1.0"
    }
  },
  "id": 1
}

Tools

tools/list

Lists available tools.

Request:

{
  "jsonrpc": "2.0",
  "method": "tools/list",
  "id": 2
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "tools": [
      {
        "name": "get_posts",
        "description": "Retrieve WordPress posts",
        "inputSchema": {
          "type": "object",
          "properties": {},
          "required": []
        }
      }
    ]
  },
  "id": 2
}

tools/call

Executes a tool.

Request:

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "create_post",
    "arguments": {
      "title": "My New Post",
      "content": "This is the post content."
    }
  },
  "id": 3
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Created post with ID: 123"
      }
    ],
    "isError": false
  },
  "id": 3
}

Resources

resources/list

Lists available resources.

Request:

{
  "jsonrpc": "2.0",
  "method": "resources/list",
  "id": 4
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "resources": [
      {
        "uri": "wordpress://posts",
        "name": "WordPress Posts",
        "description": "All published WordPress posts",
        "mimeType": "application/json"
      },
      {
        "uri": "wordpress://pages",
        "name": "WordPress Pages",
        "description": "All published WordPress pages",
        "mimeType": "application/json"
      }
    ]
  },
  "id": 4
}

resources/read

Reads a resource.

Request:

{
  "jsonrpc": "2.0",
  "method": "resources/read",
  "params": {
    "uri": "wordpress://posts"
  },
  "id": 5
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "contents": [
      {
        "uri": "wordpress://posts",
        "mimeType": "application/json",
        "text": "[{\"id\":1,\"title\":\"Sample Post\",\"content\":\"...\"}]"
      }
    ]
  },
  "id": 5
}

Prompts

prompts/list

Lists available prompts.

Request:

{
  "jsonrpc": "2.0",
  "method": "prompts/list",
  "id": 6
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "prompts": [
      {
        "name": "wordpress_content_analysis",
        "description": "Analyze WordPress content for SEO and readability",
        "arguments": [
          {
            "name": "post_id",
            "description": "WordPress post ID to analyze",
            "required": true
          }
        ]
      }
    ]
  },
  "id": 6
}

prompts/get

Retrieves a prompt.

Request:

{
  "jsonrpc": "2.0",
  "method": "prompts/get",
  "params": {
    "name": "wordpress_content_analysis",
    "arguments": {
      "post_id": "123"
    }
  },
  "id": 7
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "description": "WordPress content analysis prompt",
    "messages": [
      {
        "role": "user",
        "content": {
          "type": "text",
          "text": "Please analyze the following WordPress post for SEO optimization and readability improvements..."
        }
      }
    ]
  },
  "id": 7
}

Error Codes

MCP-RS uses standard JSON-RPC error codes plus custom MCP-specific codes:

Code Message Description
-32700 Parse error Invalid JSON
-32600 Invalid Request Invalid JSON-RPC request
-32601 Method not found Method doesn’t exist
-32602 Invalid params Invalid method parameters
-32603 Internal error Internal JSON-RPC error
-32000 Server error Generic server error
-32001 Invalid tool Tool not found or invalid
-32002 Tool execution failed Tool execution error
-32003 Resource not found Resource URI not found
-32004 Resource read failed Resource read error
-32005 Configuration error Configuration validation error

WordPress Handler API

Available Tools

get_posts

Retrieves WordPress posts.

Parameters: None (current implementation)

create_post

Creates a new WordPress post.

Parameters:

  • title (string, required): Post title
  • content (string, required): Post content (HTML)

get_comments

Retrieves WordPress comments.

Parameters:

  • post_id (number, optional): Post ID to filter comments

Resources

  • wordpress://posts - All published posts
  • wordpress://pages - All published pages
  • wordpress://media - Media library items
  • wordpress://categories - Post categories
  • wordpress://tags - Post tags
  • wordpress://users - Site users

For implementation examples, see the Guides section.