@absolutejs/mcp
Enables serving a remote Model Context Protocol endpoint by exposing tools, prompts, and resources with customizable authorization and hooks, allowing AI models to interact with your application through a standardized JSON-RPC interface.
README
@absolutejs/mcp
Serve a remote Model Context Protocol endpoint
— streamable HTTP, stateless — from a tool/prompt/resource registry. You supply
which tools to expose and how to authorize a request into a caller; the
package owns the JSON-RPC protocol, protocol-version negotiation, RFC 9728
discovery metadata, and the 401 challenge that lets a client find your
authorization server.
Nothing here depends on a model. The tool shape is structurally compatible with
@absolutejs/ai's AIToolMap, so an AI tool
registry serves over MCP without conversion — but any typed tool registry works.
bun add @absolutejs/mcp
Peer dependency: elysia.
Define an endpoint
import { Elysia } from "elysia";
import { mcpServer, verifyBearer } from "@absolutejs/mcp";
import { verifyJwt } from "@absolutejs/auth"; // or any JWT verifier
type Caller = { userId: string };
const server = new Elysia().use(
mcpServer<Caller>({
path: "/mcp",
issuer: "https://your.app",
serverInfo: { name: "your-app", title: "Your App", version: "1.0.0" },
instructions: "What the model should know about this server.",
scopesSupported: ["openid", "mcp"],
serveRootMetadata: true,
// You decide who is allowed in. verifyBearer does the standard OAuth
// access-token checks; add your own (billing, role, MFA) on top.
authorize: async (request) => {
const token = await verifyBearer({
request,
issuer: "https://your.app",
requiredScope: "mcp",
verify: (jwt) => verifyJwt(jwt, publicJwk),
});
if ("error" in token) return { ok: false, reason: token.error };
return { ok: true, caller: { userId: token.subject } };
},
// Called once per request; build the tools for this caller.
tools: ({ caller }) => buildToolsFor(caller.userId),
}),
);
That is a complete member endpoint. GET /mcp returns 405, POST /mcp speaks
JSON-RPC, and GET /.well-known/oauth-protected-resource[/mcp] serves the
discovery metadata.
Guards, prompts, resources
Everything beyond tools is a hook — the package ships no opinion about billing, storage, or auditing.
mcpServer<Caller>({
// ...as above
// Refuse a single call before it runs (credits, rate limit). The message
// comes back as an isError tool result the model can relay — not a crash.
beforeCall: async ({ caller }) =>
(await outOfCredits(caller))
? { block: "Out of credits this cycle." }
: undefined,
// Audit every call. `meta` carries whatever the tool handler wrote.
onCall: ({ caller, name, ok, meta }) =>
recordCall({ caller, name, ok, touched: meta.touched }),
// Server-side prompts: recipes the client shows in its picker.
prompts: {
definitions: {
daily_briefing: { title: "Daily briefing", description: "..." },
},
get: async ({ name, args, caller }) => buildPromptText(name, args, caller),
},
// Readable resources.
resources: {
list: ({ caller }) => listResources(caller),
read: ({ caller, uri }) => readResource(caller, uri), // string | null
},
});
The meta scratchpad
Each tools/call gets a fresh meta object shared between tools,
beforeCall, and onCall. A tool handler can record what it touched, and your
audit hook can read it back:
tools: ({ caller, meta }) =>
buildAdminTools(caller, (memberId) => { meta.touched = memberId; }),
onCall: ({ meta, name, ok }) =>
ledger.write({ tool: name, ok, member: meta.touched }),
A second, stricter endpoint
mcpServer is per-endpoint, so an admin console is the same call with a
different scope, a stricter authorize (role + MFA + a kill switch, re-checked
live), a rate-limit beforeCall, and an audit onCall:
app.use(mcpServer({ path: "/mcp" /* member */ })).use(
mcpServer({
path: "/mcp/admin",
scopesSupported: ["openid", "mcp:admin"] /* stricter */,
}),
);
Only one endpoint per app should set serveRootMetadata (the un-suffixed alias).
License
Business Source License 1.1 — see LICENSE. Converts to Apache 2.0 on the Change Date.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。