@mcpcloud/runtime 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.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Runtime configuration for an MCPCloud-generated server.
3
+ *
4
+ * The codegen used to bake server-specific constants into every bundle's
5
+ * `src/config.ts`; in the package the same values arrive as a
6
+ * `ServerIdentity` (the `defineServer` data) and behavior lives here once.
7
+ */
8
+ export type RuntimeAccessMode = 'public' | 'privateOrg' | 'unlisted';
9
+ export interface RuntimeEnv {
10
+ UPSTREAM_BASE_URL?: string;
11
+ UPSTREAM_API_KEY?: string;
12
+ UPSTREAM_API_KEY_HEADER?: string;
13
+ UPSTREAM_API_KEY_PREFIX?: string;
14
+ UPSTREAM_CUSTOM_HEADERS?: string;
15
+ MCP_OAUTH_RUNTIME_URL?: string;
16
+ MCP_OAUTH_CONNECTION_ID?: string;
17
+ MCP_OAUTH_RUNTIME_TOKEN?: string;
18
+ MCP_OAUTH_MODE?: string;
19
+ MCP_OAUTH_APPLY_ALL?: string;
20
+ MCP_OAUTH_TOOL_OVERRIDES?: string;
21
+ MCP_RUNTIME_AUTH_ACCESS_MODE?: string;
22
+ MCP_RUNTIME_AUTH_AUDIENCE?: string;
23
+ MCP_RUNTIME_AUTH_DEPLOYMENT_ID?: string;
24
+ MCP_RUNTIME_AUTH_DEPLOYMENT_VERSION?: string;
25
+ MCP_RUNTIME_AUTH_ISSUER?: string;
26
+ MCP_RUNTIME_AUTH_ORGANIZATION_ID?: string;
27
+ MCP_RUNTIME_AUTH_PUBLIC_KEY?: string;
28
+ MCP_RUNTIME_AUTH_SERVER_ID?: string;
29
+ }
30
+ /** Per-server data the codegen passes to `defineServer` / config resolution. */
31
+ export interface ServerIdentity {
32
+ serverName: string;
33
+ serverVersion: string;
34
+ /** Spec-derived default upstream origin; null when the spec declared none. */
35
+ defaultUpstreamBaseUrl: string | null;
36
+ apiKeyHeader: string;
37
+ apiKeyPrefix: string;
38
+ }
39
+ export interface RuntimeOAuthConfig {
40
+ runtimeUrl: string;
41
+ connectionId: string;
42
+ mode: 'shared' | 'perMember';
43
+ applyToAllTools: boolean;
44
+ toolOverrides: Partial<Record<string, 'on' | 'off'>>;
45
+ }
46
+ export interface CallerContext {
47
+ userId: string | null;
48
+ runtimeToken: string | null;
49
+ }
50
+ export interface RuntimeAccessConfig {
51
+ audience: string;
52
+ deploymentId: string;
53
+ deploymentVersion: number;
54
+ issuer: string;
55
+ organizationId: string;
56
+ publicKey: string;
57
+ serverId: string;
58
+ }
59
+ export interface RuntimeConfig {
60
+ serverName: string;
61
+ serverVersion: string;
62
+ upstreamBaseUrl: string;
63
+ apiKey: string | null;
64
+ apiKeyHeader: string;
65
+ apiKeyPrefix: string;
66
+ customHeaders: Record<string, string>;
67
+ accessMode: RuntimeAccessMode;
68
+ oauth: RuntimeOAuthConfig | null;
69
+ runtimeAuth: RuntimeAccessConfig | null;
70
+ }
71
+ export declare function getProcessEnv(): RuntimeEnv;
72
+ export declare function resolveRuntimeAccessMode(env?: RuntimeEnv): RuntimeAccessMode;
73
+ export declare function resolveRuntimeConfig(identity: ServerIdentity, env?: RuntimeEnv): RuntimeConfig;
74
+ export declare function postOAuthRuntimeRequest(config: RuntimeConfig, body: {
75
+ connectionId: string;
76
+ forceRefresh: boolean;
77
+ callerRuntimeToken: string | null;
78
+ }): Promise<Response>;
@@ -0,0 +1,20 @@
1
+ export interface ToolCatalogEntry {
2
+ name: string;
3
+ title: string;
4
+ description: string;
5
+ tags: string[];
6
+ }
7
+ export interface ToolSearchResult {
8
+ name: string;
9
+ title: string;
10
+ description: string;
11
+ score: number;
12
+ }
13
+ /**
14
+ * Hybrid tool search over a catalog.
15
+ * - `/pattern/flags` → regex match against name/title/description/tags.
16
+ * - empty query → directory listing of the first `limit` tools.
17
+ * - otherwise → BM25 ranking, with a substring fallback for exact-name or
18
+ * partial-word lookups that produced no BM25 hit.
19
+ */
20
+ export declare function searchCatalog(entries: ToolCatalogEntry[], query: string, limit?: number): ToolSearchResult[];
package/dist/http.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { CallerContext, RuntimeConfig } from './config';
2
+ import type { ToolDefinition } from './types';
3
+ export declare function buildUpstreamRequest(tool: ToolDefinition, rawInput: Record<string, unknown>, config: RuntimeConfig, caller: CallerContext, forceOauthRefresh?: boolean): Promise<{
4
+ url: string;
5
+ init: RequestInit;
6
+ }>;
7
+ export declare function encodeFormUrlencodedBody(value: unknown): string;
8
+ export declare function parseUpstreamResponse(response: Response): Promise<unknown>;
9
+ export declare function mapUpstreamError(tool: ToolDefinition, status: number, payload: unknown): Error;
10
+ export declare function normalizeUpstreamPayload(tool: ToolDefinition, response: Response, payload: unknown): unknown;
11
+ export declare function formatToolResultText(tool: ToolDefinition, payload: unknown): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @mcpcloud/runtime — the runtime for MCPCloud-generated MCP servers.
3
+ *
4
+ * Worker-safe entry: everything here runs on Cloudflare Workers, Node 20+,
5
+ * and Bun. stdio and node HTTP adapters live in the `./stdio` and `./node`
6
+ * subpath exports (they import node builtins).
7
+ */
8
+ export type { EndpointDefinition, ErrorMappingDefinition, SecuritySchemeDefinition, ToolDefinition, } from './types';
9
+ export { getProcessEnv, postOAuthRuntimeRequest, resolveRuntimeAccessMode, resolveRuntimeConfig, } from './config';
10
+ export type { CallerContext, RuntimeAccessConfig, RuntimeAccessMode, RuntimeConfig, RuntimeEnv, RuntimeOAuthConfig, ServerIdentity, } from './config';
11
+ export { buildUpstreamHeaders, hasOauthSecurity, resolveUseOAuth, } from './auth-headers';
12
+ export { buildUpstreamRequest, encodeFormUrlencodedBody, formatToolResultText, mapUpstreamError, normalizeUpstreamPayload, parseUpstreamResponse, } from './http';
13
+ export { authorizeRuntimeRequest, describeRuntimeAccess, isProtectedRuntimeAccessMode, } from './access';
14
+ export type { RuntimeAuthorization } from './access';
15
+ export { assertValidInput } from './validation';
16
+ export { applyResponseProjection } from './projection';
17
+ export { jsonSchemaToZodObject, jsonSchemaToZodSchema } from './schema';
18
+ export { clearMetadataOverrides, getMetadataOverrides, resolveDescription, resolveTitle, setMetadataOverride, } from './metadata-overrides';
19
+ export type { ToolMetadataOverride } from './metadata-overrides';
20
+ export { searchCatalog } from './discovery';
21
+ export type { ToolCatalogEntry, ToolSearchResult } from './discovery';
22
+ export { defineServer } from './server';
23
+ export type { DefineServerOptions, GeneratedServer, RegisteredTool, ToolHandler, } from './server';
24
+ export { toWorkerHandler } from './adapters/worker';
25
+ export { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
26
+ export { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
27
+ export { McpError } from '@modelcontextprotocol/sdk/types.js';
28
+ export type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
29
+ export { z } from 'zod';