MCP
Expose Heron services through Model Context Protocol tools, fixed resources and prompts. Tested with SDK server/client 2.4.0 and Node adapter 2.1.2, including 2026-07-28 requests and the SDK’s legacy interoperability. Requires Node.js 24+.
import {Module} from '@heronjs/common';
import {HeronJS} from '@heronjs/core';
import {MCP, Tool} from '@heronjs/mcp';
import {z} from 'zod';
@MCP()
class Tools {
@Tool({name: 'echo', description: 'Echo text', inputSchema: z.object({text: z.string()})})
async echo(input: {text: string}) {
return {content: [{type: 'text' as const, text: input.text}]};
}
}
@Module({mcps: [Tools]})
class App {}
const app = await HeronJS.create({module: App});
// HTTP is the default. Put endpoint options on @MCP.
await app.listen({port: 3000, host: '127.0.0.1'});
// Connect an MCP client to http://127.0.0.1:3000/mcpFor stdio, declare @MCP({path: '/mcp/local', transport: 'stdio'}), create the application
with runtime: {stdio: true}, and call await app.start(). The flag only enables
stdio: other endpoints remain HTTP. Call listen() to serve HTTP endpoints alongside
that stdio endpoint. Only one MCP or ACP endpoint may own process stdio.
Stdout contains protocol messages; framework logs use stderr. Call app.close()
for shutdown. A stdio path identifies a catalog, not a network URL.
Resource({ name, uri, mimeType? }) handlers receive a URL and return SDK
ReadResourceResult. Prompt({ name, argsSchema, description? }) handlers receive
validated arguments and return SDK GetPromptResult. Tools return CallToolResult.
Every handler’s second argument is McpContext, containing caller identity,
signal and the SDK protocol context. Shared service pools belong in DI; HTTP
controller instances are resolved per request. Handle cancellation cooperatively.
Options on @MCP({path, ...options}) include path, allowedHosts and allowedOrigins (hostname lists;
SDK localhost defaults), publicAccess, verifyToken({token, request}),
resourceMetadata and authorize({guard, context}). A remote bind requires a verifier
or explicit publicAccess: true, plus the appropriate Host/Origin allowlists.
The token verifier must return SDK AuthInfo with token, clientId, scopes,
and expiresAt in epoch seconds. Verify token signatures and claims in that hook;
the SDK also checks expiry. Return undefined to reject the token.
Optional resourceMetadata accepts { resource, oauthMetadata, scopesSupported? },
where oauthMetadata is the authorization server metadata. The SDK validates it;
metadata is served at /.well-known/oauth-protected-resource followed by the MCP
path. Tokens must then identify the matching resource URL. Guard metadata is
evaluated against the authenticated identity, or by the configured authorize.
SDK progress/notification APIs are available through using native = useMcp(context) and native.value.mcpReq; import useMcp from @heronjs/mcp.
Unexpected errors are sanitized. Tool execution failures use isError: true.
Outgoing clients, custom WebSocket transports, dynamic catalogs and subscriptions
are outside this package’s first release.
Omitting endpoint transport always selects HTTP, even with runtime.stdio: true.
Registered controllers enable the extension automatically. app.add({mcp: {path}})
sets only the default path; endpoint policy and transport settings there are rejected.
Multiple catalog endpoints
Declare @MCP({path: '/mcp/search'}) and @MCP({path: '/mcp/admin'}) on separate controllers.
Each path has its own tool/resource/prompt catalog. Tool names may repeat across
paths; duplicate entries within one catalog fail registration. Controllers sharing
a path contribute to the same catalog. @MCP() keeps the configured path,
defaulting to /mcp.
Declare settings directly, for example @MCP({path: '/mcp/admin', verifyToken, authorize}).
Controllers sharing a catalog path may have one configuration owner; other contributors
use path-only decorators. Declare the owner with the catalog’s first registration.
Conflicting configuration owners fail before startup. All HTTP catalogs share the
application’s HTTP listener and retain SDK validation and authentication handling.
Select stdio on the catalog decorator. Other catalogs of the same protocol can run
over HTTP simultaneously. The public decorators are MCP, Tool, Resource, and
Prompt.
Running a stdio catalog
After selecting transport: 'stdio' on the Tools catalog, use this bootstrap with the App module from the example above:
import {finished} from 'node:stream/promises';
await using app = await HeronJS.create({module: App, runtime: {stdio: true}});
await app.start();
await finished(process.stdin, {cleanup: true});An MCP client launches the compiled entrypoint with node dist/main.js. Closing stdin ends the scope and awaits application shutdown.
Execution and notification limits
Declare maxConcurrentExecutions (default 32), maxPendingExecutions (256), and
maxPendingExecutionBytes (4 MiB) on the endpoint’s @MCP configuration owner.
The pending limits include active work and apply across that endpoint’s HTTP requests.
Native-hook mcpReq.notify() calls are ordered and awaitable; maxPendingNotifications
(128) and maxPendingNotificationBytes (1 MiB) bound their pending production per invocation.
Always await notification sends. These limits do not bound the MCP SDK’s internal HTTP
SSE buffer; they do not provide end-to-end output backpressure for a stalled HTTP client.