Skip to main content
POST
/
messages
/
Deploy API: MCP Server
curl --request POST \
  --url http://127.0.0.1:8765/messages/ \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '
{
  "jsonrpc": "<string>",
  "method": "<string>",
  "params": {},
  "id": 123,
  "params.name": "<string>",
  "params.arguments": {},
  "params.protocolVersion": "<string>",
  "params.capabilities": {},
  "params.clientInfo": {}
}
'
import requests

url = "http://127.0.0.1:8765/messages/"

payload = {
    "jsonrpc": "<string>",
    "method": "<string>",
    "params": {},
    "id": 123,
    "params.name": "<string>",
    "params.arguments": {},
    "params.protocolVersion": "<string>",
    "params.capabilities": {},
    "params.clientInfo": {}
}
headers = {
    "X-API-Key": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '<string>',
    method: '<string>',
    params: {},
    id: 123,
    'params.name': '<string>',
    'params.arguments': {},
    'params.protocolVersion': '<string>',
    'params.capabilities': {},
    'params.clientInfo': {}
  })
};

fetch('http://127.0.0.1:8765/messages/', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_PORT => "8765",
  CURLOPT_URL => "http://127.0.0.1:8765/messages/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'jsonrpc' => '<string>',
    'method' => '<string>',
    'params' => [
        
    ],
    'id' => 123,
    'params.name' => '<string>',
    'params.arguments' => [
        
    ],
    'params.protocolVersion' => '<string>',
    'params.capabilities' => [
        
    ],
    'params.clientInfo' => [
        
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "X-API-Key: <api-key>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:8765/messages/"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"<string>\",\n  \"method\": \"<string>\",\n  \"params\": {},\n  \"id\": 123,\n  \"params.name\": \"<string>\",\n  \"params.arguments\": {},\n  \"params.protocolVersion\": \"<string>\",\n  \"params.capabilities\": {},\n  \"params.clientInfo\": {}\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-API-Key", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("http://127.0.0.1:8765/messages/")
  .header("X-API-Key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"<string>\",\n  \"method\": \"<string>\",\n  \"params\": {},\n  \"id\": 123,\n  \"params.name\": \"<string>\",\n  \"params.arguments\": {},\n  \"params.protocolVersion\": \"<string>\",\n  \"params.capabilities\": {},\n  \"params.clientInfo\": {}\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:8765/messages/")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"jsonrpc\": \"<string>\",\n  \"method\": \"<string>\",\n  \"params\": {},\n  \"id\": 123,\n  \"params.name\": \"<string>\",\n  \"params.arguments\": {},\n  \"params.protocolVersion\": \"<string>\",\n  \"params.capabilities\": {},\n  \"params.clientInfo\": {}\n}"

response = http.request(request)
puts response.read_body

MCP API

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

Base URL + Playground

# Start MCP server
agent.launch(protocol="mcp", port=8080)
Base URL: http://localhost:8080

Endpoints

GET /sse

Server-Sent Events endpoint for MCP communication.
none
none
No parameters required.
curl -N http://localhost:8080/sse
import requests

response = requests.get("http://localhost:8080/sse", stream=True)
for line in response.iter_lines():
    if line:
        print(line.decode())
Response: SSE stream with MCP protocol messages.

POST /messages/

Send JSON-RPC messages to the MCP server.
jsonrpc
string
required
JSON-RPC version (must be “2.0”)
method
string
required
MCP method name (tools/list, tools/call, initialize)
params
object
Method parameters
id
integer
required
Request ID
curl -X POST http://localhost:8080/messages/ \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
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]}")
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));
Response:
{
  "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.
curl -X POST http://localhost:8080/messages/ \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
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']}")
Response:
{
  "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.
params.name
string
required
Tool name to execute
params.arguments
object
required
Tool arguments
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
  }'
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"])
Response:
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Results for: AI news"
      }
    ]
  }
}

initialize

Initialize MCP session.
params.protocolVersion
string
required
MCP protocol version
params.capabilities
object
Client capabilities
params.clientInfo
object
Client information (name, version)
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
  }'
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']}")
Response:
{
  "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:
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}
CodeMessage
-32700Parse error
-32600Invalid request
-32601Method not found
-32602Invalid params
-32603Internal error