agents
Version:
A home for your AI agents
108 lines (106 loc) • 3.77 kB
TypeScript
import { ClientOptions } from "@modelcontextprotocol/client";
import {
CreateMcpHandlerOptions,
McpHandlerRequestOptions,
McpServerFactory,
ServerNotifier
} from "@modelcontextprotocol/server";
//#region src/mcp/types.d.ts
type MaybePromise<T> = T | Promise<T>;
type HttpTransportType = "sse" | "streamable-http";
type BaseTransportType = HttpTransportType | "rpc";
type TransportType = BaseTransportType | "auto";
/**
* Agents-owned MCP client configuration. Only these SDK behaviours are part of
* the supported interface; new beta SDK fields are not persisted or exposed
* accidentally.
*/
interface McpClientOptions {
capabilities?: ClientOptions["capabilities"];
jsonSchemaValidator?: ClientOptions["jsonSchemaValidator"];
versionNegotiation?: ClientOptions["versionNegotiation"];
inputRequired?: ClientOptions["inputRequired"];
listChanged?: ClientOptions["listChanged"];
supportedProtocolVersions?: ClientOptions["supportedProtocolVersions"];
enforceStrictCapabilities?: ClientOptions["enforceStrictCapabilities"];
debouncedNotificationMethods?: ClientOptions["debouncedNotificationMethods"];
listMaxPages?: ClientOptions["listMaxPages"];
responseCacheStore?: ClientOptions["responseCacheStore"];
cachePartition?: ClientOptions["cachePartition"];
defaultCacheTtlMs?: ClientOptions["defaultCacheTtlMs"];
}
interface CORSOptions {
origin?: string;
methods?: string;
headers?: string;
maxAge?: number;
exposeHeaders?: string;
}
interface ServeOptions {
binding?: string;
corsOptions?: CORSOptions;
transport?: TransportType;
jurisdiction?: DurableObjectJurisdiction;
}
//#endregion
//#region src/mcp/auth-context.d.ts
interface McpAuthContext {
props: Record<string, unknown>;
}
declare function getMcpAuthContext(): McpAuthContext | undefined;
//#endregion
//#region src/mcp/handler-stateless.d.ts
interface CreateStatelessMcpHandlerOptions extends Omit<
CreateMcpHandlerOptions,
"bus"
> {
/** Exact pathname handled by this Worker wrapper. @default "/mcp" */
route?: string;
/** CORS headers applied by the Worker wrapper. Pass `false` to disable. */
corsOptions?: CORSOptions | false;
/**
* Restrict `Host` headers to these hostnames. Localhost and `workers.dev`
* endpoints receive matching defaults; custom domains rely on Cloudflare
* routing unless this option is set.
*/
allowedHostnames?: string[];
/**
* Restrict present browser `Origin` headers to these hostnames. Requests
* without an Origin (including non-browser MCP clients) remain valid. The
* default includes localhost-class Origins, the endpoint's `workers.dev`
* hostname, and a concrete `corsOptions.origin` hostname. Pass `"*"` only
* when equivalent Origin validation runs in trusted middleware upstream.
*/
allowedOriginHostnames?: string[] | "*";
/** Application props exposed through {@link getMcpAuthContext}. */
authContext?: McpAuthContext;
}
type StatelessMcpHandler = {
(request: Request, env: unknown, ctx: ExecutionContext): Promise<Response>;
fetch(
request: Request,
options?: McpHandlerRequestOptions
): Promise<Response>;
notify: ServerNotifier;
};
type StatelessMcpServerInput = McpServerFactory;
declare function createStatelessMcpHandler(
factory: StatelessMcpServerInput,
options?: CreateStatelessMcpHandlerOptions
): StatelessMcpHandler;
//#endregion
export {
McpAuthContext as a,
CORSOptions as c,
ServeOptions as d,
TransportType as f,
createStatelessMcpHandler as i,
MaybePromise as l,
StatelessMcpHandler as n,
getMcpAuthContext as o,
StatelessMcpServerInput as r,
BaseTransportType as s,
CreateStatelessMcpHandlerOptions as t,
McpClientOptions as u
};
//# sourceMappingURL=handler-stateless-C_bo-Ytq.d.ts.map