@useagents/redop 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -5
- package/package.json +2 -2
- package/dist/adapters/schema.d.ts +0 -7
- package/dist/index.d.ts +0 -5
- package/dist/plugins/index.d.ts +0 -98
- package/dist/redop.d.ts +0 -109
- package/dist/transports/http.d.ts +0 -7
- package/dist/transports/stdio.d.ts +0 -4
- package/dist/types.d.ts +0 -328
package/dist/index.js
CHANGED
|
@@ -60,8 +60,9 @@ function createSessionStore(timeoutMs) {
|
|
|
60
60
|
function gc() {
|
|
61
61
|
const now = Date.now();
|
|
62
62
|
for (const [id, s] of sessions) {
|
|
63
|
-
if (now - s.lastSeen > timeoutMs)
|
|
63
|
+
if (now - s.lastSeen > timeoutMs) {
|
|
64
64
|
sessions.delete(id);
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
const gcTimer = setInterval(gc, 30000);
|
|
@@ -73,8 +74,9 @@ function createSessionStore(timeoutMs) {
|
|
|
73
74
|
},
|
|
74
75
|
touch(id) {
|
|
75
76
|
const s = sessions.get(id);
|
|
76
|
-
if (!s)
|
|
77
|
+
if (!s) {
|
|
77
78
|
return false;
|
|
79
|
+
}
|
|
78
80
|
s.lastSeen = Date.now();
|
|
79
81
|
return true;
|
|
80
82
|
},
|
|
@@ -87,8 +89,9 @@ function createSessionStore(timeoutMs) {
|
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
function buildCorsHeaders(cors, requestOrigin) {
|
|
90
|
-
if (!cors)
|
|
92
|
+
if (!cors) {
|
|
91
93
|
return {};
|
|
94
|
+
}
|
|
92
95
|
if (cors === true) {
|
|
93
96
|
return {
|
|
94
97
|
"Access-Control-Allow-Origin": requestOrigin ?? "*",
|
|
@@ -151,7 +154,7 @@ async function handleJsonRpc(body, tools, runner, requestMeta, serverInfo, sessi
|
|
|
151
154
|
if (method === "tools/call") {
|
|
152
155
|
const p = params;
|
|
153
156
|
const toolName = p?.name;
|
|
154
|
-
if (!toolName
|
|
157
|
+
if (!(toolName && tools.has(toolName))) {
|
|
155
158
|
return {
|
|
156
159
|
jsonrpc: "2.0",
|
|
157
160
|
id,
|
|
@@ -554,8 +557,9 @@ class Redop {
|
|
|
554
557
|
}
|
|
555
558
|
async _runTool(toolName, rawArgs, request = DEFAULT_REQUEST_META) {
|
|
556
559
|
const tool = this._tools.get(toolName);
|
|
557
|
-
if (!tool)
|
|
560
|
+
if (!tool) {
|
|
558
561
|
throw new Error(`Unknown tool: ${toolName}`);
|
|
562
|
+
}
|
|
559
563
|
const ctx = {
|
|
560
564
|
headers: request.headers,
|
|
561
565
|
requestId: crypto.randomUUID(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useagents/redop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Bun-native MCP server framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepublishOnly": "bun run build && bun test"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"bun
|
|
39
|
+
"@types/bun": "latest",
|
|
40
40
|
"typescript": "^5.4.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {},
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { InferSchemaOutput, SchemaAdapter, StandardSchemaV1 } from "../types";
|
|
2
|
-
type JsonSchema = Record<string, unknown>;
|
|
3
|
-
export declare function standardSchemaAdapter<S extends StandardSchemaV1 = StandardSchemaV1>(): SchemaAdapter<S, InferSchemaOutput<S>>;
|
|
4
|
-
export declare function zodAdapter<S extends StandardSchemaV1 = StandardSchemaV1>(): SchemaAdapter<S, InferSchemaOutput<S>>;
|
|
5
|
-
export declare function jsonSchemaAdapter(): SchemaAdapter<JsonSchema, JsonSchema>;
|
|
6
|
-
export declare function detectAdapter(schema: unknown): SchemaAdapter;
|
|
7
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { detectAdapter, jsonSchemaAdapter, standardSchemaAdapter, zodAdapter, } from "./adapters/schema";
|
|
2
|
-
export { analytics, apiKey, bearer, cache, logger, rateLimit, } from "./plugins/index";
|
|
3
|
-
export { definePlugin, middleware, Redop } from "./redop";
|
|
4
|
-
export type { AfterHook, BeforeHook, Context, CorsOptions, ErrorHook, InferSchemaOutput, ListenOptions, MapResponseHook, PluginDefinition, PluginFactory, PluginMeta, RequestMeta, RedopOptions, ResolvedTool, SchemaAdapter, StandardSchemaIssue, StandardSchemaJsonOptions, StandardSchemaResultFailure, StandardSchemaResultSuccess, StandardSchemaV1, ToolHandler, ToolHandlerEvent, ToolMiddleware, ToolMiddlewareEvent, ToolNext, ToolRequest, ToolDef, ToolAfterHook, ToolAfterHookEvent, ToolBeforeHook, ToolBeforeHookEvent, TransformHook, TransportKind, } from "./types";
|
|
5
|
-
export { McpError, McpErrorCode } from "./types";
|
package/dist/plugins/index.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Redop } from "../redop";
|
|
2
|
-
import type { Context, ToolHandlerEvent } from "../types";
|
|
3
|
-
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
4
|
-
interface LoggerOptions {
|
|
5
|
-
/** Minimum log level to emit. Default: `"info"`. */
|
|
6
|
-
level?: LogLevel;
|
|
7
|
-
/** Custom write function. Defaults to console.log. */
|
|
8
|
-
write?: (entry: Record<string, unknown>) => void;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Log tool lifecycle events using a simple structured logger.
|
|
12
|
-
*
|
|
13
|
-
* Default: logs `info` and above with `console.log`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function logger(opts?: LoggerOptions): Redop;
|
|
16
|
-
type AnalyticsSink = "console" | "posthog" | ((event: AnalyticsEvent) => void | Promise<void>);
|
|
17
|
-
interface AnalyticsEvent {
|
|
18
|
-
durationMs: number;
|
|
19
|
-
requestId: string;
|
|
20
|
-
success: boolean;
|
|
21
|
-
tool: string;
|
|
22
|
-
}
|
|
23
|
-
interface AnalyticsOptions {
|
|
24
|
-
/** PostHog API key (required when sink = 'posthog') */
|
|
25
|
-
apiKey?: string;
|
|
26
|
-
/** Event sink. Default: `"console"`. */
|
|
27
|
-
sink?: AnalyticsSink;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Emit tool execution analytics to console, PostHog, or a custom sink.
|
|
31
|
-
*
|
|
32
|
-
* Default: writes analytics events to the console.
|
|
33
|
-
*/
|
|
34
|
-
export declare function analytics(opts?: AnalyticsOptions): Redop;
|
|
35
|
-
interface HeaderAuthOptions {
|
|
36
|
-
/** Context key to populate after successful validation. */
|
|
37
|
-
ctxKey?: string;
|
|
38
|
-
/** Header to read from. Defaults vary by helper. */
|
|
39
|
-
headerName?: string;
|
|
40
|
-
/** Whether the header must be present. Default true for HTTP transport. */
|
|
41
|
-
required?: boolean;
|
|
42
|
-
/** Static secret to validate against */
|
|
43
|
-
secret?: string;
|
|
44
|
-
/** Custom validate function — return true to allow */
|
|
45
|
-
validate?: (token: string, event: ToolHandlerEvent<unknown, Context>) => boolean | Promise<boolean>;
|
|
46
|
-
}
|
|
47
|
-
interface BearerOptions extends Omit<HeaderAuthOptions, "headerName"> {
|
|
48
|
-
/** Override the auth scheme prefix. Default: 'Bearer' */
|
|
49
|
-
scheme?: string;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Validate an API key header and store the value on `ctx`.
|
|
53
|
-
*
|
|
54
|
-
* Default header: `x-api-key`.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* app.use(
|
|
58
|
-
* apiKey({
|
|
59
|
-
* secret: process.env.API_SECRET,
|
|
60
|
-
* ctxKey: "apiKey",
|
|
61
|
-
* })
|
|
62
|
-
* );
|
|
63
|
-
*/
|
|
64
|
-
export declare function apiKey(opts?: HeaderAuthOptions): Redop;
|
|
65
|
-
/**
|
|
66
|
-
* Validate `Authorization` bearer tokens and store the parsed token on `ctx`.
|
|
67
|
-
*
|
|
68
|
-
* Default header: `authorization`.
|
|
69
|
-
* Default scheme: `"Bearer"`.
|
|
70
|
-
*/
|
|
71
|
-
export declare function bearer(opts?: BearerOptions): Redop;
|
|
72
|
-
interface RateLimitOptions {
|
|
73
|
-
/** Key to rate-limit on. Default: IP, session, then request ID fallback. */
|
|
74
|
-
keyBy?: (event: ToolHandlerEvent<unknown, Context>) => string;
|
|
75
|
-
/** Max calls per window. Default 60. */
|
|
76
|
-
max?: number;
|
|
77
|
-
/** Window duration as ms or string like '1m', '1h'. Default '1m'. */
|
|
78
|
-
window?: number | string;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Limit tool execution frequency in memory.
|
|
82
|
-
*
|
|
83
|
-
* Default: `60` calls per `"1m"` window.
|
|
84
|
-
*/
|
|
85
|
-
export declare function rateLimit(opts?: RateLimitOptions): Redop;
|
|
86
|
-
interface CacheOptions {
|
|
87
|
-
/** Tools to cache. Defaults to all. */
|
|
88
|
-
tools?: string[];
|
|
89
|
-
/** TTL in ms. Default 60_000 (1 min). */
|
|
90
|
-
ttl?: number;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Cache successful tool results in memory by tool name and parsed input.
|
|
94
|
-
*
|
|
95
|
-
* Default TTL: `60_000` ms.
|
|
96
|
-
*/
|
|
97
|
-
export declare function cache(opts?: CacheOptions): Redop;
|
|
98
|
-
export {};
|
package/dist/redop.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { AfterHook, BeforeHook, Context, ErrorHook, InferSchemaOutput, ListenOptions, MapResponseHook, RedopOptions, PluginDefinition, PluginFactory, ResolvedTool, ToolDef, ToolMiddleware, TransformHook } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Bun-native framework for building MCP servers with typed tools, hooks, and plugins.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const app = new Redop({
|
|
7
|
-
* name: "my-mcp-server",
|
|
8
|
-
* version: "0.1.0",
|
|
9
|
-
* });
|
|
10
|
-
*/
|
|
11
|
-
export declare class Redop<C extends Context = Context> {
|
|
12
|
-
private _hooks;
|
|
13
|
-
private _tools;
|
|
14
|
-
private _middlewares;
|
|
15
|
-
private _inputParsers;
|
|
16
|
-
private _schemaAdapter?;
|
|
17
|
-
private _serverInfo;
|
|
18
|
-
private _prefix;
|
|
19
|
-
/**
|
|
20
|
-
* Create a new redop app instance.
|
|
21
|
-
*/
|
|
22
|
-
constructor(options?: RedopOptions);
|
|
23
|
-
/**
|
|
24
|
-
* Register a hook that runs before middleware and the final tool handler.
|
|
25
|
-
*/
|
|
26
|
-
onBeforeHandle(hook: BeforeHook<C>): this;
|
|
27
|
-
/**
|
|
28
|
-
* Register a hook that runs after a tool returns successfully.
|
|
29
|
-
*/
|
|
30
|
-
onAfterHandle(hook: AfterHook<C>): this;
|
|
31
|
-
/**
|
|
32
|
-
* Register a hook that runs when middleware or a tool handler throws.
|
|
33
|
-
*/
|
|
34
|
-
onError(hook: ErrorHook<C>): this;
|
|
35
|
-
/**
|
|
36
|
-
* Register a hook that can mutate raw tool params before schema parsing.
|
|
37
|
-
*/
|
|
38
|
-
onTransform(hook: TransformHook<C>): this;
|
|
39
|
-
/**
|
|
40
|
-
* Register a hook that maps successful tool results before transport output.
|
|
41
|
-
*/
|
|
42
|
-
mapResponse(hook: MapResponseHook): this;
|
|
43
|
-
/**
|
|
44
|
-
* Register request-aware middleware around the tool handler pipeline.
|
|
45
|
-
*/
|
|
46
|
-
middleware<I = unknown>(mw: ToolMiddleware<I, unknown, C>): this;
|
|
47
|
-
/**
|
|
48
|
-
* Register a tool with optional schema validation and typed handler input.
|
|
49
|
-
* Tool-local `before` / `after` hooks are useful for per-tool analytics and post-processing.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* app.tool("search", {
|
|
53
|
-
* input: z.object({ query: z.string() }),
|
|
54
|
-
* handler: ({ input }) => search(input.query),
|
|
55
|
-
* });
|
|
56
|
-
*/
|
|
57
|
-
tool<S, I = InferSchemaOutput<S>, O = unknown>(name: string, def: ToolDef<S, I, C, O>): this;
|
|
58
|
-
/**
|
|
59
|
-
* Register multiple tools under a shared prefix.
|
|
60
|
-
*/
|
|
61
|
-
group(prefix: string, callback: (scoped: Redop<C>) => void): this;
|
|
62
|
-
/**
|
|
63
|
-
* Merge another Redop instance as a plugin into this app.
|
|
64
|
-
*/
|
|
65
|
-
use(plugin: Redop): this;
|
|
66
|
-
private _runTool;
|
|
67
|
-
/**
|
|
68
|
-
* Start serving the app over HTTP or stdio.
|
|
69
|
-
*/
|
|
70
|
-
listen(opts?: ListenOptions): this;
|
|
71
|
-
/**
|
|
72
|
-
* Registered tool names in their final exposed form.
|
|
73
|
-
*/
|
|
74
|
-
get toolNames(): string[];
|
|
75
|
-
/**
|
|
76
|
-
* MCP server identity advertised during initialize.
|
|
77
|
-
*/
|
|
78
|
-
get serverInfo(): {
|
|
79
|
-
name: string;
|
|
80
|
-
version: string;
|
|
81
|
-
};
|
|
82
|
-
getTool(name: string): ResolvedTool | undefined;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Wrap a middleware function in a reusable Redop plugin.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* app.use(
|
|
89
|
-
* middleware(async ({ request, next }) => {
|
|
90
|
-
* console.log(request.transport);
|
|
91
|
-
* return next();
|
|
92
|
-
* })
|
|
93
|
-
* );
|
|
94
|
-
*/
|
|
95
|
-
export declare function middleware<I = unknown, C extends Context = Context>(fn: ToolMiddleware<I, unknown, C>): Redop<C>;
|
|
96
|
-
/**
|
|
97
|
-
* Create a reusable plugin factory with attached metadata.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* const notesPlugin = definePlugin({
|
|
101
|
-
* name: "notes-plugin",
|
|
102
|
-
* version: "0.1.0",
|
|
103
|
-
* setup: ({ namespace = "notes" }) =>
|
|
104
|
-
* new Redop().group(namespace, (notes) => {
|
|
105
|
-
* notes.tool("list", { handler: () => [] });
|
|
106
|
-
* }),
|
|
107
|
-
* });
|
|
108
|
-
*/
|
|
109
|
-
export declare function definePlugin<Options, C extends Context = Context>(definition: PluginDefinition<Options, C>): PluginFactory<Options, C>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ListenOptions, RequestMeta, ResolvedTool, ServerInfoOptions } from "../types";
|
|
2
|
-
type ToolRunner = (toolName: string, args: Record<string, unknown>, requestMeta: RequestMeta) => Promise<unknown>;
|
|
3
|
-
export declare function startHttpTransport(tools: Map<string, ResolvedTool>, runner: ToolRunner, opts: ListenOptions, serverInfo: Required<ServerInfoOptions>): {
|
|
4
|
-
stop(): void;
|
|
5
|
-
broadcast(sessionId: string, event: string, data: unknown): void;
|
|
6
|
-
};
|
|
7
|
-
export {};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RequestMeta, ResolvedTool, ServerInfoOptions } from "../types";
|
|
2
|
-
type ToolRunner = (toolName: string, args: Record<string, unknown>, requestMeta: RequestMeta) => Promise<unknown>;
|
|
3
|
-
export declare function startStdioTransport(tools: Map<string, ResolvedTool>, runner: ToolRunner, serverInfo: Required<ServerInfoOptions>): void;
|
|
4
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
export interface JsonRpcRequest {
|
|
2
|
-
id: string | number | null;
|
|
3
|
-
jsonrpc: "2.0";
|
|
4
|
-
method: string;
|
|
5
|
-
params?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
export interface JsonRpcResponse {
|
|
8
|
-
error?: {
|
|
9
|
-
code: number;
|
|
10
|
-
message: string;
|
|
11
|
-
data?: unknown;
|
|
12
|
-
};
|
|
13
|
-
id: string | number | null;
|
|
14
|
-
jsonrpc: "2.0";
|
|
15
|
-
result?: unknown;
|
|
16
|
-
}
|
|
17
|
-
export interface McpToolCallParams {
|
|
18
|
-
arguments?: Record<string, unknown>;
|
|
19
|
-
name: string;
|
|
20
|
-
}
|
|
21
|
-
export interface McpContent {
|
|
22
|
-
data?: string;
|
|
23
|
-
mimeType?: string;
|
|
24
|
-
text?: string;
|
|
25
|
-
type: "text" | "image" | "resource";
|
|
26
|
-
}
|
|
27
|
-
export interface McpToolResult {
|
|
28
|
-
content: McpContent[];
|
|
29
|
-
isError?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export declare enum McpErrorCode {
|
|
32
|
-
ParseError = -32700,
|
|
33
|
-
InvalidRequest = -32600,
|
|
34
|
-
MethodNotFound = -32601,
|
|
35
|
-
InvalidParams = -32602,
|
|
36
|
-
InternalError = -32603,
|
|
37
|
-
ToolNotFound = -32000,
|
|
38
|
-
ValidationFailed = -32001,
|
|
39
|
-
Unauthorized = -32002,
|
|
40
|
-
RateLimited = -32003,
|
|
41
|
-
Timeout = -32004
|
|
42
|
-
}
|
|
43
|
-
export declare class McpError extends Error {
|
|
44
|
-
readonly code: McpErrorCode;
|
|
45
|
-
readonly data?: unknown | undefined;
|
|
46
|
-
constructor(code: McpErrorCode, message: string, data?: unknown | undefined);
|
|
47
|
-
}
|
|
48
|
-
export type TransportKind = "http" | "stdio" | "ws";
|
|
49
|
-
/**
|
|
50
|
-
* Normalized transport metadata for the current tool invocation.
|
|
51
|
-
*/
|
|
52
|
-
export interface ToolRequest {
|
|
53
|
-
/** Lowercased request headers. */
|
|
54
|
-
headers: Record<string, string>;
|
|
55
|
-
/** Client IP when the active transport can provide it. */
|
|
56
|
-
ip?: string;
|
|
57
|
-
/** HTTP method for HTTP transport requests. */
|
|
58
|
-
method?: string;
|
|
59
|
-
/** Raw HTTP Request object when transport = `http`. */
|
|
60
|
-
raw?: Request;
|
|
61
|
-
/** MCP session id for streamable HTTP sessions. */
|
|
62
|
-
sessionId?: string;
|
|
63
|
-
/** Active transport handling the request. */
|
|
64
|
-
transport: TransportKind;
|
|
65
|
-
/** Full request URL for HTTP transport requests. */
|
|
66
|
-
url?: string;
|
|
67
|
-
}
|
|
68
|
-
export type RequestMeta = ToolRequest;
|
|
69
|
-
/**
|
|
70
|
-
* Mutable bag threaded through every hook for a single request.
|
|
71
|
-
* Extend with your own fields via the generic parameter.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* type AppCtx = Context<{ userId: string; startedAt: number }>
|
|
75
|
-
*/
|
|
76
|
-
export type Context<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
77
|
-
/** Lowercased request headers mirrored from `request.headers`. */
|
|
78
|
-
headers: Record<string, string>;
|
|
79
|
-
/** Per-request unique id generated by redop. */
|
|
80
|
-
requestId: string;
|
|
81
|
-
/** MCP session id for streamable HTTP sessions. */
|
|
82
|
-
sessionId?: string;
|
|
83
|
-
/** Fully resolved tool name. */
|
|
84
|
-
tool: string;
|
|
85
|
-
/** Active transport handling the request. */
|
|
86
|
-
transport: TransportKind;
|
|
87
|
-
/** Raw tool arguments before schema parsing. */
|
|
88
|
-
rawParams: Record<string, unknown>;
|
|
89
|
-
} & T;
|
|
90
|
-
/**
|
|
91
|
-
* Event object passed to every tool handler.
|
|
92
|
-
*/
|
|
93
|
-
export interface ToolHandlerEvent<I = unknown, C extends Context = Context> {
|
|
94
|
-
/** Shared mutable per-request state. */
|
|
95
|
-
ctx: C;
|
|
96
|
-
/** Parsed tool input after schema validation/coercion. */
|
|
97
|
-
input: I;
|
|
98
|
-
/** Read-only transport metadata for the current invocation. */
|
|
99
|
-
request: ToolRequest;
|
|
100
|
-
/** Fully resolved tool name. */
|
|
101
|
-
tool: string;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Event object passed to a tool-local `before` hook.
|
|
105
|
-
*/
|
|
106
|
-
export interface ToolBeforeHookEvent<I = unknown, C extends Context = Context> {
|
|
107
|
-
/** Shared mutable per-request state. */
|
|
108
|
-
ctx: C;
|
|
109
|
-
/** Parsed tool input after schema validation/coercion. */
|
|
110
|
-
input: I;
|
|
111
|
-
/** Read-only transport metadata for the current invocation. */
|
|
112
|
-
request: ToolRequest;
|
|
113
|
-
/** Fully resolved tool name. */
|
|
114
|
-
tool: string;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Event object passed to a tool-local `after` hook.
|
|
118
|
-
*/
|
|
119
|
-
export interface ToolAfterHookEvent<I = unknown, R = unknown, C extends Context = Context> extends ToolBeforeHookEvent<I, C> {
|
|
120
|
-
/** Successful result returned by middleware/handler before global after hooks. */
|
|
121
|
-
result: R;
|
|
122
|
-
}
|
|
123
|
-
export type ToolHandler<I, O = unknown, C extends Context = Context> = (event: ToolHandlerEvent<I, C>) => O | Promise<O>;
|
|
124
|
-
export type ToolNext<R = unknown> = () => Promise<R>;
|
|
125
|
-
/**
|
|
126
|
-
* Event object passed to middleware.
|
|
127
|
-
*/
|
|
128
|
-
export interface ToolMiddlewareEvent<I = unknown, C extends Context = Context, R = unknown> extends ToolHandlerEvent<I, C> {
|
|
129
|
-
/** Continue to the next middleware or final handler. */
|
|
130
|
-
next: ToolNext<R>;
|
|
131
|
-
}
|
|
132
|
-
export type ToolMiddleware<I = unknown, R = unknown, C extends Context = Context> = (event: ToolMiddlewareEvent<I, C, R>) => R | Promise<R>;
|
|
133
|
-
export type ToolBeforeHook<I = unknown, C extends Context = Context> = (event: ToolBeforeHookEvent<I, C>) => void | Promise<void>;
|
|
134
|
-
export type ToolAfterHook<I = unknown, R = unknown, C extends Context = Context> = (event: ToolAfterHookEvent<I, R, C>) => void | Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Descriptive metadata for reusable plugins.
|
|
137
|
-
*/
|
|
138
|
-
export interface PluginMeta {
|
|
139
|
-
description?: string;
|
|
140
|
-
name: string;
|
|
141
|
-
version: string;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Definition object used by `definePlugin(...)`.
|
|
145
|
-
*/
|
|
146
|
-
export interface PluginDefinition<Options, C extends Context = Context> extends PluginMeta {
|
|
147
|
-
/** Create a plugin instance from a single options object. */
|
|
148
|
-
setup: (options: Options) => import("./redop").Redop<C>;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Callable plugin factory with attached metadata for docs and introspection.
|
|
152
|
-
*/
|
|
153
|
-
export interface PluginFactory<Options, C extends Context = Context> {
|
|
154
|
-
(options: Options): import("./redop").Redop<C>;
|
|
155
|
-
meta: PluginMeta;
|
|
156
|
-
}
|
|
157
|
-
export interface BeforeHookEvent<C extends Context = Context, I = unknown> {
|
|
158
|
-
ctx: C;
|
|
159
|
-
input: I;
|
|
160
|
-
params: I;
|
|
161
|
-
request: ToolRequest;
|
|
162
|
-
tool: string;
|
|
163
|
-
}
|
|
164
|
-
export interface AfterHookEvent<C extends Context = Context, R = unknown, I = unknown> {
|
|
165
|
-
ctx: C;
|
|
166
|
-
input: I;
|
|
167
|
-
params: I;
|
|
168
|
-
request: ToolRequest;
|
|
169
|
-
result: R;
|
|
170
|
-
tool: string;
|
|
171
|
-
}
|
|
172
|
-
export interface ErrorHookEvent<C extends Context = Context, I = unknown> {
|
|
173
|
-
ctx: C;
|
|
174
|
-
error: unknown;
|
|
175
|
-
input: I;
|
|
176
|
-
params: I;
|
|
177
|
-
request: ToolRequest;
|
|
178
|
-
tool: string;
|
|
179
|
-
}
|
|
180
|
-
export interface TransformHookEvent<C extends Context = Context> {
|
|
181
|
-
ctx: C;
|
|
182
|
-
params: Record<string, unknown>;
|
|
183
|
-
request: ToolRequest;
|
|
184
|
-
tool: string;
|
|
185
|
-
}
|
|
186
|
-
export type BeforeHook<C extends Context = Context> = (event: BeforeHookEvent<C>) => void | Promise<void>;
|
|
187
|
-
export type AfterHook<C extends Context = Context, R = unknown> = (event: AfterHookEvent<C, R>) => void | Promise<void>;
|
|
188
|
-
export type ErrorHook<C extends Context = Context> = (event: ErrorHookEvent<C>) => void | Promise<void>;
|
|
189
|
-
export type TransformHook<C extends Context = Context> = (event: TransformHookEvent<C>) => void | Record<string, unknown> | Promise<void | Record<string, unknown>>;
|
|
190
|
-
export type MapResponseHook<R = unknown> = (result: R, tool: string) => unknown | Promise<unknown>;
|
|
191
|
-
export interface StandardSchemaResultSuccess<Output> {
|
|
192
|
-
readonly issues?: undefined;
|
|
193
|
-
readonly value: Output;
|
|
194
|
-
}
|
|
195
|
-
export interface StandardSchemaIssue {
|
|
196
|
-
readonly message: string;
|
|
197
|
-
readonly path?: ReadonlyArray<PropertyKey | {
|
|
198
|
-
readonly key: PropertyKey;
|
|
199
|
-
}>;
|
|
200
|
-
}
|
|
201
|
-
export interface StandardSchemaResultFailure {
|
|
202
|
-
readonly issues: ReadonlyArray<StandardSchemaIssue>;
|
|
203
|
-
}
|
|
204
|
-
export interface StandardSchemaJsonOptions {
|
|
205
|
-
readonly libraryOptions?: Record<string, unknown>;
|
|
206
|
-
readonly target: string;
|
|
207
|
-
}
|
|
208
|
-
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
209
|
-
readonly "~standard": {
|
|
210
|
-
readonly jsonSchema?: {
|
|
211
|
-
readonly input: (options: StandardSchemaJsonOptions) => Record<string, unknown>;
|
|
212
|
-
readonly output: (options: StandardSchemaJsonOptions) => Record<string, unknown>;
|
|
213
|
-
};
|
|
214
|
-
readonly validate: (value: unknown, options?: {
|
|
215
|
-
readonly libraryOptions?: Record<string, unknown>;
|
|
216
|
-
}) => StandardSchemaResultSuccess<Output> | StandardSchemaResultFailure | Promise<StandardSchemaResultSuccess<Output> | StandardSchemaResultFailure>;
|
|
217
|
-
readonly types?: {
|
|
218
|
-
readonly input: Input;
|
|
219
|
-
readonly output: Output;
|
|
220
|
-
};
|
|
221
|
-
readonly vendor: string;
|
|
222
|
-
readonly version: 1;
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
export type InferSchemaOutput<S> = S extends StandardSchemaV1<any, infer Output> ? Output : S extends Record<string, unknown> ? Record<string, unknown> : unknown;
|
|
226
|
-
/**
|
|
227
|
-
* Implement this interface to plug any schema library into redop.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* const zodAdapter: SchemaAdapter<ZodTypeAny> = {
|
|
231
|
-
* toJsonSchema: (s) => zodToJsonSchema(s),
|
|
232
|
-
* parse: (s, input) => s.parse(input),
|
|
233
|
-
* }
|
|
234
|
-
*/
|
|
235
|
-
export interface SchemaAdapter<S = unknown, Parsed = InferSchemaOutput<S>> {
|
|
236
|
-
/** Runtime parse + coerce. Throw on failure. */
|
|
237
|
-
parse(schema: S, input: unknown): Parsed | Promise<Parsed>;
|
|
238
|
-
/** Convert schema to JSON Schema for MCP tool descriptions */
|
|
239
|
-
toJsonSchema(schema: S): Record<string, unknown>;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Definition object for a single MCP tool.
|
|
243
|
-
*/
|
|
244
|
-
export interface ToolDef<S = unknown, I = InferSchemaOutput<S>, C extends Context = Context, O = unknown> {
|
|
245
|
-
/** MCP tool annotations surfaced to compatible clients. */
|
|
246
|
-
annotations?: {
|
|
247
|
-
title?: string;
|
|
248
|
-
readOnlyHint?: boolean;
|
|
249
|
-
destructiveHint?: boolean;
|
|
250
|
-
idempotentHint?: boolean;
|
|
251
|
-
openWorldHint?: boolean;
|
|
252
|
-
};
|
|
253
|
-
/** Tool-local hook that runs after global before hooks and before middleware. */
|
|
254
|
-
before?: ToolBeforeHook<I, C>;
|
|
255
|
-
/** Human-friendly tool description shown in tool listings. */
|
|
256
|
-
description?: string;
|
|
257
|
-
/** Tool-local hook that runs after middleware/handler success and before global after hooks. */
|
|
258
|
-
after?: ToolAfterHook<I, O, C>;
|
|
259
|
-
/** Tool handler receiving parsed input, shared context, and request metadata. */
|
|
260
|
-
handler: ToolHandler<I, O, C>;
|
|
261
|
-
/** Schema instance (Zod, TypeBox, etc.) or plain JSON Schema object */
|
|
262
|
-
input?: S;
|
|
263
|
-
}
|
|
264
|
-
export interface ResolvedTool {
|
|
265
|
-
after?: ToolAfterHook<unknown, unknown>;
|
|
266
|
-
annotations?: Record<string, unknown>;
|
|
267
|
-
before?: ToolBeforeHook<unknown>;
|
|
268
|
-
description?: string;
|
|
269
|
-
handler: ToolHandler<unknown>;
|
|
270
|
-
inputSchema: Record<string, unknown>;
|
|
271
|
-
name: string;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* CORS configuration for the HTTP transport.
|
|
275
|
-
*/
|
|
276
|
-
export interface CorsOptions {
|
|
277
|
-
/** Whether browsers may send credentials. Default: `true`. */
|
|
278
|
-
credentials?: boolean;
|
|
279
|
-
/** Allowed request headers. Default includes content type, auth, API key, and session id headers. */
|
|
280
|
-
headers?: string[];
|
|
281
|
-
/** Allowed HTTP methods. Default: `GET, POST, DELETE, OPTIONS`. */
|
|
282
|
-
methods?: string[];
|
|
283
|
-
/** Allowed origins. Default: `"*"`. */
|
|
284
|
-
origins?: string | string[];
|
|
285
|
-
}
|
|
286
|
-
export type TlsOptions = import("bun").TLSOptions;
|
|
287
|
-
export interface ServerInfoOptions {
|
|
288
|
-
name?: string;
|
|
289
|
-
version?: string;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Constructor options for `new Redop(...)`.
|
|
293
|
-
*/
|
|
294
|
-
export interface RedopOptions {
|
|
295
|
-
/** MCP server identity advertised during initialize. Default: `"redop"`. */
|
|
296
|
-
name?: string;
|
|
297
|
-
/** Custom schema adapter. By default, redop auto-detects supported schemas. */
|
|
298
|
-
schemaAdapter?: SchemaAdapter;
|
|
299
|
-
/** MCP server version advertised during initialize. Default: `"0.1.0"`. */
|
|
300
|
-
version?: string;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Runtime options for `app.listen(...)`.
|
|
304
|
-
*/
|
|
305
|
-
export interface ListenOptions {
|
|
306
|
-
/** CORS — true = permissive dev mode. */
|
|
307
|
-
cors?: boolean | CorsOptions;
|
|
308
|
-
/** Bind address. "0.0.0.0" for all interfaces. */
|
|
309
|
-
hostname?: string;
|
|
310
|
-
/** Max request body in bytes. Default 4MB. */
|
|
311
|
-
maxBodySize?: number;
|
|
312
|
-
/** Fires once the server is bound. */
|
|
313
|
-
onListen?: (info: {
|
|
314
|
-
hostname: string;
|
|
315
|
-
port: number;
|
|
316
|
-
url: string;
|
|
317
|
-
}) => void;
|
|
318
|
-
/** MCP mount path. Defaults to "/mcp". */
|
|
319
|
-
path?: string;
|
|
320
|
-
/** TCP port (HTTP / WS only). Defaults to 3000. */
|
|
321
|
-
port?: number | string;
|
|
322
|
-
/** Idle session TTL in ms. Default 30_000. */
|
|
323
|
-
sessionTimeout?: number;
|
|
324
|
-
/** Bun TLS config */
|
|
325
|
-
tls?: TlsOptions;
|
|
326
|
-
/** Transport protocol. Auto-detects if omitted. */
|
|
327
|
-
transport?: TransportKind;
|
|
328
|
-
}
|