hono-apcore
hono-apcore
Hono 用アダプタで、apcore AI-Perceivable モジュールエコシステム向けです。Hono アプリを MCP ツールや OpenAI 互換の関数定義に変換します。ツールを明示的に宣言するか、既存のルートをスキャンするかのどちらかで実現します。
特徴
2つの入り口 —
defineTool()/defineToolset()でツールを宣言するか、既存のルートをコード変更なしでスキャンするルートリプレイ — スキャンしたルートは
app.request()を介してコールバックするモジュールになるため、ミドルウェア、バリデータ、エラーハンドラもすべて引き続き実行されます1つのポート —
mountMcp()は MCP エンドポイント、Tool Explorer、/healthを同じ Hono アプリから提供しますアノテーション推論 —
GET→ readonly + cacheable、PUT→ idempotent、DELETE→ destructive(RFC 9110 の安全なメソッドのセマンティクス)マルチスキーマ — TypeBox、Zod 3、Zod 4、プレーンな JSON Schema を、優先度チェーンで自動検出
コンテキスト、ACL、アイデンティティ —
apcore()ミドルウェアは、W3C トレース伝播を備えたリクエストごとの apcoreContextを構築するため、ACL ルールもルートに適用されますランタイム非依存のコア —
apcore-mcp、apcore-cli、apcore-a2aは遅延ロードされるオプションのピアであるため、hono-apcoreをインポートしてもエッジビルドにnode:httpが引き込まれることはありませんCLI —
hono-apcore scan | serve | exportはプレーンな Hono アプリに対して動作しますYAML バインディング — ソースに触れずにモジュールを宣言的に登録
Related MCP server: hono-mcp-server
インストール
npm install hono-apcore honoオプションのピアは、使用するサーフェスのみにインストールされます:
npm install apcore-mcp @modelcontextprotocol/sdk # MCP server + Tool Explorer
npm install @hono/node-server # mountMcp() on the Node runtime
npm install apcore-cli # CLI surface
npm install apcore-a2a # A2A agent surface
npm install @sinclair/typebox # TypeBox schemas (recommended)
npm install zod # Zod schemas要件: Node.js >= 18、Hono >= 4(Hono 4.13 でテスト済み)。
クイックスタート
1. ツールを宣言する
// todo.tools.ts
import { Type } from '@sinclair/typebox';
import { defineToolset } from 'hono-apcore';
export const todoTools = defineToolset({
namespace: 'todo',
description: 'Todo list management',
tags: ['todo'],
tools: {
list: {
description: 'List all todos, optionally filtered by status',
inputSchema: Type.Object({ done: Type.Optional(Type.Boolean()) }),
annotations: { readonly: true, idempotent: true },
handler: (inputs) => ({ todos: store.list(inputs.done as boolean | undefined) }),
},
add: {
description: 'Add a new todo item',
inputSchema: Type.Object({ title: Type.String() }),
annotations: { readonly: false },
handler: (inputs) => ({ todo: store.add(String(inputs.title)) }),
},
},
});2. アプリに組み込む
// app.ts
import { Hono } from 'hono';
import { apcore, createApcore } from 'hono-apcore';
import { todoTools } from './todo.tools.js';
export const ap = createApcore({
tools: todoTools,
mcp: { name: 'my-app', explorer: true, allowExecute: true },
});
export const app = new Hono();
app.use('*', apcore(ap));
app.get('/todos', (c) => c.json(store.list()));3. 起動
// main.ts
import { serve } from '@hono/node-server';
import { app, ap } from './app.js';
await ap.init(app); // register tools + scan routes
await ap.mountMcp(app); // mount /mcp, /explorer, /health
serve({ fetch: app.fetch, port: 3000 });アプリは次の応答を行います:
REST —
http://localhost:3000/todosMCP —
http://localhost:3000/mcpTool Explorer —
http://localhost:3000/explorer/
機能を公開する2つの方法
defineTool() — 明示的なツール
NestJS の @ApTool デコレータに相当する Hono 版です。Hono にはデコレートするクラスや DI コンテナがないため、ツールは独自のメタデータとハンドラを持つプレーンなオブジェクトです。
import { defineTool } from 'hono-apcore';
const sendEmail = defineTool({
namespace: 'email',
name: 'send', // -> module id "email.send"
description: 'Send an email',
inputSchema: Type.Object({ to: Type.String(), body: Type.String() }),
outputSchema: Type.Object({ messageId: Type.String() }),
annotations: { readonly: false, destructive: false, requiresApproval: true },
tags: ['email'],
params: { to: 'Recipient address' }, // merged into the schema descriptions
handler: async (inputs, context) => mailer.send(inputs, context),
});フィールド | 説明 |
| そのまま使用されます。それ以外の場合は |
| TypeBox、Zod、またはプレーンな JSON Schema |
|
|
| パラメータごとの説明文を入力スキーマにマージします。JavaScript は Python が docstring を読むように実行時に関数の先頭コメントを読むことができないため、これは明示的です。 |
|
|
ルートスキャン — 侵入ゼロのツール
スキャナをアプリに向けると、すべてのルートが app.request() を介してプロセス内でリプレイするモジュールになります:
const ap = createApcore({
routes: {
excludePaths: ['/health', '/mcp*', '/explorer*'],
modulePrefix: 'api',
},
});
await ap.init(app); // -> api.todos.list, api.todos.get, api.todos.create, …モジュール ID はパスと HTTP メソッドから生成されます:
ルート | モジュール ID | 推論されたアノテーション |
|
|
|
|
|
|
|
| — |
|
|
|
|
|
|
生成された入力スキーマには、パスパラメータごとに必須の文字列プロパティが1つ含まれ、さらに自由形式の query オブジェクト(GET/DELETE)または body オブジェクト(POST/PUT/PATCH)が含まれます。ルートごとに任意の部分を上書きできます:
routes: {
overrides: {
'GET /todos': {
id: 'todo.all',
description: 'Every todo, newest first',
inputSchema: Type.Object({ done: Type.Optional(Type.Boolean()) }),
annotations: { readonly: true, idempotent: true },
},
'DELETE /admin/wipe': { skip: true },
},
}実行は app.request() を介して戻るため、AI 呼び出しは HTTP 呼び出しと同じコードパスを実行します — 認証ミドルウェア、バリデータ、エラーハンドラなどすべてを含みます。apcore Context からのアイデンティティと W3C トレースヘッダーは、リプレイされたリクエストに転送されます。
API リファレンス
createApcore(options)
HonoApcore を返します — Registry、Executor、およびすべてのサーフェスがそれにぶら下がります。
createApcore({
extensionsDir?: string | null, // scanned by Registry.discover()
acl?: ACL, // enforced by the Executor on every call
middleware?: Middleware[], // apcore middleware installed on the Executor
bindings?: string, // YAML bindings file loaded during init()
tools?: ApToolDefinition[], // registered during init()
routes?: RouteScanOptions, // route-scanner configuration
settings?: Partial<ApcoreSettings>, // overrides for the APCORE_* settings
mcp?: ApcoreMcpOptions, // presence enables the MCP surface
cli?: ApcoreCliOptions, // presence enables the CLI surface
a2a?: ApcoreA2aOptions, // presence enables the A2A surface
})メソッド | 説明 |
| ツールとバインディングを検出・登録し、ルートをスキャンし、スタンドアロンサーフェスを起動します。冪等です。 |
| 実行中の |
| 実行時にツール定義を登録します |
| プレーンなサービスオブジェクトのメソッドを登録します |
| アプリのルートをスキャンして登録します |
| このインスタンスが使用するマージ済みのルートスキャンオプション |
| YAML バインディングファイルを読み込みます |
|
|
| OpenAI 互換の関数定義 |
| MCP と A2A のサーフェスをシャットダウンします |
apcore(instance | options, middlewareOptions?)
インスタンスとリクエストごとの apcore Context を Hono コンテキストに配置する Hono ミドルウェアです。
app.use('*', apcore(ap));
app.get('/orders', async (c) =>
c.json(await getApcore(c).executor.call('orders.list', {}, getApcoreContext(c))),
);変数マップが拡張されるため、c.get('apcore') と c.get('apcoreContext') も型付けされます。モジュールを呼び出さないルートには { skipContext: true } を渡すか、実際の認証を組み込むには { contextFactory } を渡します。
HonoContextFactory
Hono コンテキスト、Request、または素の Headers から apcore Context を構築します。
アイデンティティ解決は、次の順序で行われます:x-user-id → Authorization: Bearer …(アイデンティティ ID "bearer")→ 素の x-roles ヘッダー(デモ用のショートカット)→ 匿名。traceparent ヘッダーがトレース ID を提供し、x-correlation-id(または x-request-id)は context.data に格納されます。
new HonoContextFactory({
resolveIdentity: (headers) => identityFromSession(headers), // wins over the above
data: (headers) => ({ tenant: headers.get('x-tenant') }),
});MCP
ApcoreMcpService は MCP サーバーを2つの方法で実行します。
組み込み — 1つのプロセス、1つのポート:
await ap.mountMcp(app, { endpoint: '/mcp', explorer: true, allowExecute: true });これには @hono/node-server が c.env で公開する生の Node リクエストおよびレスポンスオブジェクトが必要なため、Node 専用です。他のランタイムでマウントされたハンドラは、その説明とともに 501 を返します。endpoint は HTTP サーバーが見るパスである必要があります — アプリが basePath の下にある場合はプレフィックスを含めてください。
スタンドアロン — 別のポート、または CLI で起動したサーバー用の stdio:
createApcore({ mcp: { transport: 'streamable-http', host: '0.0.0.0', port: 8000 } });
// init() starts it, because `transport` was set explicitly主な MCP オプション:
フィールド | タイプ | 説明 |
|
| スタンドアロンのトランスポート。設定すると |
|
| HTTP トランスポートのバインドアドレス |
|
| サーバーの識別情報 |
| Tool Explorer の Web UI | |
| JWT またはカスタム認証 | |
| 一致するモジュールのみを公開 | |
|
| すべての呼び出しで入力スキーマを強制 |
| メトリクス + 使用状況ミドルウェアとそのエンドポイント | |
| 結果のシリアライズ | |
| 破壊的なツールの承認ゲート | |
| MCP エグゼキュータ用の追加の apcore ミドルウェア / ACL |
スキーマアダプタ
スキーマは自動検出され、優先度チェーンを介して変換されます:
アダプタ | 優先度 | 入力 |
| 100 |
|
| 50 | Zod 3( |
| 30 | プレーンな JSON Schema オブジェクト |
検出は構造的です — TypeBox も Zod も実行時にはインポートされません — そのため、ホストアプリがどちらをインストールしても(またはどちらもインストールしなくても)問題ありません。独自のアダプタは SchemaExtractor.registerAdapter() で登録できます。
YAML バインディング
ソースに触れずにモジュールを登録:
bindings:
- module_id: email.send
target: EmailService.send
description: Send an email
input_schema:
type: object
properties:
to: { type: string }
tags: [email, mutate]
annotations:
readonly: falseimport { resolverFromObjects } from 'hono-apcore';
await ap.loadBindings('./bindings.yaml', resolverFromObjects({ EmailService: mailer }));逆に、writeBindingsFile() はスキャンしたモジュールをシリアライズして出力します — これは hono-apcore scan --format yaml が行うことです。
CLI
hono-apcore scan ./src/app.ts # print the modules a scan would produce
hono-apcore scan ./src/app.ts --format yaml --out bindings.yaml
hono-apcore serve ./src/app.ts --transport http --port 8000 --explorer
hono-apcore export ./src/app.ts --out tools.jsonエントリは path[:export] です。エクスポートはデフォルトで default、次に app になります。モジュールが 任意の 名前で HonoApcore をエクスポートする場合、その設定(ルートフィルタ、モジュールプレフィックス、MCP オプション)が尊重されるため、scan はアプリ自体が登録するモジュールを正確に報告します。CLI フラグはそれを上書きします。インスタンスがないエントリでも動作するため、serve は apcore を認識していないアプリに対して実行できます。TypeScript エントリにはローダーが必要です:
npx tsx node_modules/.bin/hono-apcore scan ./src/app.ts設定(APCORE_*)
すべての apcore 統合が実装する標準設定で、環境から読み取られ、settings で上書きできます:
変数 | 型 | デフォルト | 目的 |
| bool |
| マスタースイッチ — |
| bool |
| 詳細ログ / イントロスペクション |
| list |
| 有効なスキャナー識別子 |
| list |
| 含めるルートパターン(空 = すべて) |
| list |
| 除外するルートパターン |
| str |
| 生成されたモジュールIDに付加されるプレフィックス |
| bool |
| MCP/A2A エンドポイントに認証を要求 |
| str |
|
|
| str |
| MCP トランスポート: |
| str |
| トランスポートが stdio でない場合のバインドアドレス |
| int |
| トランスポートが stdio でない場合のバインドポート |
オプショナルピアは再エクスポートされない
NestJS アダプターとは異なり、hono-apcore は apcore-mcp / apcore-cli / apcore-a2a のサーフェスを再エクスポートしません。再エクスポートするとそれらが即時ロードされ、apcore-mcp は node:http を引き込むため、MCP サーフェスを一切使用しないアプリの Workers、Deno、Bun ビルドが壊れます。これらのシンボルはそれぞれのパッケージからインポートしてください:
import { JWTAuthenticator, getCurrentIdentity } from 'apcore-mcp';
import { createCli } from 'apcore-cli';
import { A2AClient } from 'apcore-a2a';apcore-js と apcore-toolkit はハード依存関係であるため、それらの共通シンボル(ACL、Config、registerSysModules、TraceContext、BaseScanner、formatModules など)は hono-apcore から直接再エクスポートされます。
例
例 | 内容 |
完全なアプリ: 手書きツールとルートスキャン、JWT、ACL、システムモジュール、Docker | |
apcore ACL によって管理されるルート — 管理者のみ |
pnpm install && pnpm build
cd examples/demo && pnpm install && pnpm dev詳細ドキュメント
機能概要 — アーキテクチャと依存関係グラフ
ツール定義 —
defineTool、defineToolset、モジュールIDルートスキャナー — ルートがモジュールになる仕組みとリプレイのコスト
MCP 統合 — 組み込み vs スタンドアロン、Node ブリッジ
スキーマ抽出 — アダプターチェーンとカスタムアダプター
コンテキストと ACL — アイデンティティ、トレーシング、ルートの管理
スクリプト
コマンド | 説明 |
| TypeScript をコンパイル |
| ウォッチモードでコンパイル |
| テストスイートを実行(vitest) |
| カバレッジ付きテスト(90% しきい値) |
| 出力なしで型チェック |
| ソースとテストをリント |
ライセンス
Apache-2.0
This server cannot be deployed
Maintenance
Related MCP Connectors
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Build, validate, deploy — HTTP APIs, cron jobs, webhooks and MCP tools — from your AI client.
Give any MCP-compatible AI assistant a builder for live, hosted web tools and workflows.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceExposes Hono API endpoints as Model Context Protocol tools, allowing LLMs to interact with your API routes through a dedicated MCP endpoint. It provides helpers to describe routes and includes a codemode for dynamic API interaction via search and execute tools.34 npm86MIT
- AlicenseNot gradedqualityCmaintenanceEasily expose your Hono API endpoints as MCP tools with minimal configuration, supporting type-safe input handling and tool registration.34 npm2MIT
- AlicenseNot gradedqualityDmaintenanceExposes OpenAPI endpoints as MCP tools, enabling LLMs to discover and interact with REST APIs through the MCP protocol.9 npmMIT
- AlicenseNot gradedqualityCmaintenanceExposes FastAPI routes as MCP tools with auto-discovery, Pydantic schema extraction, and built-in observability.Apache 2.0