OJ API

Reference

MCP Reference

Use the mounted MCP transport when you want tool-based access to the same public problem, daily, similarity, and status capabilities.

The mounted MCP transport is currently reachable without bearer auth.
01

Transport

Document the two HTTP surfaces exposed by the mounted Streamable HTTP MCP service.

01Agent client
02Streamable HTTP
03OJ API tools
POST /mcp

Streamable HTTP entrypoint

Primary Streamable HTTP endpoint for initialize and tool-call requests.

#
Expand details
Auth
Bearer auth follows the existing MCP middleware setting.
curl -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' http://127.0.0.1:7856/mcp
GET /mcp

SSE session stream

SSE/session-resume transport surface exposed by the mounted MCP service.

#
Expand details
Auth
Bearer auth follows the existing MCP middleware setting.
curl -N -H 'Authorization: Bearer <token>' http://127.0.0.1:7856/mcp
02

Tools

Each MCP tool maps back to an existing public REST capability while returning plain-language output for tool clients.

TOOL resolve_problem

Resolve a problem from flexible input

Inputs: query

#
Expand details

REST capability

Maps to GET /api/v1/resolve/{*query}.

Output style

Text summary of the resolved problem detail.

Usage note

Use when the source/ID format is uncertain or when the input is a URL.

TOOL get_problem

Fetch one normalized problem

Inputs: source, id

#
Expand details

REST capability

Maps to GET /api/v1/problems/{source}/{id}.

Output style

Text summary of the requested problem detail.

Usage note

Use when the caller already knows the normalized source and problem ID.

TOOL get_daily_challenge

Read the current daily challenge

Inputs: domain?, date?

#
Expand details

REST capability

Maps to GET /api/v1/daily.

Output style

Text summary of the daily challenge or the active fetch state.

Usage note

Use when the caller wants the current daily challenge without composing REST query strings.

TOOL find_similar_problems

Search similar problems

Inputs: query or source+id, plus limit/threshold/source_filter?

#
Expand details

REST capability

Maps to POST /api/v1/similar and GET /api/v1/similar/{source}/{id}.

Output style

Text ranking of similar problems with similarity scores.

Usage note

Use text query mode for semantic search or source+id mode for seed-problem lookup.

TOOL get_platform_status

Check indexed platform status

Inputs: none

#
Expand details

REST capability

Maps to GET /status.

Output style

Text summary of service version and platform stats.

Usage note

Use for a compact operational overview of available indexed platforms.

03

Examples

Start with one connection snippet and one JSON-RPC request to verify auth, transport, and tool naming.

CONFIG

Connection example

mcpServers.oj-api

Point your MCP client at the mounted HTTP endpoint and send the same bearer token you use for protected public routes.

{
  "mcpServers": {
    "oj-api": {
      "transport": {
        "type": "streamable-http",
        "url": "http://127.0.0.1:7856/mcp",
        "headers": {
          "Authorization": "Bearer <token>"
        }
      }
    }
  }
}
JSON-RPC

Request example

tools/call

This request asks the MCP server to run the exact tool name get_problem with the same source and ID you would send to the REST detail endpoint.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_problem",
    "arguments": {
      "source": "leetcode",
      "id": "1"
    }
  }
}