Back to Discover

Project-Koma

connector

swnotmetal

Classifies prompt injection, jailbreaks, and out-of-scope user input before agents act on it.

View on GitHub
0 starsSynced Aug 15, 2026

Install to Claude Code

/plugin marketplace add swnotmetal/Project-Koma

README

Koma

A prompt-injection firewall for Node.js.

Stop malicious prompts before they reach your LLM, tools, or RAG pipeline.

npm install koma-gate

Koma

License CI koma-gate koma-scout koma-core
benchmark total downloads visitors

中文版

Koma demo

Security primitives distilled from a real AI application.How Koma was built


What It Stops

Your appAttackFixInstall
AI chatbotPrompt injection / jailbreakSemantic filter blocks attacks before the modelkoma-gate
Voice AIAudio abuse / floodingValidation + rate limiting + geokoma-scout
RAG / searchData enumeration / scrapingSplit index from content, token-gate retrievalkoma-core

Different attacks cross different boundaries. Koma provides a small primitive for each one.


What Koma Is — and Isn't

Is: composable security primitives · defense-in-depth · usable independently · sits outside the model's authority

Isn't: a model · an agent framework · a replacement for authorization · a magic prompt-injection detector · a complete security boundary by itself


Benchmarks

I threw 1,769 real prompt-injection attacks at Koma Gate in fail-closed mode, using real providers — not mock adapters.

ProviderRecallPrecisionFalse Positives
DeepSeek (deepseek-chat)98.8%100%0
Google (gemini-2.5-flash)96.2%100%0

Chinese attack set: 100% recall · 100% precision · 0% FPR across 8 categories.

Can you break it? Open an issue with an attack Koma misses. → Full methodology


Quick Start

import { createGeneralKnowledgeGuard } from 'koma-gate';

const guard = createGeneralKnowledgeGuard({
  llm: { apiKey: process.env.GEMINI_API_KEY },
});

app.post('/api/chat', guard.middleware(), async (req, res) => {
  // Only in-scope requests reach your model
  res.json({ reply: await chat(req.body.message) });
});
git clone https://github.com/swnotmetal/Project-Koma
cd Project-Koma && node demo/server.js
curl http://localhost:8080/self-test

Three Defenses

koma-gate — Prompt injection firewall. LLM-based scope classifier that blocks jailbreaks, off-topic requests, and instruction overrides. Supports OpenAI, Anthropic, Google, DeepSeek, and local Ollama models. README →

koma-scout — Perimeter protection. Rate limiting, audio upload validation, geo allowlisting. Cheap checks before expensive AI work. README →

Koma Scout perimeter checks

koma-core — Protected RAG storage. Public search index, private content, opaque HKDF-derived tokens. Discovery is not authorization. README →

Koma Core split-store

Each package works standalone. Stack them: Gate filters → Scout throttles → Core stores.

MCP servers — expose Koma to AI agents directly:

  • koma-gate-mcpclassify_input tool for prompt-injection checks. README →
  • koma-core-mcpsearch_docs + retrieve_doc for protected RAG retrieval. README →
{
  "mcpServers": {
    "koma-gate": { "command": "npx", "args": ["-y", "koma-gate-mcp"] },
    "koma-core": { "command": "npx", "args": ["-y", "koma-core-mcp"] }
  }
}

Using an AI coding agent?

Tell it:

"Add Koma to protect this AI endpoint. Use koma-gate for prompt injection, koma-scout for perimeter abuse, and koma-core for protected RAG retrieval. Each works standalone."

Koma is designed for both human and agent discoverability — including two MCP servers. See llms.txt.


Trust & Safety

  • Zero runtime dependencies. No supply-chain surface.
  • No code execution. Classifies, rate-limits, stores — never executes AI output.
  • Fail-closed by default. A broken guard blocks, not passes.
  • CodeQL on every push. Targets OWASP LLM01.
  • MIT licensed.

Security policy · Known limitations · Comparison with alternatives · Contributing


Koma comes from Komainu ("狛犬"), the stone guardian lions of Japanese Shinto shrines. Three defense layers. Each standalone. Patterns distilled from production, not papers.

License

Rendered live from swnotmetal/Project-Koma's GitHub README — not stored, always reflects the source repo.

1 Install Method

NameDescriptionCategorySource
npm packageInstall via npm (stdio transport)mcp-serverkoma-gate-mcp

0 Comments

Login required
Log in to post a comment or update on this repo.

No comments yet — be the first to share an update.