> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy API: MCP Server

> MCP protocol endpoints for agent and tools servers

# MCP API

MCP (Model Context Protocol) endpoints for agents deployed via `Agent.launch(protocol="mcp")` or `ToolsMCPServer`.

## Base URL + Playground

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Start MCP server
agent.launch(protocol="mcp", port=8080)
```

**Base URL:** `http://localhost:8080`

## Endpoints

### GET /sse

Server-Sent Events endpoint for MCP communication.

<ParamField query="none" type="none">
  No parameters required.
</ParamField>

<CodeGroup>
  ```bash curl theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl -N http://localhost:8080/sse
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import requests

  response = requests.get("http://localhost:8080/sse", stream=True)
  for line in response.iter_lines():
      if line:
          print(line.decode())
  ```
</CodeGroup>

**Response:** SSE stream with MCP protocol messages.

### POST /messages/

Send JSON-RPC messages to the MCP server.

<ParamField body="jsonrpc" type="string" required>
  JSON-RPC version (must be "2.0")
</ParamField>

<ParamField body="method" type="string" required>
  MCP method name (tools/list, tools/call, initialize)
</ParamField>

<ParamField body="params" type="object">
  Method parameters
</ParamField>

<ParamField body="id" type="integer" required>
  Request ID
</ParamField>

<CodeGroup>
  ```bash curl theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl -X POST http://localhost:8080/messages/ \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import requests

  response = requests.post(
      "http://localhost:8080/messages/",
      json={"jsonrpc": "2.0", "method": "tools/list", "id": 1}
  )
  tools = response.json()["result"]["tools"]
  print(f"Available tools: {[t['name'] for t in tools]}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  const response = await fetch("http://localhost:8080/messages/", {
    method: "POST",
    headers: {"Content-Type": "application/json"},
    body: JSON.stringify({jsonrpc: "2.0", method: "tools/list", id: 1})
  });
  const { result } = await response.json();
  console.log("Tools:", result.tools.map(t => t.name));
  ```
</CodeGroup>

**Response:**

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "execute_assistant_task",
        "description": "Executes the agent's primary task with the given prompt.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "prompt": {"type": "string"}
          },
          "required": ["prompt"]
        }
      }
    ]
  }
}
```

## MCP Methods

### tools/list

List available tools.

<CodeGroup>
  ```bash curl theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl -X POST http://localhost:8080/messages/ \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import requests

  response = requests.post(
      "http://localhost:8080/messages/",
      json={"jsonrpc": "2.0", "method": "tools/list", "id": 1}
  )
  tools = response.json()["result"]["tools"]
  for tool in tools:
      print(f"- {tool['name']}: {tool['description']}")
  ```
</CodeGroup>

**Response:**

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "search",
        "description": "Search the web for information.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "query": {"type": "string"}
          },
          "required": ["query"]
        }
      }
    ]
  }
}
```

### tools/call

Execute a tool.

<ParamField body="params.name" type="string" required>
  Tool name to execute
</ParamField>

<ParamField body="params.arguments" type="object" required>
  Tool arguments
</ParamField>

<CodeGroup>
  ```bash curl theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl -X POST http://localhost:8080/messages/ \
    -H "Content-Type: application/json" \
    -d '{
      "jsonrpc": "2.0",
      "method": "tools/call",
      "params": {
        "name": "search",
        "arguments": {"query": "AI news"}
      },
      "id": 2
    }'
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import requests

  response = requests.post(
      "http://localhost:8080/messages/",
      json={
          "jsonrpc": "2.0",
          "method": "tools/call",
          "params": {"name": "search", "arguments": {"query": "AI news"}},
          "id": 2
      }
  )
  result = response.json()["result"]
  print(result["content"][0]["text"])
  ```
</CodeGroup>

**Response:**

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Results for: AI news"
      }
    ]
  }
}
```

### initialize

Initialize MCP session.

<ParamField body="params.protocolVersion" type="string" required>
  MCP protocol version
</ParamField>

<ParamField body="params.capabilities" type="object">
  Client capabilities
</ParamField>

<ParamField body="params.clientInfo" type="object">
  Client information (name, version)
</ParamField>

<CodeGroup>
  ```bash curl theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl -X POST http://localhost:8080/messages/ \
    -H "Content-Type: application/json" \
    -d '{
      "jsonrpc": "2.0",
      "method": "initialize",
      "params": {
        "protocolVersion": "2024-11-05",
        "capabilities": {},
        "clientInfo": {"name": "test-client", "version": "1.0.0"}
      },
      "id": 0
    }'
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import requests

  response = requests.post(
      "http://localhost:8080/messages/",
      json={
          "jsonrpc": "2.0",
          "method": "initialize",
          "params": {
              "protocolVersion": "2024-11-05",
              "capabilities": {},
              "clientInfo": {"name": "my-client", "version": "1.0.0"}
          },
          "id": 0
      }
  )
  server_info = response.json()["result"]["serverInfo"]
  print(f"Connected to: {server_info['name']}")
  ```
</CodeGroup>

**Response:**

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "jsonrpc": "2.0",
  "id": 0,
  "result": {
    "protocolVersion": "2024-11-05",
    "capabilities": {"tools": {}},
    "serverInfo": {"name": "praisonai-tools", "version": "1.0.0"}
  }
}
```

## Errors

MCP errors follow JSON-RPC 2.0 format:

```json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}
```

| Code     | Message          |
| -------- | ---------------- |
| `-32700` | Parse error      |
| `-32600` | Invalid request  |
| `-32601` | Method not found |
| `-32602` | Invalid params   |
| `-32603` | Internal error   |

## Related

* [MCP Server](../mcp-server) - Deploy agents as MCP server
* [Tools Server](../tools-server) - Deploy tools as MCP server
* [Agents API](./agents-api) - HTTP REST endpoints
