@barry-rocks/sdk/mcp
Serving a bag’s tools over MCP on its own: startBagServer,
serveBagOverHttp, and the bag resource server. Barry’s MCP server serves
packed bags itself; use this to run a bag as a standalone MCP server.
import { … } from "@barry-rocks/sdk/mcp";Interfaces
Section titled “Interfaces”BagServerOptions
Section titled “BagServerOptions”Properties
Section titled “Properties”| Property | Type |
|---|---|
bagDir |
string |
name? |
string |
version? |
string |
LoadedBagResources
Section titled “LoadedBagResources”The loaded-once inputs an MCP resource server is built from.
Loading parses the manifest, walks skills/+actions/ and runs
loadBagToolDefinitions — work worth doing once per bag directory rather
than once per client session. An McpServer still binds to a single
transport, so each session gets its own server, but they share these
resources.
Properties
Section titled “Properties”| Property | Type |
|---|---|
bagDir |
string |
manifest |
BagManifest | null |
rawManifest |
Record<string, unknown> | null |
tools |
BagToolMeta[] |
StartBagServerOptions
Section titled “StartBagServerOptions”Properties
Section titled “Properties”| Property | Type |
|---|---|
name |
string |
tools |
AnyToolDefinition[] |
version? |
string |
Variables
Section titled “Variables”createBagServer
Section titled “createBagServer”
constcreateBagServer: (options) =>Promise<McpServer> =createBagResourceServer
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
BagServerOptions |
Returns
Section titled “Returns”Promise<McpServer>
Deprecated
Section titled “Deprecated”Renamed to createBagResourceServer. This factory builds
the HTTP resource server (manifest/skills/traits as barry:// resources),
not the stdio tool server startBagServer — the two “bag server” names were
a documented source of confusion. Kept as an alias for any external importer
of the old name; prefer createBagResourceServer.
Functions
Section titled “Functions”buildBagResourceServer()
Section titled “buildBagResourceServer()”buildBagResourceServer(
resources,options?):McpServer
Build an MCP resource server from already-loaded bag resources.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
resources |
LoadedBagResources |
options? |
{ name?: string; version?: string; } |
options.name? |
string |
options.version? |
string |
Returns
Section titled “Returns”McpServer
createBagResourceServer()
Section titled “createBagResourceServer()”createBagResourceServer(
options):Promise<McpServer>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
BagServerOptions |
Returns
Section titled “Returns”Promise<McpServer>
loadBagResources()
Section titled “loadBagResources()”loadBagResources(
bagDir):Promise<LoadedBagResources>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bagDir |
string |
Returns
Section titled “Returns”Promise<LoadedBagResources>
serveBagOverHttp()
Section titled “serveBagOverHttp()”serveBagOverHttp(
options):Promise<{close: () =>Promise<void>;url:string; }>
Serve a local bag over HTTP as a remote MCP bag.
Extracted so the CLI (barry bag serve) and the QA mock exercise the same
code path — this is also the reference implementation a third-party author
can point at when writing their own server in another language.
Binds to 127.0.0.1 by default: this exposes a bag’s manifest and skills, so listening on all interfaces must be a deliberate choice.
Authentication: when BARRY_SECRET is set in the environment (or secret
is passed), every /mcp request must carry it as a bearer token or
x-barry-secret, parsed by the same requestCredential the API server
uses. When no secret is configured this route is UNAUTHENTICATED BY DESIGN:
it binds to loopback and serves only a bag’s own manifest/skills/traits to
local tooling (barry bag serve, the QA mock). Exposing it off-host is the
caller’s deliberate choice and should set a secret.
When port is omitted, uses listenOnAssignedPort to read PORT from env —
the standard path for services started by the service management. Tests and CLI
callers pass an explicit port.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
{ bagDir: string; host?: string; idleTimeoutMs?: number; port?: number; secret?: string; } |
- |
options.bagDir |
string |
- |
options.host? |
string |
- |
options.idleTimeoutMs? |
number |
Evict a session whose last request is older than this (ms). Default 5 min. |
options.port? |
number |
- |
options.secret? |
string |
Require this secret on every /mcp request. Defaults to BARRY_SECRET. |
Returns
Section titled “Returns”Promise<{ close: () => Promise<void>; url: string; }>
startBagServer()
Section titled “startBagServer()”startBagServer(
options):Promise<McpServer>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
StartBagServerOptions |
Returns
Section titled “Returns”Promise<McpServer>