@phake/mcp 0.0.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +187 -0
  3. package/dist/adapters/http-node/http/app.d.ts +5 -0
  4. package/dist/adapters/http-node/http/auth-app.d.ts +5 -0
  5. package/dist/adapters/http-node/http/middlewares/auth.d.ts +39 -0
  6. package/dist/adapters/http-node/http/middlewares/cors.d.ts +8 -0
  7. package/dist/adapters/http-node/http/routes/health.d.ts +5 -0
  8. package/dist/adapters/http-node/http/routes/mcp.d.ts +11 -0
  9. package/dist/adapters/http-node/middleware.security.d.ts +6 -0
  10. package/dist/adapters/http-node/routes.discovery.d.ts +6 -0
  11. package/dist/adapters/http-node/routes.oauth.d.ts +7 -0
  12. package/dist/adapters/http-worker/index.d.ts +48 -0
  13. package/dist/adapters/http-worker/mcp.handler.d.ts +24 -0
  14. package/dist/adapters/http-worker/routes.discovery.d.ts +7 -0
  15. package/dist/adapters/http-worker/routes.oauth.d.ts +8 -0
  16. package/dist/adapters/http-worker/security.d.ts +7 -0
  17. package/dist/index-1zyem3xr.js +14893 -0
  18. package/dist/index-4f4xvtt9.js +19552 -0
  19. package/dist/index-sbqy8kgq.js +3478 -0
  20. package/dist/index.d.ts +27 -0
  21. package/dist/index.js +1083 -0
  22. package/dist/mcp-server.d.ts +18 -0
  23. package/dist/runtime/node/capabilities.d.ts +2 -0
  24. package/dist/runtime/node/context.d.ts +29 -0
  25. package/dist/runtime/node/index.d.ts +5 -0
  26. package/dist/runtime/node/index.js +27 -0
  27. package/dist/runtime/node/mcp.d.ts +28 -0
  28. package/dist/runtime/node/storage/file.d.ts +44 -0
  29. package/dist/runtime/node/storage/sqlite.d.ts +213 -0
  30. package/dist/runtime/worker/index.d.ts +1 -0
  31. package/dist/runtime/worker/index.js +12 -0
  32. package/dist/shared/auth/index.d.ts +1 -0
  33. package/dist/shared/auth/strategy.d.ts +71 -0
  34. package/dist/shared/config/env.d.ts +52 -0
  35. package/dist/shared/config/index.d.ts +2 -0
  36. package/dist/shared/config/metadata.d.ts +5 -0
  37. package/dist/shared/crypto/aes-gcm.d.ts +37 -0
  38. package/dist/shared/crypto/index.d.ts +1 -0
  39. package/dist/shared/http/cors.d.ts +20 -0
  40. package/dist/shared/http/index.d.ts +2 -0
  41. package/dist/shared/http/response.d.ts +52 -0
  42. package/dist/shared/mcp/dispatcher.d.ts +81 -0
  43. package/dist/shared/mcp/index.d.ts +3 -0
  44. package/dist/shared/mcp/security.d.ts +23 -0
  45. package/dist/shared/mcp/server-internals.d.ts +79 -0
  46. package/dist/shared/oauth/cimd.d.ts +43 -0
  47. package/dist/shared/oauth/discovery-handlers.d.ts +14 -0
  48. package/dist/shared/oauth/discovery.d.ts +26 -0
  49. package/dist/shared/oauth/endpoints.d.ts +11 -0
  50. package/dist/shared/oauth/flow.d.ts +31 -0
  51. package/dist/shared/oauth/index.d.ts +9 -0
  52. package/dist/shared/oauth/input-parsers.d.ts +43 -0
  53. package/dist/shared/oauth/refresh.d.ts +61 -0
  54. package/dist/shared/oauth/ssrf.d.ts +31 -0
  55. package/dist/shared/oauth/types.d.ts +78 -0
  56. package/dist/shared/schemas/prompts.d.ts +1 -0
  57. package/dist/shared/services/http-client.d.ts +16 -0
  58. package/dist/shared/services/index.d.ts +1 -0
  59. package/dist/shared/storage/index.d.ts +4 -0
  60. package/dist/shared/storage/interface.d.ts +99 -0
  61. package/dist/shared/storage/kv.d.ts +68 -0
  62. package/dist/shared/storage/memory.d.ts +91 -0
  63. package/dist/shared/storage/singleton.d.ts +4 -0
  64. package/dist/shared/tools/echo.d.ts +16 -0
  65. package/dist/shared/tools/health.d.ts +13 -0
  66. package/dist/shared/tools/index.d.ts +4 -0
  67. package/dist/shared/tools/registry.d.ts +64 -0
  68. package/dist/shared/tools/types.d.ts +161 -0
  69. package/dist/shared/types/auth.d.ts +35 -0
  70. package/dist/shared/types/context.d.ts +79 -0
  71. package/dist/shared/types/index.d.ts +8 -0
  72. package/dist/shared/types/provider.d.ts +28 -0
  73. package/dist/shared/utils/base64.d.ts +12 -0
  74. package/dist/shared/utils/cancellation.d.ts +13 -0
  75. package/dist/shared/utils/elicitation.d.ts +247 -0
  76. package/dist/shared/utils/formatting.d.ts +106 -0
  77. package/dist/shared/utils/index.d.ts +11 -0
  78. package/dist/shared/utils/limits.d.ts +6 -0
  79. package/dist/shared/utils/logger.d.ts +20 -0
  80. package/dist/shared/utils/pagination.d.ts +11 -0
  81. package/dist/shared/utils/progress.d.ts +56 -0
  82. package/dist/shared/utils/roots.d.ts +62 -0
  83. package/dist/shared/utils/sampling.d.ts +155 -0
  84. package/dist/shared/utils/security.d.ts +6 -0
  85. package/package.json +55 -0
@@ -0,0 +1,18 @@
1
+ /**
2
+ * MCP Server factory.
3
+ * Creates a configured server for different runtimes.
4
+ */
5
+ import type { SharedToolDefinition } from "./shared/tools/types.js";
6
+ export interface MCPServerOptions {
7
+ /** Runtime adapter: 'worker' (Cloudflare Workers) or 'node' (Hono/Node.js) */
8
+ adapter: "worker" | "node";
9
+ /** Array of tools to register */
10
+ tools?: SharedToolDefinition<any>[];
11
+ }
12
+ export interface MCPServer {
13
+ fetch: (request: Request, env: unknown) => Promise<Response>;
14
+ }
15
+ /**
16
+ * Create an MCP server instance.
17
+ */
18
+ export declare function createMCPServer(options: MCPServerOptions): MCPServer;
@@ -0,0 +1,2 @@
1
+ import type { ServerCapabilities } from "@modelcontextprotocol/sdk/types.js";
2
+ export declare function buildCapabilities(): ServerCapabilities;
@@ -0,0 +1,29 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import type { RequestContext } from "../../shared/types/context.js";
3
+ import type { CancellationToken } from "../../shared/utils/cancellation.js";
4
+ export declare const authContextStorage: AsyncLocalStorage<RequestContext>;
5
+ export declare function getCurrentAuthContext(): RequestContext | undefined;
6
+ declare class ContextRegistry {
7
+ private contexts;
8
+ create(requestId: string | number, sessionId?: string, authData?: {
9
+ authStrategy?: RequestContext["authStrategy"];
10
+ authHeaders?: RequestContext["authHeaders"];
11
+ resolvedHeaders?: RequestContext["resolvedHeaders"];
12
+ rsToken?: string;
13
+ providerToken?: string;
14
+ provider?: RequestContext["provider"];
15
+ serviceToken?: string;
16
+ }): RequestContext;
17
+ get(requestId: string | number): RequestContext | undefined;
18
+ getCancellationToken(requestId: string | number): CancellationToken | undefined;
19
+ cancel(requestId: string | number, _reason?: string): boolean;
20
+ delete(requestId: string | number): boolean;
21
+ deleteBySession(sessionId: string): number;
22
+ get size(): number;
23
+ cleanupExpired(maxAgeMs?: number): number;
24
+ clear(): void;
25
+ }
26
+ export declare const contextRegistry: ContextRegistry;
27
+ export declare function startContextCleanup(intervalMs?: number, maxAgeMs?: number): void;
28
+ export declare function stopContextCleanup(): void;
29
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from "./capabilities.js";
2
+ export * from "./context.js";
3
+ export * from "./mcp.js";
4
+ export * from "./storage/file.js";
5
+ export * from "./storage/sqlite.js";
@@ -0,0 +1,27 @@
1
+ // @bun
2
+ import {
3
+ FileTokenStore,
4
+ SqliteSessionStore,
5
+ buildServer,
6
+ sessions
7
+ } from "../../index-1zyem3xr.js";
8
+ import {
9
+ authContextStorage,
10
+ buildCapabilities,
11
+ contextRegistry,
12
+ getCurrentAuthContext,
13
+ startContextCleanup,
14
+ stopContextCleanup
15
+ } from "../../index-4f4xvtt9.js";
16
+ export {
17
+ stopContextCleanup,
18
+ startContextCleanup,
19
+ sessions,
20
+ getCurrentAuthContext,
21
+ contextRegistry,
22
+ buildServer,
23
+ buildCapabilities,
24
+ authContextStorage,
25
+ SqliteSessionStore,
26
+ FileTokenStore
27
+ };
@@ -0,0 +1,28 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { type ContextResolver } from "../../shared/tools/registry.js";
3
+ export interface ServerOptions {
4
+ name: string;
5
+ version: string;
6
+ instructions?: string;
7
+ /** Instructions fallback if not provided */
8
+ defaultInstructions?: string;
9
+ /**
10
+ * Called when initialization is complete (after client sends notifications/initialized).
11
+ * Per review finding #3: This fires AFTER transport.onsessioninitialized.
12
+ *
13
+ * Guaranteed ordering:
14
+ * 1. transport.onsessioninitialized(sid) - session ID assigned
15
+ * 2. server.oninitialized() - client confirmed ready
16
+ *
17
+ * At this point, you can safely:
18
+ * - Access client capabilities via server.server.getClientCapabilities()
19
+ * - Send server→client requests (sampling, elicitation, roots)
20
+ */
21
+ oninitialized?: () => void;
22
+ /**
23
+ * Optional resolver to look up auth context by requestId.
24
+ * Required for tools to receive authentication data.
25
+ */
26
+ contextResolver?: ContextResolver;
27
+ }
28
+ export declare function buildServer(options: ServerOptions): McpServer;
@@ -0,0 +1,44 @@
1
+ import type { ProviderTokens, RsRecord, TokenStore, Transaction } from "../../../shared/storage/interface.js";
2
+ export declare class FileTokenStore implements TokenStore {
3
+ private memory;
4
+ private persistPath;
5
+ private encryptor;
6
+ private saveDebounceTimer;
7
+ private pendingSave;
8
+ /**
9
+ * Create a file-backed token store.
10
+ *
11
+ * @param persistPath - Path to the JSON file for persistence
12
+ * @param encryptionKey - Base64url-encoded 32-byte key for AES-256-GCM encryption
13
+ */
14
+ constructor(persistPath?: string, encryptionKey?: string);
15
+ private loadAsync;
16
+ private scheduleSave;
17
+ private saveAsync;
18
+ storeRsMapping(rsAccess: string, provider: ProviderTokens, rsRefresh?: string): Promise<RsRecord>;
19
+ getByRsAccess(rsAccess: string): Promise<RsRecord | null>;
20
+ getByRsRefresh(rsRefresh: string): Promise<RsRecord | null>;
21
+ updateByRsRefresh(rsRefresh: string, provider: ProviderTokens, maybeNewRsAccess?: string): Promise<RsRecord | null>;
22
+ saveTransaction(txnId: string, txn: Transaction, ttlSeconds?: number): Promise<void>;
23
+ getTransaction(txnId: string): Promise<Transaction | null>;
24
+ deleteTransaction(txnId: string): Promise<void>;
25
+ saveCode(code: string, txnId: string, ttlSeconds?: number): Promise<void>;
26
+ getTxnIdByCode(code: string): Promise<string | null>;
27
+ deleteCode(code: string): Promise<void>;
28
+ /**
29
+ * Force immediate save (useful before shutdown).
30
+ */
31
+ flush(): Promise<void>;
32
+ /**
33
+ * Stop cleanup intervals.
34
+ */
35
+ stopCleanup(): void;
36
+ /**
37
+ * Get store statistics.
38
+ */
39
+ getStats(): {
40
+ rsTokens: number;
41
+ transactions: number;
42
+ codes: number;
43
+ };
44
+ }
@@ -0,0 +1,213 @@
1
+ import type { SessionRecord, SessionStore } from "../../../shared/storage/interface.js";
2
+ export declare const sessions: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3
+ name: "sessions";
4
+ schema: undefined;
5
+ columns: {
6
+ sessionId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7
+ name: "session_id";
8
+ tableName: "sessions";
9
+ dataType: "string";
10
+ columnType: "SQLiteText";
11
+ data: string;
12
+ driverParam: string;
13
+ notNull: true;
14
+ hasDefault: false;
15
+ isPrimaryKey: true;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: false;
18
+ enumValues: [string, ...string[]];
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}, {
23
+ length: number | undefined;
24
+ }>;
25
+ apiKey: import("drizzle-orm/sqlite-core").SQLiteColumn<{
26
+ name: "api_key";
27
+ tableName: "sessions";
28
+ dataType: "string";
29
+ columnType: "SQLiteText";
30
+ data: string;
31
+ driverParam: string;
32
+ notNull: false;
33
+ hasDefault: false;
34
+ isPrimaryKey: false;
35
+ isAutoincrement: false;
36
+ hasRuntimeDefault: false;
37
+ enumValues: [string, ...string[]];
38
+ baseColumn: never;
39
+ identity: undefined;
40
+ generated: undefined;
41
+ }, {}, {
42
+ length: number | undefined;
43
+ }>;
44
+ rsAccessToken: import("drizzle-orm/sqlite-core").SQLiteColumn<{
45
+ name: "rs_access_token";
46
+ tableName: "sessions";
47
+ dataType: "string";
48
+ columnType: "SQLiteText";
49
+ data: string;
50
+ driverParam: string;
51
+ notNull: false;
52
+ hasDefault: false;
53
+ isPrimaryKey: false;
54
+ isAutoincrement: false;
55
+ hasRuntimeDefault: false;
56
+ enumValues: [string, ...string[]];
57
+ baseColumn: never;
58
+ identity: undefined;
59
+ generated: undefined;
60
+ }, {}, {
61
+ length: number | undefined;
62
+ }>;
63
+ rsRefreshToken: import("drizzle-orm/sqlite-core").SQLiteColumn<{
64
+ name: "rs_refresh_token";
65
+ tableName: "sessions";
66
+ dataType: "string";
67
+ columnType: "SQLiteText";
68
+ data: string;
69
+ driverParam: string;
70
+ notNull: false;
71
+ hasDefault: false;
72
+ isPrimaryKey: false;
73
+ isAutoincrement: false;
74
+ hasRuntimeDefault: false;
75
+ enumValues: [string, ...string[]];
76
+ baseColumn: never;
77
+ identity: undefined;
78
+ generated: undefined;
79
+ }, {}, {
80
+ length: number | undefined;
81
+ }>;
82
+ providerJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
83
+ name: "provider_json";
84
+ tableName: "sessions";
85
+ dataType: "string";
86
+ columnType: "SQLiteText";
87
+ data: string;
88
+ driverParam: string;
89
+ notNull: false;
90
+ hasDefault: false;
91
+ isPrimaryKey: false;
92
+ isAutoincrement: false;
93
+ hasRuntimeDefault: false;
94
+ enumValues: [string, ...string[]];
95
+ baseColumn: never;
96
+ identity: undefined;
97
+ generated: undefined;
98
+ }, {}, {
99
+ length: number | undefined;
100
+ }>;
101
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
102
+ name: "created_at";
103
+ tableName: "sessions";
104
+ dataType: "number";
105
+ columnType: "SQLiteInteger";
106
+ data: number;
107
+ driverParam: number;
108
+ notNull: true;
109
+ hasDefault: false;
110
+ isPrimaryKey: false;
111
+ isAutoincrement: false;
112
+ hasRuntimeDefault: false;
113
+ enumValues: undefined;
114
+ baseColumn: never;
115
+ identity: undefined;
116
+ generated: undefined;
117
+ }, {}, {}>;
118
+ lastAccessed: import("drizzle-orm/sqlite-core").SQLiteColumn<{
119
+ name: "last_accessed";
120
+ tableName: "sessions";
121
+ dataType: "number";
122
+ columnType: "SQLiteInteger";
123
+ data: number;
124
+ driverParam: number;
125
+ notNull: true;
126
+ hasDefault: false;
127
+ isPrimaryKey: false;
128
+ isAutoincrement: false;
129
+ hasRuntimeDefault: false;
130
+ enumValues: undefined;
131
+ baseColumn: never;
132
+ identity: undefined;
133
+ generated: undefined;
134
+ }, {}, {}>;
135
+ initialized: import("drizzle-orm/sqlite-core").SQLiteColumn<{
136
+ name: "initialized";
137
+ tableName: "sessions";
138
+ dataType: "number";
139
+ columnType: "SQLiteInteger";
140
+ data: number;
141
+ driverParam: number;
142
+ notNull: false;
143
+ hasDefault: true;
144
+ isPrimaryKey: false;
145
+ isAutoincrement: false;
146
+ hasRuntimeDefault: false;
147
+ enumValues: undefined;
148
+ baseColumn: never;
149
+ identity: undefined;
150
+ generated: undefined;
151
+ }, {}, {}>;
152
+ protocolVersion: import("drizzle-orm/sqlite-core").SQLiteColumn<{
153
+ name: "protocol_version";
154
+ tableName: "sessions";
155
+ dataType: "string";
156
+ columnType: "SQLiteText";
157
+ data: string;
158
+ driverParam: string;
159
+ notNull: false;
160
+ hasDefault: false;
161
+ isPrimaryKey: false;
162
+ isAutoincrement: false;
163
+ hasRuntimeDefault: false;
164
+ enumValues: [string, ...string[]];
165
+ baseColumn: never;
166
+ identity: undefined;
167
+ generated: undefined;
168
+ }, {}, {
169
+ length: number | undefined;
170
+ }>;
171
+ };
172
+ dialect: "sqlite";
173
+ }>;
174
+ export type SessionRow = typeof sessions.$inferSelect;
175
+ /**
176
+ * SQLite-based session store using Drizzle ORM.
177
+ * Provides persistent session storage with multi-tenant support.
178
+ */
179
+ export declare class SqliteSessionStore implements SessionStore {
180
+ private db;
181
+ private sqlite;
182
+ private createSessionTxn;
183
+ constructor(dbPath?: string);
184
+ private initSchema;
185
+ create(sessionId: string, apiKey: string): Promise<SessionRecord>;
186
+ get(sessionId: string): Promise<SessionRecord | null>;
187
+ update(sessionId: string, data: Partial<SessionRecord>): Promise<void>;
188
+ delete(sessionId: string): Promise<void>;
189
+ getByApiKey(apiKey: string): Promise<SessionRecord[]>;
190
+ countByApiKey(apiKey: string): Promise<number>;
191
+ deleteOldestByApiKey(apiKey: string): Promise<void>;
192
+ ensure(sessionId: string): Promise<void>;
193
+ put(sessionId: string, value: SessionRecord): Promise<void>;
194
+ /**
195
+ * Close the database connection.
196
+ * Call this on graceful shutdown.
197
+ */
198
+ close(): void;
199
+ /**
200
+ * Clean up expired sessions (older than TTL).
201
+ * Call periodically or on startup.
202
+ *
203
+ * @param ttlMs - Time-to-live in milliseconds (default: 24 hours)
204
+ * @returns Number of deleted sessions
205
+ */
206
+ cleanup(ttlMs?: number): Promise<number>;
207
+ /**
208
+ * Get store statistics for monitoring/debugging.
209
+ */
210
+ getStats(): Promise<{
211
+ sessions: number;
212
+ }>;
213
+ }
@@ -0,0 +1 @@
1
+ export * from "../../adapters/http-worker/index.js";
@@ -0,0 +1,12 @@
1
+ // @bun
2
+ import {
3
+ createWorkerRouter,
4
+ initializeWorkerStorage,
5
+ shimProcessEnv
6
+ } from "../../index-sbqy8kgq.js";
7
+ import"../../index-4f4xvtt9.js";
8
+ export {
9
+ shimProcessEnv,
10
+ initializeWorkerStorage,
11
+ createWorkerRouter
12
+ };
@@ -0,0 +1 @@
1
+ export * from "./strategy.js";
@@ -0,0 +1,71 @@
1
+ import type { AuthStrategy } from "../types/auth.js";
2
+ export type { AuthStrategy as AuthStrategyType } from "../types/auth.js";
3
+ /**
4
+ * Resolved auth headers to inject into tool context.
5
+ */
6
+ export interface ResolvedAuth {
7
+ /** Auth strategy used */
8
+ strategy: AuthStrategy;
9
+ /** Headers to pass to API calls */
10
+ headers: Record<string, string>;
11
+ /** Raw access token (if bearer/oauth) */
12
+ accessToken?: string;
13
+ /** Provider tokens (oauth only) */
14
+ provider?: {
15
+ accessToken: string;
16
+ refreshToken?: string;
17
+ expiresAt?: number;
18
+ };
19
+ }
20
+ /**
21
+ * Strategy configuration parsed from env.
22
+ */
23
+ export interface AuthStrategyConfig {
24
+ type: AuthStrategy;
25
+ /** For api_key: header name (default: x-api-key) */
26
+ headerName?: string;
27
+ /** For api_key/bearer: the token/key value */
28
+ value?: string;
29
+ /** For custom: map of header name → value */
30
+ customHeaders?: Record<string, string>;
31
+ }
32
+ /**
33
+ * Parse auth strategy from config.
34
+ *
35
+ * Reads from:
36
+ * - AUTH_STRATEGY: 'oauth' | 'bearer' | 'api_key' | 'custom' | 'none'
37
+ * - API_KEY: The API key value (for api_key strategy)
38
+ * - API_KEY_HEADER: Header name (default: x-api-key)
39
+ * - BEARER_TOKEN: Static bearer token (for bearer strategy)
40
+ * - CUSTOM_HEADERS: "Header1:value1,Header2:value2" format
41
+ */
42
+ export declare function parseAuthStrategy(env: Record<string, unknown>): AuthStrategyConfig;
43
+ /**
44
+ * Build auth headers from strategy config.
45
+ * Used for non-OAuth strategies where headers are static.
46
+ */
47
+ export declare function buildAuthHeaders(strategyConfig: AuthStrategyConfig): Record<string, string>;
48
+ /**
49
+ * Resolve auth for a request.
50
+ *
51
+ * For OAuth: requires incoming RS token to be mapped
52
+ * For other strategies: uses static config values
53
+ */
54
+ export declare function resolveStaticAuth(strategyConfig: AuthStrategyConfig): ResolvedAuth;
55
+ /**
56
+ * Merge incoming request headers with strategy headers.
57
+ * Strategy headers take precedence (they're the "real" auth).
58
+ */
59
+ export declare function mergeAuthHeaders(incoming: Record<string, string>, strategy: Record<string, string>): Record<string, string>;
60
+ /**
61
+ * Check if auth strategy requires OAuth flow.
62
+ */
63
+ export declare function isOAuthStrategy(config: AuthStrategyConfig): boolean;
64
+ /**
65
+ * Check if auth strategy requires any authentication.
66
+ */
67
+ export declare function requiresAuth(config: AuthStrategyConfig): boolean;
68
+ /**
69
+ * Validate that required config values are present for the strategy.
70
+ */
71
+ export declare function validateAuthConfig(config: AuthStrategyConfig): string[];
@@ -0,0 +1,52 @@
1
+ import type { AuthStrategyType } from "../auth/strategy.js";
2
+ export type UnifiedConfig = {
3
+ HOST: string;
4
+ PORT: number;
5
+ NODE_ENV: "development" | "production" | "test";
6
+ MCP_TITLE: string;
7
+ MCP_INSTRUCTIONS: string;
8
+ MCP_VERSION: string;
9
+ MCP_PROTOCOL_VERSION: string;
10
+ MCP_ACCEPT_HEADERS: string[];
11
+ AUTH_STRATEGY: AuthStrategyType;
12
+ AUTH_ENABLED: boolean;
13
+ AUTH_REQUIRE_RS: boolean;
14
+ AUTH_ALLOW_DIRECT_BEARER: boolean;
15
+ AUTH_RESOURCE_URI?: string;
16
+ AUTH_DISCOVERY_URL?: string;
17
+ API_KEY?: string;
18
+ API_KEY_HEADER: string;
19
+ BEARER_TOKEN?: string;
20
+ CUSTOM_HEADERS?: string;
21
+ OAUTH_CLIENT_ID?: string;
22
+ OAUTH_CLIENT_SECRET?: string;
23
+ OAUTH_SCOPES: string;
24
+ OAUTH_AUTHORIZATION_URL?: string;
25
+ OAUTH_TOKEN_URL?: string;
26
+ OAUTH_REVOCATION_URL?: string;
27
+ OAUTH_REDIRECT_URI: string;
28
+ OAUTH_REDIRECT_ALLOWLIST: string[];
29
+ OAUTH_REDIRECT_ALLOW_ALL: boolean;
30
+ OAUTH_EXTRA_AUTH_PARAMS?: string;
31
+ CIMD_ENABLED: boolean;
32
+ CIMD_FETCH_TIMEOUT_MS: number;
33
+ CIMD_MAX_RESPONSE_BYTES: number;
34
+ /** Comma-separated list of allowed domains for CIMD client_ids */
35
+ CIMD_ALLOWED_DOMAINS: string[];
36
+ PROVIDER_CLIENT_ID?: string;
37
+ PROVIDER_CLIENT_SECRET?: string;
38
+ PROVIDER_API_URL?: string;
39
+ PROVIDER_ACCOUNTS_URL?: string;
40
+ BASE_URL?: string;
41
+ RS_TOKENS_FILE?: string;
42
+ /** Base64url-encoded 32-byte key for encrypting tokens at rest */
43
+ RS_TOKENS_ENC_KEY?: string;
44
+ RPS_LIMIT: number;
45
+ CONCURRENCY_LIMIT: number;
46
+ LOG_LEVEL: "debug" | "info" | "warning" | "error";
47
+ };
48
+ /**
49
+ * Parse environment variables into a unified config object
50
+ * Works for both process.env (Node.js) and Workers env bindings
51
+ */
52
+ export declare function parseConfig(env: Record<string, unknown>): UnifiedConfig;
@@ -0,0 +1,2 @@
1
+ export type { UnifiedConfig } from "./env.js";
2
+ export * from "./env.js";
@@ -0,0 +1,5 @@
1
+ export declare const serverMetadata: {
2
+ title: string;
3
+ version: string;
4
+ instructions: string;
5
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * AES-256-GCM encryption/decryption using Web Crypto API.
3
+ * Works in both Cloudflare Workers and Node.js 18+.
4
+ */
5
+ /**
6
+ * Encrypt plaintext string using AES-256-GCM.
7
+ *
8
+ * @param plaintext - String to encrypt
9
+ * @param secret - Base64url-encoded 32-byte secret key
10
+ * @returns Base64url-encoded ciphertext (IV prepended)
11
+ */
12
+ export declare function encrypt(plaintext: string, secret: string): Promise<string>;
13
+ /**
14
+ * Decrypt ciphertext string using AES-256-GCM.
15
+ *
16
+ * @param ciphertext - Base64url-encoded ciphertext (IV prepended)
17
+ * @param secret - Base64url-encoded 32-byte secret key
18
+ * @returns Decrypted plaintext string
19
+ */
20
+ export declare function decrypt(ciphertext: string, secret: string): Promise<string>;
21
+ /**
22
+ * Generate a random 32-byte (256-bit) key suitable for AES-256.
23
+ * Returns base64url-encoded string.
24
+ */
25
+ export declare function generateKey(): string;
26
+ /**
27
+ * Encryptor interface for encrypt/decrypt operations.
28
+ */
29
+ export interface Encryptor {
30
+ encrypt: (plaintext: string) => Promise<string>;
31
+ decrypt: (ciphertext: string) => Promise<string>;
32
+ }
33
+ /**
34
+ * Create encryption/decryption functions bound to a specific key.
35
+ * Useful for initializing KV stores and file stores.
36
+ */
37
+ export declare function createEncryptor(secret: string): Encryptor;
@@ -0,0 +1 @@
1
+ export * from "./aes-gcm.js";
@@ -0,0 +1,20 @@
1
+ export interface CorsOptions {
2
+ origin?: string;
3
+ methods?: string[];
4
+ headers?: string[];
5
+ credentials?: boolean;
6
+ maxAge?: number;
7
+ }
8
+ /**
9
+ * Apply CORS headers to a Response object.
10
+ * Works with both Node.js and Cloudflare Workers.
11
+ */
12
+ export declare function withCors(response: Response, options?: CorsOptions): Response;
13
+ /**
14
+ * Create a preflight (OPTIONS) response with CORS headers.
15
+ */
16
+ export declare function corsPreflightResponse(options?: CorsOptions): Response;
17
+ /**
18
+ * Build CORS headers object (for frameworks that need headers separately).
19
+ */
20
+ export declare function buildCorsHeaders(options?: CorsOptions): Record<string, string>;
@@ -0,0 +1,2 @@
1
+ export * from "./cors.js";
2
+ export * from "./response.js";
@@ -0,0 +1,52 @@
1
+ import { type CorsOptions } from "./cors.js";
2
+ /**
3
+ * Create a JSON response with proper headers.
4
+ */
5
+ export declare function jsonResponse(data: unknown, options?: {
6
+ status?: number;
7
+ headers?: Record<string, string>;
8
+ cors?: boolean | CorsOptions;
9
+ }): Response;
10
+ /**
11
+ * Create a JSON-RPC error response.
12
+ */
13
+ export declare function jsonRpcError(code: number, message: string, id?: string | number | null, options?: {
14
+ status?: number;
15
+ cors?: boolean | CorsOptions;
16
+ }): Response;
17
+ /**
18
+ * Create a JSON-RPC success response.
19
+ */
20
+ export declare function jsonRpcSuccess(result: unknown, id: string | number | null, options?: {
21
+ headers?: Record<string, string>;
22
+ cors?: boolean | CorsOptions;
23
+ }): Response;
24
+ /**
25
+ * Create a text error response.
26
+ */
27
+ export declare function textError(message: string, options?: {
28
+ status?: number;
29
+ cors?: boolean | CorsOptions;
30
+ }): Response;
31
+ /**
32
+ * Create an OAuth error response.
33
+ */
34
+ export declare function oauthError(error: string, description?: string, options?: {
35
+ status?: number;
36
+ cors?: boolean | CorsOptions;
37
+ }): Response;
38
+ /**
39
+ * Create a redirect response.
40
+ */
41
+ export declare function redirectResponse(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
42
+ /**
43
+ * Standard JSON-RPC error codes
44
+ */
45
+ export declare const JsonRpcErrorCode: {
46
+ readonly ParseError: -32700;
47
+ readonly InvalidRequest: -32600;
48
+ readonly MethodNotFound: -32601;
49
+ readonly InvalidParams: -32602;
50
+ readonly InternalError: -32603;
51
+ readonly ServerError: -32000;
52
+ };