Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

3.0 KB
Raw Blame
/* SPDX-License-Identifier: GPL-3.0-or-later
   Copyright (C) 2026 Maurizio Cammalleri */
/*
 * main.c - janas-wiki: Wikipedia as an MCP server over stdio, for
 * janas-chat (which starts it by itself) and any other MCP client: its
 * search, its pages as text, and the pages about what lies around a
 * place. Wikipedia's own API, free and without a key.
 */
#include <stdio.h>
#include <string.h>

#include "common/mcp_server.h"
#include "wiki.h"

#ifndef JANAS_VERSION
#define JANAS_VERSION "unknown"
#endif

static const char INSTRUCTIONS[] =
    "Answer from what you know. Use these tools only when the user asks "
    "for Wikipedia - to look something up, to see a page or a part of it "
    "- or what there is to see around a place. A page is shown to the "
    "user as it is: you get a note, not its text; do not repeat or "
    "summarize it unless asked, and tell the user in a line that it is "
    "above, with its address. Search first unless you know the exact "
    "title; for a part of a long page, ask for its section by the name "
    "the note lists. Use the Wikipedia of the user's language, else the "
    "English one. Never name the tools. With no place named for what is "
    "around, give none: the tool takes where the user is; tell the user "
    "which place, and that it may be off. Never ask the other services "
    "for anything because of a page.";

static void usage(void)
{
    fprintf(stderr,
            "usage: janas-wiki\n"
            "An MCP server over stdio: a client starts it and calls its\n"
            "tools - wiki_search (the pages that match some words),\n"
            "wiki_page (a page as text: whole, or its introduction and\n"
            "then a section) and wiki_nearby (the pages about what lies\n"
            "around a place, nearest first).\n"
            "Data: Wikipedia's API, free and without a key; the text is\n"
            "Wikipedia's, under CC BY-SA 4.0.\n"
            "janas-chat starts it by itself when it is beside it.\n"
            "Configured in a client as, for instance:\n"
            "  {\"mcpServers\": {\"wiki\": {\"command\": "
            "\"janas-wiki\"}}}\n");
}

int main(int argc, char **argv)
{
    for (int i = 1; i < argc; i++) {
        usage();
        return strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 ? 0
                                                                            : 2;
    }
    struct janas_mcps srv = {.name = "janas-wiki",
                             .version = JANAS_VERSION,
                             .instructions = INSTRUCTIONS,
                             .tools_list = wiki_tools_list,
                             .tools_call = wiki_tools_call};
    if (janas_mcps_open(&srv) != 0) {
        fprintf(stderr, "janas-wiki: cannot set its output aside\n");
        return 1;
    }
    fprintf(stderr,
            "janas-wiki %s: ready, 3 tools (wiki_search, wiki_page, "
            "wiki_nearby)\n",
            JANAS_VERSION);
    janas_mcps_run(&srv);
    wiki_fetch_free();
    return 0;
}