From f9f30f7c1a985f4b3cd8acc05db82d3736bbd762 Mon Sep 17 00:00:00 2001 From: arka-ops Date: Tue, 13 Oct 2026 18:04:51 +0300 Subject: [PATCH] =?UTF-8?q?feat(mcp):=20arka-search-mcp=20=E2=80=94=20MCP?= =?UTF-8?q?=20stdio=20server=20for=20Arka=20web=20search/fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zero-dependency Node MCP server exposing web_search/web_fetch backed by https://search.arka-ai.ru (X-Api-Key from ARKA_API_KEY). For opencode, Hermes, DeepSeek Harness and any MCP client. Agent Arka uses http_compat directly. --- mcp/arka-search-mcp/README.md | 56 +++++++++++ mcp/arka-search-mcp/package.json | 13 +++ mcp/arka-search-mcp/server.js | 161 +++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 mcp/arka-search-mcp/README.md create mode 100644 mcp/arka-search-mcp/package.json create mode 100644 mcp/arka-search-mcp/server.js diff --git a/mcp/arka-search-mcp/README.md b/mcp/arka-search-mcp/README.md new file mode 100644 index 0000000..92080cb --- /dev/null +++ b/mcp/arka-search-mcp/README.md @@ -0,0 +1,56 @@ +# arka-search-mcp + +A tiny **MCP stdio server** that exposes Arka web **search** and **fetch** to any +MCP-capable agent harness (opencode, Hermes, DeepSeek Harness, Claude Code, …). + +Backend: `https://search.arka-ai.ru` (Arka ops) — self-hosted SearXNG behind an +authenticated gateway that resolves `ARKA_API_KEY → billing account`, applies +per-account rate limits, and runs an SSRF-guarded reader. + +Agent Arka itself does **not** need this shim — it talks to the gateway directly +via the built-in `http_compat` MCP transport. See the setup doc. + +## Requirements + +- Node.js ≥ 18 (uses global `fetch`). +- An Arka API key in `ARKA_API_KEY` (the key Agent Arka stores for inference; + obtained via SSO / trial provisioning). + +## Environment + +| Variable | Default | Meaning | +|---|---|---| +| `ARKA_API_KEY` | — (**required**) | Arka API key; sent as `X-Api-Key`. | +| `ARKA_SEARCH_URL` | `https://search.arka-ai.ru` | Gateway base URL. | +| `ARKA_SEARCH_UA` | `arka-search-mcp/1.0` | User-Agent. | + +## Tools + +| Tool | Arguments | Returns | +|---|---|---| +| `web_search` | `q` (required), `language`, `categories`, `pageno`, `time_range` | SearXNG JSON `{ query, results: [{ title, url, content, engine }] }` | +| `web_fetch` | `url` (required) | `{ title, content (Markdown), url, final_url, content_type, bytes, truncated }` | + +## Install + +```bash +git clone https://git.arka-ai.ru/arka/public.git +# or copy just this directory +# server: /path/to/arka-search-mcp/server.js +``` + +Zero dependencies — run it directly with `node server.js`. + +## Manual smoke test + +```bash +printf '%s\n' \ + '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}' \ + '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \ + '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"web_search","arguments":{"q":"Arka AI"}}}' \ + | ARKA_API_KEY="$ARKA_API_KEY" node server.js +``` + +## License + +MIT. diff --git a/mcp/arka-search-mcp/package.json b/mcp/arka-search-mcp/package.json new file mode 100644 index 0000000..270167a --- /dev/null +++ b/mcp/arka-search-mcp/package.json @@ -0,0 +1,13 @@ +{ + "name": "arka-search-mcp", + "version": "1.0.0", + "private": true, + "description": "MCP stdio server exposing Arka web search + fetch (https://search.arka-ai.ru) to any MCP-capable agent harness.", + "license": "MIT", + "bin": { + "arka-search-mcp": "server.js" + }, + "engines": { + "node": ">=18" + } +} diff --git a/mcp/arka-search-mcp/server.js b/mcp/arka-search-mcp/server.js new file mode 100644 index 0000000..783aa96 --- /dev/null +++ b/mcp/arka-search-mcp/server.js @@ -0,0 +1,161 @@ +#!/usr/bin/env node +'use strict'; + +const readline = require('readline'); + +const BASE = (process.env.ARKA_SEARCH_URL || 'https://search.arka-ai.ru').replace(/\/+$/, ''); +const KEY = process.env.ARKA_API_KEY || process.env.ARKA_SEARCH_TOKEN || ''; +const UA = process.env.ARKA_SEARCH_UA || 'arka-search-mcp/1.0'; + +const DEFAULT_PROTOCOL = '2025-06-18'; + +const TOOLS = [ + { + name: 'web_search', + description: + 'Search the web via Arka (self-hosted SearXNG). Returns ranked results with title, url and snippet.', + inputSchema: { + type: 'object', + properties: { + q: { type: 'string', description: 'Search query' }, + language: { type: 'string', description: 'Language hint, e.g. ru, en' }, + categories: { + type: 'string', + description: 'general, news, images, it, science, ...', + }, + pageno: { type: 'integer', description: '1-based page number' }, + time_range: { type: 'string', description: 'day | week | month | year' }, + }, + required: ['q'], + }, + }, + { + name: 'web_fetch', + description: + 'Fetch a URL through Arka and return its readable content as Markdown (SSRF-guarded).', + inputSchema: { + type: 'object', + properties: { + url: { type: 'string', description: 'Absolute http(s) URL' }, + }, + required: ['url'], + }, + }, +]; + +function send(msg) { + process.stdout.write(JSON.stringify(msg) + '\n'); +} + +function reply(id, result) { + send({ jsonrpc: '2.0', id, result }); +} + +function replyError(id, code, message) { + send({ jsonrpc: '2.0', id, error: { code, message } }); +} + +async function callGateway(path, params) { + if (!KEY) { + throw new Error('ARKA_API_KEY is not set in the server environment'); + } + const url = new URL(BASE + path); + for (const [k, v] of Object.entries(params)) { + if (v !== undefined && v !== null && v !== '') url.searchParams.set(k, String(v)); + } + const res = await fetch(url, { + headers: { + 'x-api-key': KEY, + accept: 'application/json', + 'user-agent': UA, + }, + signal: AbortSignal.timeout(25000), + }); + const text = await res.text(); + if (!res.ok) { + throw new Error(`Arka search ${res.status}: ${text.slice(0, 400)}`); + } + return text; +} + +async function callTool(name, args) { + if (name === 'web_search') { + return callGateway('/search', { + q: args.q, + language: args.language, + categories: args.categories, + pageno: args.pageno, + time_range: args.time_range, + format: 'json', + }); + } + if (name === 'web_fetch') { + return callGateway('/fetch', { url: args.url }); + } + throw new Error('Unknown tool: ' + name); +} + +async function handle(msg) { + const id = msg.id; + const method = msg.method; + + if (method === 'initialize') { + const requested = msg.params && msg.params.protocolVersion; + reply(id, { + protocolVersion: requested || DEFAULT_PROTOCOL, + capabilities: { tools: { listChanged: false } }, + serverInfo: { name: 'arka-search', version: '1.0.0' }, + }); + return; + } + + if (typeof method === 'string' && method.startsWith('notifications/')) { + return; + } + + if (method === 'ping') { + reply(id, {}); + return; + } + + if (method === 'tools/list') { + reply(id, { tools: TOOLS }); + return; + } + + if (method === 'tools/call') { + const name = msg.params && msg.params.name; + const args = (msg.params && msg.params.arguments) || {}; + try { + const text = await callTool(name, args); + reply(id, { content: [{ type: 'text', text }] }); + } catch (err) { + reply(id, { + content: [{ type: 'text', text: String((err && err.message) || err) }], + isError: true, + }); + } + return; + } + + if (id !== undefined && id !== null) { + replyError(id, -32601, 'Method not found: ' + method); + } +} + +const rl = readline.createInterface({ input: process.stdin }); +rl.on('line', (line) => { + const trimmed = line.trim(); + if (!trimmed) return; + let msg; + try { + msg = JSON.parse(trimmed); + } catch { + return; + } + handle(msg).catch((err) => { + if (msg && msg.id !== undefined && msg.id !== null) { + replyError(msg.id, -32603, String((err && err.message) || err)); + } + }); +}); -- 2.54.0