diff --git a/.gitignore b/.gitignore index a1b83bc4f..d8eecc765 100644 --- a/.gitignore +++ b/.gitignore @@ -129,7 +129,8 @@ out .pnp.* .DS_Store -dist/ +# dist/ - Uncommented for GitHub installation support +# dist/ # IDE .idea/ diff --git a/SESSIONSTORE.md b/SESSIONSTORE.md new file mode 100644 index 000000000..c9dc5bd7f --- /dev/null +++ b/SESSIONSTORE.md @@ -0,0 +1,244 @@ +# SessionStore Extension for Multi-Pod Deployments + +This fork adds native support for distributed session storage in the MCP SDK, enabling multi-pod/multi-node deployments where session state must be shared across server instances. + +## Quick Start + +```typescript +import { StreamableHTTPServerTransport, RedisSessionStore } from '@anthropic-advisori/mcp-sdk/server'; +import Redis from 'ioredis'; + +// Single-pod mode (default) - sessions in memory +const singlePodTransport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'memory' // This is the default +}); + +// Multi-pod mode - sessions in Redis +const multiPodTransport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', // ← Explicit mode selection + sessionStore: new RedisSessionStore({ + redis: new Redis(), + ttlSeconds: 3600 + }) +}); +``` + +## The Problem + +The official `@modelcontextprotocol/sdk` stores session state **in-memory**: + +```typescript +// Original SDK - sessions are local to each process +private _initialized: boolean = false; +sessionId?: string; +``` + +This means: +- Sessions cannot be shared across multiple pods/containers +- Load balancers routing requests to different instances will fail +- Sessions are lost on server restart + +## The Solution: SessionStorageMode + SessionStore Interface + +We've added two new options to `StreamableHTTPServerTransport`: + +### SessionStorageMode + +```typescript +type SessionStorageMode = 'memory' | 'external'; +``` + +| Mode | Description | Use Case | +|------|-------------|----------| +| `memory` | Sessions in process memory (default) | Single-pod deployments, development | +| `external` | Sessions in external store | Multi-pod deployments, production clusters | + +### SessionStore Interface + +```typescript +export interface SessionStore { + storeSession(sessionId: string, data: SessionData): Promise; + getSession(sessionId: string): Promise; + updateSessionActivity(sessionId: string): Promise; + deleteSession(sessionId: string): Promise; + sessionExists(sessionId: string): Promise; +} + +export interface SessionData { + sessionId: string; + initialized: boolean; + createdAt: number; + lastActivity: number; + metadata?: Record; +} +``` + +## Usage + +### Memory Mode (Default - Single Pod) + +```typescript +import { StreamableHTTPServerTransport } from '@anthropic-advisori/mcp-sdk/server'; +import { randomUUID } from 'crypto'; + +// Memory mode is the default - no external dependencies needed +const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + // sessionStorageMode: 'memory' is implicit +}); +``` + +### External Mode with Redis (Multi-Pod) + +```typescript +import Redis from 'ioredis'; +import { StreamableHTTPServerTransport, RedisSessionStore } from '@anthropic-advisori/mcp-sdk/server'; +import { randomUUID } from 'crypto'; + +// Create Redis client +const redis = new Redis({ + host: 'redis.example.com', + port: 6379, + password: 'your-password' +}); + +// Create session store with 1-hour TTL +const sessionStore = new RedisSessionStore({ + redis, + keyPrefix: 'mcp:session:', + ttlSeconds: 3600 +}); + +// Create transport with external session storage +const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', // ← Explicitly enable external storage + sessionStore // ← Required when mode is 'external' +}); + +// Check mode at runtime +console.log(transport.sessionStorageMode); // 'external' +console.log(transport.isUsingExternalSessionStore); // true +``` + +**Important**: When `sessionStorageMode` is `'external'`, you MUST provide a `sessionStore`. Otherwise, an error will be thrown at construction time. + +### Custom Session Store Implementation + +Implement the `SessionStore` interface for any backend: + +```typescript +import { SessionStore, SessionData } from '@anthropic-advisori/mcp-sdk/server'; + +class PostgresSessionStore implements SessionStore { + constructor(private pool: Pool) {} + + async storeSession(sessionId: string, data: SessionData): Promise { + await this.pool.query( + `INSERT INTO mcp_sessions (id, data, expires_at) + VALUES ($1, $2, NOW() + INTERVAL '1 hour') + ON CONFLICT (id) DO UPDATE SET data = $2, expires_at = NOW() + INTERVAL '1 hour'`, + [sessionId, JSON.stringify(data)] + ); + } + + async getSession(sessionId: string): Promise { + const result = await this.pool.query( + `SELECT data FROM mcp_sessions WHERE id = $1 AND expires_at > NOW()`, + [sessionId] + ); + return result.rows[0]?.data ?? null; + } + + // ... implement other methods +} +``` + +## Backward Compatibility + +This is a **non-breaking change**. When `sessionStore` is not provided, the transport behaves exactly as before with in-memory sessions. + +| Scenario | Behavior | +|----------|----------| +| `sessionStore` not provided | In-memory sessions (original behavior) | +| `sessionStore` provided | External session storage (Redis, DB, etc.) | + +## Key Features + +### Cross-Pod Session Recovery + +When a request arrives at a different pod than where the session was created, the transport automatically recovers the session from the store: + +```typescript +// In validateSession(): +if (this._sessionStore) { + const sessionData = await this._sessionStore.getSession(requestSessionId); + if (sessionData) { + // Recover session locally + this.sessionId = requestSessionId; + this._initialized = true; + } +} +``` + +### Automatic TTL Refresh + +Session activity updates refresh the TTL in the store: + +```typescript +// On every request: +if (this._sessionStore && this.sessionId) { + await this._sessionStore.updateSessionActivity(this.sessionId); +} +``` + +## Included Implementations + +### RedisSessionStore + +Production-ready Redis implementation with: +- Configurable key prefix +- Configurable TTL +- Automatic activity-based TTL refresh +- Logging callback support + +### InMemorySessionStore + +For development/testing only - NOT suitable for multi-pod production deployments. + +## Migration from Custom Workarounds + +If you've implemented custom session recovery (like we did in mcp_virtualserver), you can now remove that code and use native SessionStore: + +**Before (with workarounds):** +```typescript +// Custom session recovery logic... +const redisSession = await this.sessionStore.getSession(sessionId); +if (redisSession) { + // Manually reconstruct transport... + (transport as any)._initialized = true; + (transport as any).sessionId = sessionId; +} +``` + +**After (native support):** +```typescript +const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStore: myRedisSessionStore // That's it! +}); +``` + +## PR to Upstream + +This feature has been submitted as a PR to the official SDK repository. Until it's merged, use this fork: + +```bash +npm install @anthropic-advisori/mcp-sdk +``` + +## License + +MIT (same as original SDK) diff --git a/dist/cjs/client/auth-extensions.d.ts b/dist/cjs/client/auth-extensions.d.ts new file mode 100644 index 000000000..2a3f6bff6 --- /dev/null +++ b/dist/cjs/client/auth-extensions.d.ts @@ -0,0 +1,178 @@ +/** + * OAuth provider extensions for specialized authentication flows. + * + * This module provides ready-to-use OAuthClientProvider implementations + * for common machine-to-machine authentication scenarios. + */ +import { OAuthClientInformation, OAuthClientMetadata, OAuthTokens } from '../shared/auth.js'; +import { AddClientAuthentication, OAuthClientProvider } from './auth.js'; +/** + * Helper to produce a private_key_jwt client authentication function. + * + * Usage: + * const addClientAuth = createPrivateKeyJwtAuth({ issuer, subject, privateKey, alg, audience? }); + * // pass addClientAuth as provider.addClientAuthentication implementation + */ +export declare function createPrivateKeyJwtAuth(options: { + issuer: string; + subject: string; + privateKey: string | Uint8Array | Record; + alg: string; + audience?: string | URL; + lifetimeSeconds?: number; + claims?: Record; +}): AddClientAuthentication; +/** + * Options for creating a ClientCredentialsProvider. + */ +export interface ClientCredentialsProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * The client_secret for client_secret_basic authentication. + */ + clientSecret: string; + /** + * Optional client name for metadata. + */ + clientName?: string; +} +/** + * OAuth provider for client_credentials grant with client_secret_basic authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a client_id and client_secret. + * + * @example + * const provider = new ClientCredentialsProvider({ + * clientId: 'my-client', + * clientSecret: 'my-secret' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export declare class ClientCredentialsProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + constructor(options: ClientCredentialsProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +/** + * Options for creating a PrivateKeyJwtProvider. + */ +export interface PrivateKeyJwtProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * The private key for signing JWT assertions. + * Can be a PEM string, Uint8Array, or JWK object. + */ + privateKey: string | Uint8Array | Record; + /** + * The algorithm to use for signing (e.g., 'RS256', 'ES256'). + */ + algorithm: string; + /** + * Optional client name for metadata. + */ + clientName?: string; + /** + * Optional JWT lifetime in seconds (default: 300). + */ + jwtLifetimeSeconds?: number; +} +/** + * OAuth provider for client_credentials grant with private_key_jwt authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a signed JWT assertion (RFC 7523 Section 2.2). + * + * @example + * const provider = new PrivateKeyJwtProvider({ + * clientId: 'my-client', + * privateKey: pemEncodedPrivateKey, + * algorithm: 'RS256' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export declare class PrivateKeyJwtProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + addClientAuthentication: AddClientAuthentication; + constructor(options: PrivateKeyJwtProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +/** + * Options for creating a StaticPrivateKeyJwtProvider. + */ +export interface StaticPrivateKeyJwtProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * A pre-built JWT client assertion to use for authentication. + * + * This token should already contain the appropriate claims + * (iss, sub, aud, exp, etc.) and be signed by the client's key. + */ + jwtBearerAssertion: string; + /** + * Optional client name for metadata. + */ + clientName?: string; +} +/** + * OAuth provider for client_credentials grant with a static private_key_jwt assertion. + * + * This provider mirrors {@link PrivateKeyJwtProvider} but instead of constructing and + * signing a JWT on each request, it accepts a pre-built JWT assertion string and + * uses it directly for authentication. + */ +export declare class StaticPrivateKeyJwtProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + addClientAuthentication: AddClientAuthentication; + constructor(options: StaticPrivateKeyJwtProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +//# sourceMappingURL=auth-extensions.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/auth-extensions.d.ts.map b/dist/cjs/client/auth-extensions.d.ts.map new file mode 100644 index 000000000..863e23a83 --- /dev/null +++ b/dist/cjs/client/auth-extensions.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-extensions.d.ts","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,uBAAuB,CAgE1B;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC7C;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,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100644 index 000000000..d551ce3df --- /dev/null +++ b/dist/cjs/client/auth-extensions.js @@ -0,0 +1,300 @@ +"use strict"; +/** + * OAuth provider extensions for specialized authentication flows. + * + * This module provides ready-to-use OAuthClientProvider implementations + * for common machine-to-machine authentication scenarios. + */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StaticPrivateKeyJwtProvider = exports.PrivateKeyJwtProvider = exports.ClientCredentialsProvider = void 0; +exports.createPrivateKeyJwtAuth = createPrivateKeyJwtAuth; +/** + * Helper to produce a private_key_jwt client authentication function. + * + * Usage: + * const addClientAuth = createPrivateKeyJwtAuth({ issuer, subject, privateKey, alg, audience? }); + * // pass addClientAuth as provider.addClientAuthentication implementation + */ +function createPrivateKeyJwtAuth(options) { + return async (_headers, params, url, metadata) => { + var _a, _b, _c; + // Lazy import to avoid heavy dependency unless used + if (typeof globalThis.crypto === 'undefined') { + throw new TypeError('crypto is not available, please ensure you add have Web Crypto API support for older Node.js versions (see https://github.com/modelcontextprotocol/typescript-sdk#nodejs-web-crypto-globalthiscrypto-compatibility)'); + } + const jose = await Promise.resolve().then(() => __importStar(require('jose'))); + const audience = String((_b = (_a = options.audience) !== null && _a !== void 0 ? _a : metadata === null || metadata === void 0 ? void 0 : metadata.issuer) !== null && _b !== void 0 ? _b : url); + const lifetimeSeconds = (_c = options.lifetimeSeconds) !== null && _c !== void 0 ? _c : 300; + const now = Math.floor(Date.now() / 1000); + const jti = `${Date.now()}-${Math.random().toString(36).slice(2)}`; + const baseClaims = { + iss: options.issuer, + sub: options.subject, + aud: audience, + exp: now + lifetimeSeconds, + iat: now, + jti + }; + const claims = options.claims ? { ...baseClaims, ...options.claims } : baseClaims; + // Import key for the requested algorithm + const alg = options.alg; + let key; + if (typeof options.privateKey === 'string') { + if (alg.startsWith('RS') || alg.startsWith('ES') || alg.startsWith('PS')) { + key = await jose.importPKCS8(options.privateKey, alg); + } + else if (alg.startsWith('HS')) { + key = new TextEncoder().encode(options.privateKey); + } + else { + throw new Error(`Unsupported algorithm ${alg}`); + } + } + else if (options.privateKey instanceof Uint8Array) { + if (alg.startsWith('HS')) { + key = options.privateKey; + } + else { + // Assume PKCS#8 DER in Uint8Array for asymmetric algorithms + key = await jose.importPKCS8(new TextDecoder().decode(options.privateKey), alg); + } + } + else { + // Treat as JWK + key = await jose.importJWK(options.privateKey, alg); + } + // Sign JWT + const assertion = await new jose.SignJWT(claims) + .setProtectedHeader({ alg, typ: 'JWT' }) + .setIssuer(options.issuer) + .setSubject(options.subject) + .setAudience(audience) + .setIssuedAt(now) + .setExpirationTime(now + lifetimeSeconds) + .setJti(jti) + .sign(key); + params.set('client_assertion', assertion); + params.set('client_assertion_type', 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'); + }; +} +/** + * OAuth provider for client_credentials grant with client_secret_basic authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a client_id and client_secret. + * + * @example + * const provider = new ClientCredentialsProvider({ + * clientId: 'my-client', + * clientSecret: 'my-secret' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +class ClientCredentialsProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId, + client_secret: options.clientSecret + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'client-credentials-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'client_secret_basic' + }; + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +exports.ClientCredentialsProvider = ClientCredentialsProvider; +/** + * OAuth provider for client_credentials grant with private_key_jwt authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a signed JWT assertion (RFC 7523 Section 2.2). + * + * @example + * const provider = new PrivateKeyJwtProvider({ + * clientId: 'my-client', + * privateKey: pemEncodedPrivateKey, + * algorithm: 'RS256' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +class PrivateKeyJwtProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'private-key-jwt-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'private_key_jwt' + }; + this.addClientAuthentication = createPrivateKeyJwtAuth({ + issuer: options.clientId, + subject: options.clientId, + privateKey: options.privateKey, + alg: options.algorithm, + lifetimeSeconds: options.jwtLifetimeSeconds + }); + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +exports.PrivateKeyJwtProvider = PrivateKeyJwtProvider; +/** + * OAuth provider for client_credentials grant with a static private_key_jwt assertion. + * + * This provider mirrors {@link PrivateKeyJwtProvider} but instead of constructing and + * signing a JWT on each request, it accepts a pre-built JWT assertion string and + * uses it directly for authentication. + */ +class StaticPrivateKeyJwtProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'static-private-key-jwt-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'private_key_jwt' + }; + const assertion = options.jwtBearerAssertion; + this.addClientAuthentication = async (_headers, params) => { + params.set('client_assertion', assertion); + params.set('client_assertion_type', 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'); + }; + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +exports.StaticPrivateKeyJwtProvider = StaticPrivateKeyJwtProvider; +//# sourceMappingURL=auth-extensions.js.map \ No newline at end of file diff --git a/dist/cjs/client/auth-extensions.js.map b/dist/cjs/client/auth-extensions.js.map new file mode 100644 index 000000000..6a5cb0291 --- /dev/null +++ b/dist/cjs/client/auth-extensions.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-extensions.js","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,0DAwEC;AA/ED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,OAQvC;IACG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;;QAC7C,oDAAoD;QACpD,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YAC3C,MAAM,IAAI,SAAS,CACf,qNAAqN,CACxN,CAAC;QACN,CAAC;QAED,MAAM,IAAI,GAAG,wDAAa,MAAM,GAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,mCAAI,GAAG,CAAC,CAAC;QACrE,MAAM,eAAe,GAAG,MAAA,OAAO,CAAC,eAAe,mCAAI,GAAG,CAAC;QAEvD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAEnE,MAAM,UAAU,GAAG;YACf,GAAG,EAAE,OAAO,CAAC,MAAM;YACnB,GAAG,EAAE,OAAO,CAAC,OAAO;YACpB,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,GAAG,GAAG,eAAe;YAC1B,GAAG,EAAE,GAAG;YACR,GAAG;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C,uBAAuB,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE;YACtD,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC1C,MAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE,wDAAwD,CAAC,CAAC;QAClG,CAAC,CAAC;IACN,CAAC;IAED,IAAI,WAAW;QACX,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,qBAAqB,CAAC,IAA4B;QAC9C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,MAAmB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,uBAAuB;QACnB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,CAAC;IAED,gBAAgB;QACZ,kCAAkC;IACtC,CAAC;IAED,YAAY;QACR,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;IAED,mBAAmB,CAAC,KAAc;QAC9B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,CAAC;QACzE,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAjED,kEAiEC"} \ No newline at end of file diff --git a/dist/cjs/client/auth.d.ts b/dist/cjs/client/auth.d.ts new file mode 100644 index 000000000..c1405d6c0 --- /dev/null +++ b/dist/cjs/client/auth.d.ts @@ -0,0 +1,368 @@ +import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens, OAuthMetadata, OAuthClientInformationFull, OAuthProtectedResourceMetadata, AuthorizationServerMetadata } from '../shared/auth.js'; +import { OAuthError } from '../server/auth/errors.js'; +import { FetchLike } from '../shared/transport.js'; +/** + * Function type for adding client authentication to token requests. + */ +export type AddClientAuthentication = (headers: Headers, params: URLSearchParams, url: string | URL, metadata?: AuthorizationServerMetadata) => void | Promise; +/** + * Implements an end-to-end OAuth client to be used with one MCP server. + * + * This client relies upon a concept of an authorized "session," the exact + * meaning of which is application-defined. Tokens, authorization codes, and + * code verifiers should not cross different sessions. + */ +export interface OAuthClientProvider { + /** + * The URL to redirect the user agent to after authorization. + * Return undefined for non-interactive flows that don't require user interaction + * (e.g., client_credentials, jwt-bearer). + */ + get redirectUrl(): string | URL | undefined; + /** + * External URL the server should use to fetch client metadata document + */ + clientMetadataUrl?: string; + /** + * Metadata about this OAuth client. + */ + get clientMetadata(): OAuthClientMetadata; + /** + * Returns a OAuth2 state parameter. + */ + state?(): string | Promise; + /** + * Loads information about this OAuth client, as registered already with the + * server, or returns `undefined` if the client is not registered with the + * server. + */ + clientInformation(): OAuthClientInformationMixed | undefined | Promise; + /** + * If implemented, this permits the OAuth client to dynamically register with + * the server. Client information saved this way should later be read via + * `clientInformation()`. + * + * This method is not required to be implemented if client information is + * statically known (e.g., pre-registered). + */ + saveClientInformation?(clientInformation: OAuthClientInformationMixed): void | Promise; + /** + * Loads any existing OAuth tokens for the current session, or returns + * `undefined` if there are no saved tokens. + */ + tokens(): OAuthTokens | undefined | Promise; + /** + * Stores new OAuth tokens for the current session, after a successful + * authorization. + */ + saveTokens(tokens: OAuthTokens): void | Promise; + /** + * Invoked to redirect the user agent to the given URL to begin the authorization flow. + */ + redirectToAuthorization(authorizationUrl: URL): void | Promise; + /** + * Saves a PKCE code verifier for the current session, before redirecting to + * the authorization flow. + */ + saveCodeVerifier(codeVerifier: string): void | Promise; + /** + * Loads the PKCE code verifier for the current session, necessary to validate + * the authorization result. + */ + codeVerifier(): string | Promise; + /** + * Adds custom client authentication to OAuth token requests. + * + * This optional method allows implementations to customize how client credentials + * are included in token exchange and refresh requests. When provided, this method + * is called instead of the default authentication logic, giving full control over + * the authentication mechanism. + * + * Common use cases include: + * - Supporting authentication methods beyond the standard OAuth 2.0 methods + * - Adding custom headers for proprietary authentication schemes + * - Implementing client assertion-based authentication (e.g., JWT bearer tokens) + * + * @param headers - The request headers (can be modified to add authentication) + * @param params - The request body parameters (can be modified to add credentials) + * @param url - The token endpoint URL being called + * @param metadata - Optional OAuth metadata for the server, which may include supported authentication methods + */ + addClientAuthentication?: AddClientAuthentication; + /** + * If defined, overrides the selection and validation of the + * RFC 8707 Resource Indicator. If left undefined, default + * validation behavior will be used. + * + * Implementations must verify the returned resource matches the MCP server. + */ + validateResourceURL?(serverUrl: string | URL, resource?: string): Promise; + /** + * If implemented, provides a way for the client to invalidate (e.g. delete) the specified + * credentials, in the case where the server has indicated that they are no longer valid. + * This avoids requiring the user to intervene manually. + */ + invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise; + /** + * Prepares grant-specific parameters for a token request. + * + * This optional method allows providers to customize the token request based on + * the grant type they support. When implemented, it returns the grant type and + * any grant-specific parameters needed for the token exchange. + * + * If not implemented, the default behavior depends on the flow: + * - For authorization code flow: uses code, code_verifier, and redirect_uri + * - For client_credentials: detected via grant_types in clientMetadata + * + * @param scope - Optional scope to request + * @returns Grant type and parameters, or undefined to use default behavior + * + * @example + * // For client_credentials grant: + * prepareTokenRequest(scope) { + * return { + * grantType: 'client_credentials', + * params: scope ? { scope } : {} + * }; + * } + * + * @example + * // For authorization_code grant (default behavior): + * async prepareTokenRequest() { + * return { + * grantType: 'authorization_code', + * params: { + * code: this.authorizationCode, + * code_verifier: await this.codeVerifier(), + * redirect_uri: String(this.redirectUrl) + * } + * }; + * } + */ + prepareTokenRequest?(scope?: string): URLSearchParams | Promise | undefined; +} +export type AuthResult = 'AUTHORIZED' | 'REDIRECT'; +export declare class UnauthorizedError extends Error { + constructor(message?: string); +} +type ClientAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none'; +/** + * Determines the best client authentication method to use based on server support and client configuration. + * + * Priority order (highest to lowest): + * 1. client_secret_basic (if client secret is available) + * 2. client_secret_post (if client secret is available) + * 3. none (for public clients) + * + * @param clientInformation - OAuth client information containing credentials + * @param supportedMethods - Authentication methods supported by the authorization server + * @returns The selected authentication method + */ +export declare function selectClientAuthMethod(clientInformation: OAuthClientInformationMixed, supportedMethods: string[]): ClientAuthMethod; +/** + * Parses an OAuth error response from a string or Response object. + * + * If the input is a standard OAuth2.0 error response, it will be parsed according to the spec + * and an instance of the appropriate OAuthError subclass will be returned. + * If parsing fails, it falls back to a generic ServerError that includes + * the response status (if available) and original content. + * + * @param input - A Response object or string containing the error response + * @returns A Promise that resolves to an OAuthError instance + */ +export declare function parseErrorResponse(input: Response | string): Promise; +/** + * Orchestrates the full auth flow with a server. + * + * This can be used as a single entry point for all authorization functionality, + * instead of linking together the other lower-level functions in this module. + */ +export declare function auth(provider: OAuthClientProvider, options: { + serverUrl: string | URL; + authorizationCode?: string; + scope?: string; + resourceMetadataUrl?: URL; + fetchFn?: FetchLike; +}): Promise; +/** + * SEP-991: URL-based Client IDs + * Validate that the client_id is a valid URL with https scheme + */ +export declare function isHttpsUrl(value?: string): boolean; +export declare function selectResourceURL(serverUrl: string | URL, provider: OAuthClientProvider, resourceMetadata?: OAuthProtectedResourceMetadata): Promise; +/** + * Extract resource_metadata, scope, and error from WWW-Authenticate header. + */ +export declare function extractWWWAuthenticateParams(res: Response): { + resourceMetadataUrl?: URL; + scope?: string; + error?: string; +}; +/** + * Extract resource_metadata from response header. + * @deprecated Use `extractWWWAuthenticateParams` instead. + */ +export declare function extractResourceMetadataUrl(res: Response): URL | undefined; +/** + * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + */ +export declare function discoverOAuthProtectedResourceMetadata(serverUrl: string | URL, opts?: { + protocolVersion?: string; + resourceMetadataUrl?: string | URL; +}, fetchFn?: FetchLike): Promise; +/** + * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + * + * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`. + */ +export declare function discoverOAuthMetadata(issuer: string | URL, { authorizationServerUrl, protocolVersion }?: { + authorizationServerUrl?: string | URL; + protocolVersion?: string; +}, fetchFn?: FetchLike): Promise; +/** + * Builds a list of discovery URLs to try for authorization server metadata. + * URLs are returned in priority order: + * 1. OAuth metadata at the given URL + * 2. OIDC metadata endpoints at the given URL + */ +export declare function buildDiscoveryUrls(authorizationServerUrl: string | URL): { + url: URL; + type: 'oauth' | 'oidc'; +}[]; +/** + * Discovers authorization server metadata with support for RFC 8414 OAuth 2.0 Authorization Server Metadata + * and OpenID Connect Discovery 1.0 specifications. + * + * This function implements a fallback strategy for authorization server discovery: + * 1. Attempts RFC 8414 OAuth metadata discovery first + * 2. If OAuth discovery fails, falls back to OpenID Connect Discovery + * + * @param authorizationServerUrl - The authorization server URL obtained from the MCP Server's + * protected resource metadata, or the MCP server's URL if the + * metadata was not found. + * @param options - Configuration options + * @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch + * @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION + * @returns Promise resolving to authorization server metadata, or undefined if discovery fails + */ +export declare function discoverAuthorizationServerMetadata(authorizationServerUrl: string | URL, { fetchFn, protocolVersion }?: { + fetchFn?: FetchLike; + protocolVersion?: string; +}): Promise; +/** + * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL. + */ +export declare function startAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, redirectUrl, scope, state, resource }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + redirectUrl: string | URL; + scope?: string; + state?: string; + resource?: URL; +}): Promise<{ + authorizationUrl: URL; + codeVerifier: string; +}>; +/** + * Prepares token request parameters for an authorization code exchange. + * + * This is the default implementation used by fetchToken when the provider + * doesn't implement prepareTokenRequest. + * + * @param authorizationCode - The authorization code received from the authorization endpoint + * @param codeVerifier - The PKCE code verifier + * @param redirectUri - The redirect URI used in the authorization request + * @returns URLSearchParams for the authorization_code grant + */ +export declare function prepareAuthorizationCodeRequest(authorizationCode: string, codeVerifier: string, redirectUri: string | URL): URLSearchParams; +/** + * Exchanges an authorization code for an access token with the given server. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Falls back to appropriate defaults when server metadata is unavailable + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, auth code, etc. + * @returns Promise resolving to OAuth tokens + * @throws {Error} When token exchange fails or authentication is invalid + */ +export declare function exchangeAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + authorizationCode: string; + codeVerifier: string; + redirectUri: string | URL; + resource?: URL; + addClientAuthentication?: OAuthClientProvider['addClientAuthentication']; + fetchFn?: FetchLike; +}): Promise; +/** + * Exchange a refresh token for an updated access token. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Preserves the original refresh token if a new one is not returned + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, refresh token, etc. + * @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced) + * @throws {Error} When token refresh fails or authentication is invalid + */ +export declare function refreshAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + refreshToken: string; + resource?: URL; + addClientAuthentication?: OAuthClientProvider['addClientAuthentication']; + fetchFn?: FetchLike; +}): Promise; +/** + * Unified token fetching that works with any grant type via provider.prepareTokenRequest(). + * + * This function provides a single entry point for obtaining tokens regardless of the + * OAuth grant type. The provider's prepareTokenRequest() method determines which grant + * to use and supplies the grant-specific parameters. + * + * @param provider - OAuth client provider that implements prepareTokenRequest() + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration for the token request + * @returns Promise resolving to OAuth tokens + * @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails + * + * @example + * // Provider for client_credentials: + * class MyProvider implements OAuthClientProvider { + * prepareTokenRequest(scope) { + * const params = new URLSearchParams({ grant_type: 'client_credentials' }); + * if (scope) params.set('scope', scope); + * return params; + * } + * // ... other methods + * } + * + * const tokens = await fetchToken(provider, authServerUrl, { metadata }); + */ +export declare function fetchToken(provider: OAuthClientProvider, authorizationServerUrl: string | URL, { metadata, resource, authorizationCode, fetchFn }?: { + metadata?: AuthorizationServerMetadata; + resource?: URL; + /** Authorization code for the default authorization_code grant flow */ + authorizationCode?: string; + fetchFn?: FetchLike; +}): Promise; +/** + * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591. + */ +export declare function registerClient(authorizationServerUrl: string | URL, { metadata, clientMetadata, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientMetadata: OAuthClientMetadata; + fetchFn?: FetchLike; +}): Promise; +export {}; +//# sourceMappingURL=auth.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/auth.d.ts.map b/dist/cjs/client/auth.d.ts.map new file mode 100644 index 000000000..012c44018 --- /dev/null +++ b/dist/cjs/client/auth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/client/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,mBAAmB,EAEnB,2BAA2B,EAC3B,WAAW,EACX,aAAa,EACb,0BAA0B,EAC1B,8BAA8B,EAE9B,2BAA2B,EAE9B,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAKH,UAAU,EAGb,MAAM,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CAAC,CA+BtB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAChC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACI,QAAQ,EACR,cAAc,EACd,OAAO,EACV,EAAE;IACC,QAAQ,CAAC,EAAE,2BAA2B,CAAC;IACvC,cAAc,EAAE,mBAAmB,CAAC;IACpC,OAAO,CAAC,EAAE,SAAS,CAAC;CACvB,GACF,OAAO,CAAC,0BAA0B,CAAC,CA0BrC"} \ No newline at end of file diff --git a/dist/cjs/client/auth.js b/dist/cjs/client/auth.js new file mode 100644 index 000000000..248ce0856 --- /dev/null +++ b/dist/cjs/client/auth.js @@ -0,0 +1,855 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UnauthorizedError = void 0; +exports.selectClientAuthMethod = selectClientAuthMethod; +exports.parseErrorResponse = parseErrorResponse; +exports.auth = auth; +exports.isHttpsUrl = isHttpsUrl; +exports.selectResourceURL = selectResourceURL; +exports.extractWWWAuthenticateParams = extractWWWAuthenticateParams; +exports.extractResourceMetadataUrl = extractResourceMetadataUrl; +exports.discoverOAuthProtectedResourceMetadata = discoverOAuthProtectedResourceMetadata; +exports.discoverOAuthMetadata = discoverOAuthMetadata; +exports.buildDiscoveryUrls = buildDiscoveryUrls; +exports.discoverAuthorizationServerMetadata = discoverAuthorizationServerMetadata; +exports.startAuthorization = startAuthorization; +exports.prepareAuthorizationCodeRequest = prepareAuthorizationCodeRequest; +exports.exchangeAuthorization = exchangeAuthorization; +exports.refreshAuthorization = refreshAuthorization; +exports.fetchToken = fetchToken; +exports.registerClient = registerClient; +const pkce_challenge_1 = __importDefault(require("pkce-challenge")); +const types_js_1 = require("../types.js"); +const auth_js_1 = require("../shared/auth.js"); +const auth_js_2 = require("../shared/auth.js"); +const auth_utils_js_1 = require("../shared/auth-utils.js"); +const errors_js_1 = require("../server/auth/errors.js"); +class UnauthorizedError extends Error { + constructor(message) { + super(message !== null && message !== void 0 ? message : 'Unauthorized'); + } +} +exports.UnauthorizedError = UnauthorizedError; +function isClientAuthMethod(method) { + return ['client_secret_basic', 'client_secret_post', 'none'].includes(method); +} +const AUTHORIZATION_CODE_RESPONSE_TYPE = 'code'; +const AUTHORIZATION_CODE_CHALLENGE_METHOD = 'S256'; +/** + * Determines the best client authentication method to use based on server support and client configuration. + * + * Priority order (highest to lowest): + * 1. client_secret_basic (if client secret is available) + * 2. client_secret_post (if client secret is available) + * 3. none (for public clients) + * + * @param clientInformation - OAuth client information containing credentials + * @param supportedMethods - Authentication methods supported by the authorization server + * @returns The selected authentication method + */ +function selectClientAuthMethod(clientInformation, supportedMethods) { + const hasClientSecret = clientInformation.client_secret !== undefined; + // If server doesn't specify supported methods, use RFC 6749 defaults + if (supportedMethods.length === 0) { + return hasClientSecret ? 'client_secret_post' : 'none'; + } + // Prefer the method returned by the server during client registration if valid and supported + if ('token_endpoint_auth_method' in clientInformation && + clientInformation.token_endpoint_auth_method && + isClientAuthMethod(clientInformation.token_endpoint_auth_method) && + supportedMethods.includes(clientInformation.token_endpoint_auth_method)) { + return clientInformation.token_endpoint_auth_method; + } + // Try methods in priority order (most secure first) + if (hasClientSecret && supportedMethods.includes('client_secret_basic')) { + return 'client_secret_basic'; + } + if (hasClientSecret && supportedMethods.includes('client_secret_post')) { + return 'client_secret_post'; + } + if (supportedMethods.includes('none')) { + return 'none'; + } + // Fallback: use what we have + return hasClientSecret ? 'client_secret_post' : 'none'; +} +/** + * Applies client authentication to the request based on the specified method. + * + * Implements OAuth 2.1 client authentication methods: + * - client_secret_basic: HTTP Basic authentication (RFC 6749 Section 2.3.1) + * - client_secret_post: Credentials in request body (RFC 6749 Section 2.3.1) + * - none: Public client authentication (RFC 6749 Section 2.1) + * + * @param method - The authentication method to use + * @param clientInformation - OAuth client information containing credentials + * @param headers - HTTP headers object to modify + * @param params - URL search parameters to modify + * @throws {Error} When required credentials are missing + */ +function applyClientAuthentication(method, clientInformation, headers, params) { + const { client_id, client_secret } = clientInformation; + switch (method) { + case 'client_secret_basic': + applyBasicAuth(client_id, client_secret, headers); + return; + case 'client_secret_post': + applyPostAuth(client_id, client_secret, params); + return; + case 'none': + applyPublicAuth(client_id, params); + return; + default: + throw new Error(`Unsupported client authentication method: ${method}`); + } +} +/** + * Applies HTTP Basic authentication (RFC 6749 Section 2.3.1) + */ +function applyBasicAuth(clientId, clientSecret, headers) { + if (!clientSecret) { + throw new Error('client_secret_basic authentication requires a client_secret'); + } + const credentials = btoa(`${clientId}:${clientSecret}`); + headers.set('Authorization', `Basic ${credentials}`); +} +/** + * Applies POST body authentication (RFC 6749 Section 2.3.1) + */ +function applyPostAuth(clientId, clientSecret, params) { + params.set('client_id', clientId); + if (clientSecret) { + params.set('client_secret', clientSecret); + } +} +/** + * Applies public client authentication (RFC 6749 Section 2.1) + */ +function applyPublicAuth(clientId, params) { + params.set('client_id', clientId); +} +/** + * Parses an OAuth error response from a string or Response object. + * + * If the input is a standard OAuth2.0 error response, it will be parsed according to the spec + * and an instance of the appropriate OAuthError subclass will be returned. + * If parsing fails, it falls back to a generic ServerError that includes + * the response status (if available) and original content. + * + * @param input - A Response object or string containing the error response + * @returns A Promise that resolves to an OAuthError instance + */ +async function parseErrorResponse(input) { + const statusCode = input instanceof Response ? input.status : undefined; + const body = input instanceof Response ? await input.text() : input; + try { + const result = auth_js_1.OAuthErrorResponseSchema.parse(JSON.parse(body)); + const { error, error_description, error_uri } = result; + const errorClass = errors_js_1.OAUTH_ERRORS[error] || errors_js_1.ServerError; + return new errorClass(error_description || '', error_uri); + } + catch (error) { + // Not a valid OAuth error response, but try to inform the user of the raw data anyway + const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ''}Invalid OAuth error response: ${error}. Raw body: ${body}`; + return new errors_js_1.ServerError(errorMessage); + } +} +/** + * Orchestrates the full auth flow with a server. + * + * This can be used as a single entry point for all authorization functionality, + * instead of linking together the other lower-level functions in this module. + */ +async function auth(provider, options) { + var _a, _b; + try { + return await authInternal(provider, options); + } + catch (error) { + // Handle recoverable error types by invalidating credentials and retrying + if (error instanceof errors_js_1.InvalidClientError || error instanceof errors_js_1.UnauthorizedClientError) { + await ((_a = provider.invalidateCredentials) === null || _a === void 0 ? void 0 : _a.call(provider, 'all')); + return await authInternal(provider, options); + } + else if (error instanceof errors_js_1.InvalidGrantError) { + await ((_b = provider.invalidateCredentials) === null || _b === void 0 ? void 0 : _b.call(provider, 'tokens')); + return await authInternal(provider, options); + } + // Throw otherwise + throw error; + } +} +async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) { + var _a, _b; + let resourceMetadata; + let authorizationServerUrl; + try { + resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn); + if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) { + authorizationServerUrl = resourceMetadata.authorization_servers[0]; + } + } + catch (_c) { + // Ignore errors and fall back to /.well-known/oauth-authorization-server + } + /** + * If we don't get a valid authorization server metadata from protected resource metadata, + * fallback to the legacy MCP spec's implementation (version 2025-03-26): MCP server base URL acts as the Authorization server. + */ + if (!authorizationServerUrl) { + authorizationServerUrl = new URL('/', serverUrl); + } + const resource = await selectResourceURL(serverUrl, provider, resourceMetadata); + const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { + fetchFn + }); + // Handle client registration if needed + let clientInformation = await Promise.resolve(provider.clientInformation()); + if (!clientInformation) { + if (authorizationCode !== undefined) { + throw new Error('Existing OAuth client information is required when exchanging an authorization code'); + } + const supportsUrlBasedClientId = (metadata === null || metadata === void 0 ? void 0 : metadata.client_id_metadata_document_supported) === true; + const clientMetadataUrl = provider.clientMetadataUrl; + if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) { + throw new errors_js_1.InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`); + } + const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl; + if (shouldUseUrlBasedClientId) { + // SEP-991: URL-based Client IDs + clientInformation = { + client_id: clientMetadataUrl + }; + await ((_a = provider.saveClientInformation) === null || _a === void 0 ? void 0 : _a.call(provider, clientInformation)); + } + else { + // Fallback to dynamic registration + if (!provider.saveClientInformation) { + throw new Error('OAuth client information must be saveable for dynamic registration'); + } + const fullInformation = await registerClient(authorizationServerUrl, { + metadata, + clientMetadata: provider.clientMetadata, + fetchFn + }); + await provider.saveClientInformation(fullInformation); + clientInformation = fullInformation; + } + } + // Non-interactive flows (e.g., client_credentials, jwt-bearer) don't need a redirect URL + const nonInteractiveFlow = !provider.redirectUrl; + // Exchange authorization code for tokens, or fetch tokens directly for non-interactive flows + if (authorizationCode !== undefined || nonInteractiveFlow) { + const tokens = await fetchToken(provider, authorizationServerUrl, { + metadata, + resource, + authorizationCode, + fetchFn + }); + await provider.saveTokens(tokens); + return 'AUTHORIZED'; + } + const tokens = await provider.tokens(); + // Handle token refresh or new authorization + if (tokens === null || tokens === void 0 ? void 0 : tokens.refresh_token) { + try { + // Attempt to refresh the token + const newTokens = await refreshAuthorization(authorizationServerUrl, { + metadata, + clientInformation, + refreshToken: tokens.refresh_token, + resource, + addClientAuthentication: provider.addClientAuthentication, + fetchFn + }); + await provider.saveTokens(newTokens); + return 'AUTHORIZED'; + } + catch (error) { + // If this is a ServerError, or an unknown type, log it out and try to continue. Otherwise, escalate so we can fix things and retry. + if (!(error instanceof errors_js_1.OAuthError) || error instanceof errors_js_1.ServerError) { + // Could not refresh OAuth tokens + } + else { + // Refresh failed for another reason, re-throw + throw error; + } + } + } + const state = provider.state ? await provider.state() : undefined; + // Start new authorization flow + const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, { + metadata, + clientInformation, + state, + redirectUrl: provider.redirectUrl, + scope: scope || ((_b = resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.scopes_supported) === null || _b === void 0 ? void 0 : _b.join(' ')) || provider.clientMetadata.scope, + resource + }); + await provider.saveCodeVerifier(codeVerifier); + await provider.redirectToAuthorization(authorizationUrl); + return 'REDIRECT'; +} +/** + * SEP-991: URL-based Client IDs + * Validate that the client_id is a valid URL with https scheme + */ +function isHttpsUrl(value) { + if (!value) + return false; + try { + const url = new URL(value); + return url.protocol === 'https:' && url.pathname !== '/'; + } + catch (_a) { + return false; + } +} +async function selectResourceURL(serverUrl, provider, resourceMetadata) { + const defaultResource = (0, auth_utils_js_1.resourceUrlFromServerUrl)(serverUrl); + // If provider has custom validation, delegate to it + if (provider.validateResourceURL) { + return await provider.validateResourceURL(defaultResource, resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.resource); + } + // Only include resource parameter when Protected Resource Metadata is present + if (!resourceMetadata) { + return undefined; + } + // Validate that the metadata's resource is compatible with our request + if (!(0, auth_utils_js_1.checkResourceAllowed)({ requestedResource: defaultResource, configuredResource: resourceMetadata.resource })) { + throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`); + } + // Prefer the resource from metadata since it's what the server is telling us to request + return new URL(resourceMetadata.resource); +} +/** + * Extract resource_metadata, scope, and error from WWW-Authenticate header. + */ +function extractWWWAuthenticateParams(res) { + const authenticateHeader = res.headers.get('WWW-Authenticate'); + if (!authenticateHeader) { + return {}; + } + const [type, scheme] = authenticateHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !scheme) { + return {}; + } + const resourceMetadataMatch = extractFieldFromWwwAuth(res, 'resource_metadata') || undefined; + let resourceMetadataUrl; + if (resourceMetadataMatch) { + try { + resourceMetadataUrl = new URL(resourceMetadataMatch); + } + catch (_a) { + // Ignore invalid URL + } + } + const scope = extractFieldFromWwwAuth(res, 'scope') || undefined; + const error = extractFieldFromWwwAuth(res, 'error') || undefined; + return { + resourceMetadataUrl, + scope, + error + }; +} +/** + * Extracts a specific field's value from the WWW-Authenticate header string. + * + * @param response The HTTP response object containing the headers. + * @param fieldName The name of the field to extract (e.g., "realm", "nonce"). + * @returns The field value + */ +function extractFieldFromWwwAuth(response, fieldName) { + const wwwAuthHeader = response.headers.get('WWW-Authenticate'); + if (!wwwAuthHeader) { + return null; + } + const pattern = new RegExp(`${fieldName}=(?:"([^"]+)"|([^\\s,]+))`); + const match = wwwAuthHeader.match(pattern); + if (match) { + // Pattern matches: field_name="value" or field_name=value (unquoted) + return match[1] || match[2]; + } + return null; +} +/** + * Extract resource_metadata from response header. + * @deprecated Use `extractWWWAuthenticateParams` instead. + */ +function extractResourceMetadataUrl(res) { + const authenticateHeader = res.headers.get('WWW-Authenticate'); + if (!authenticateHeader) { + return undefined; + } + const [type, scheme] = authenticateHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !scheme) { + return undefined; + } + const regex = /resource_metadata="([^"]*)"/; + const match = regex.exec(authenticateHeader); + if (!match) { + return undefined; + } + try { + return new URL(match[1]); + } + catch (_a) { + return undefined; + } +} +/** + * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + */ +async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) { + var _a, _b; + const response = await discoverMetadataWithFallback(serverUrl, 'oauth-protected-resource', fetchFn, { + protocolVersion: opts === null || opts === void 0 ? void 0 : opts.protocolVersion, + metadataUrl: opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl + }); + if (!response || response.status === 404) { + await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`); + } + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`); + } + return auth_js_2.OAuthProtectedResourceMetadataSchema.parse(await response.json()); +} +/** + * Helper function to handle fetch with CORS retry logic + */ +async function fetchWithCorsRetry(url, headers, fetchFn = fetch) { + try { + return await fetchFn(url, { headers }); + } + catch (error) { + if (error instanceof TypeError) { + if (headers) { + // CORS errors come back as TypeError, retry without headers + return fetchWithCorsRetry(url, undefined, fetchFn); + } + else { + // We're getting CORS errors on retry too, return undefined + return undefined; + } + } + throw error; + } +} +/** + * Constructs the well-known path for auth-related metadata discovery + */ +function buildWellKnownPath(wellKnownPrefix, pathname = '', options = {}) { + // Strip trailing slash from pathname to avoid double slashes + if (pathname.endsWith('/')) { + pathname = pathname.slice(0, -1); + } + return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`; +} +/** + * Tries to discover OAuth metadata at a specific URL + */ +async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) { + const headers = { + 'MCP-Protocol-Version': protocolVersion + }; + return await fetchWithCorsRetry(url, headers, fetchFn); +} +/** + * Determines if fallback to root discovery should be attempted + */ +function shouldAttemptFallback(response, pathname) { + return !response || (response.status >= 400 && response.status < 500 && pathname !== '/'); +} +/** + * Generic function for discovering OAuth metadata with fallback support + */ +async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) { + var _a, _b; + const issuer = new URL(serverUrl); + const protocolVersion = (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : types_js_1.LATEST_PROTOCOL_VERSION; + let url; + if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) { + url = new URL(opts.metadataUrl); + } + else { + // Try path-aware discovery first + const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname); + url = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer); + url.search = issuer.search; + } + let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn); + // If path-aware discovery fails with 404 and we're not already at root, try fallback to root discovery + if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) { + const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer); + response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn); + } + return response; +} +/** + * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + * + * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`. + */ +async function discoverOAuthMetadata(issuer, { authorizationServerUrl, protocolVersion } = {}, fetchFn = fetch) { + var _a, _b; + if (typeof issuer === 'string') { + issuer = new URL(issuer); + } + if (!authorizationServerUrl) { + authorizationServerUrl = issuer; + } + if (typeof authorizationServerUrl === 'string') { + authorizationServerUrl = new URL(authorizationServerUrl); + } + protocolVersion !== null && protocolVersion !== void 0 ? protocolVersion : (protocolVersion = types_js_1.LATEST_PROTOCOL_VERSION); + const response = await discoverMetadataWithFallback(authorizationServerUrl, 'oauth-authorization-server', fetchFn, { + protocolVersion, + metadataServerUrl: authorizationServerUrl + }); + if (!response || response.status === 404) { + await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + return undefined; + } + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`); + } + return auth_js_2.OAuthMetadataSchema.parse(await response.json()); +} +/** + * Builds a list of discovery URLs to try for authorization server metadata. + * URLs are returned in priority order: + * 1. OAuth metadata at the given URL + * 2. OIDC metadata endpoints at the given URL + */ +function buildDiscoveryUrls(authorizationServerUrl) { + const url = typeof authorizationServerUrl === 'string' ? new URL(authorizationServerUrl) : authorizationServerUrl; + const hasPath = url.pathname !== '/'; + const urlsToTry = []; + if (!hasPath) { + // Root path: https://example.com/.well-known/oauth-authorization-server + urlsToTry.push({ + url: new URL('/.well-known/oauth-authorization-server', url.origin), + type: 'oauth' + }); + // OIDC: https://example.com/.well-known/openid-configuration + urlsToTry.push({ + url: new URL(`/.well-known/openid-configuration`, url.origin), + type: 'oidc' + }); + return urlsToTry; + } + // Strip trailing slash from pathname to avoid double slashes + let pathname = url.pathname; + if (pathname.endsWith('/')) { + pathname = pathname.slice(0, -1); + } + // 1. OAuth metadata at the given URL + // Insert well-known before the path: https://example.com/.well-known/oauth-authorization-server/tenant1 + urlsToTry.push({ + url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin), + type: 'oauth' + }); + // 2. OIDC metadata endpoints + // RFC 8414 style: Insert /.well-known/openid-configuration before the path + urlsToTry.push({ + url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin), + type: 'oidc' + }); + // OIDC Discovery 1.0 style: Append /.well-known/openid-configuration after the path + urlsToTry.push({ + url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin), + type: 'oidc' + }); + return urlsToTry; +} +/** + * Discovers authorization server metadata with support for RFC 8414 OAuth 2.0 Authorization Server Metadata + * and OpenID Connect Discovery 1.0 specifications. + * + * This function implements a fallback strategy for authorization server discovery: + * 1. Attempts RFC 8414 OAuth metadata discovery first + * 2. If OAuth discovery fails, falls back to OpenID Connect Discovery + * + * @param authorizationServerUrl - The authorization server URL obtained from the MCP Server's + * protected resource metadata, or the MCP server's URL if the + * metadata was not found. + * @param options - Configuration options + * @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch + * @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION + * @returns Promise resolving to authorization server metadata, or undefined if discovery fails + */ +async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = types_js_1.LATEST_PROTOCOL_VERSION } = {}) { + var _a; + const headers = { + 'MCP-Protocol-Version': protocolVersion, + Accept: 'application/json' + }; + // Get the list of URLs to try + const urlsToTry = buildDiscoveryUrls(authorizationServerUrl); + // Try each URL in order + for (const { url: endpointUrl, type } of urlsToTry) { + const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn); + if (!response) { + /** + * CORS error occurred - don't throw as the endpoint may not allow CORS, + * continue trying other possible endpoints + */ + continue; + } + if (!response.ok) { + await ((_a = response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + // Continue looking for any 4xx response code. + if (response.status >= 400 && response.status < 500) { + continue; // Try next URL + } + throw new Error(`HTTP ${response.status} trying to load ${type === 'oauth' ? 'OAuth' : 'OpenID provider'} metadata from ${endpointUrl}`); + } + // Parse and validate based on type + if (type === 'oauth') { + return auth_js_2.OAuthMetadataSchema.parse(await response.json()); + } + else { + return auth_js_1.OpenIdProviderDiscoveryMetadataSchema.parse(await response.json()); + } + } + return undefined; +} +/** + * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL. + */ +async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) { + let authorizationUrl; + if (metadata) { + authorizationUrl = new URL(metadata.authorization_endpoint); + if (!metadata.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) { + throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`); + } + if (metadata.code_challenge_methods_supported && + !metadata.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) { + throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`); + } + } + else { + authorizationUrl = new URL('/authorize', authorizationServerUrl); + } + // Generate PKCE challenge + const challenge = await (0, pkce_challenge_1.default)(); + const codeVerifier = challenge.code_verifier; + const codeChallenge = challenge.code_challenge; + authorizationUrl.searchParams.set('response_type', AUTHORIZATION_CODE_RESPONSE_TYPE); + authorizationUrl.searchParams.set('client_id', clientInformation.client_id); + authorizationUrl.searchParams.set('code_challenge', codeChallenge); + authorizationUrl.searchParams.set('code_challenge_method', AUTHORIZATION_CODE_CHALLENGE_METHOD); + authorizationUrl.searchParams.set('redirect_uri', String(redirectUrl)); + if (state) { + authorizationUrl.searchParams.set('state', state); + } + if (scope) { + authorizationUrl.searchParams.set('scope', scope); + } + if (scope === null || scope === void 0 ? void 0 : scope.includes('offline_access')) { + // if the request includes the OIDC-only "offline_access" scope, + // we need to set the prompt to "consent" to ensure the user is prompted to grant offline access + // https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess + authorizationUrl.searchParams.append('prompt', 'consent'); + } + if (resource) { + authorizationUrl.searchParams.set('resource', resource.href); + } + return { authorizationUrl, codeVerifier }; +} +/** + * Prepares token request parameters for an authorization code exchange. + * + * This is the default implementation used by fetchToken when the provider + * doesn't implement prepareTokenRequest. + * + * @param authorizationCode - The authorization code received from the authorization endpoint + * @param codeVerifier - The PKCE code verifier + * @param redirectUri - The redirect URI used in the authorization request + * @returns URLSearchParams for the authorization_code grant + */ +function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) { + return new URLSearchParams({ + grant_type: 'authorization_code', + code: authorizationCode, + code_verifier: codeVerifier, + redirect_uri: String(redirectUri) + }); +} +/** + * Internal helper to execute a token request with the given parameters. + * Used by exchangeAuthorization, refreshAuthorization, and fetchToken. + */ +async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) { + var _a; + const tokenUrl = (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL('/token', authorizationServerUrl); + const headers = new Headers({ + 'Content-Type': 'application/x-www-form-urlencoded', + Accept: 'application/json' + }); + if (resource) { + tokenRequestParams.set('resource', resource.href); + } + if (addClientAuthentication) { + await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata); + } + else if (clientInformation) { + const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : []; + const authMethod = selectClientAuthMethod(clientInformation, supportedMethods); + applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams); + } + const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, { + method: 'POST', + headers, + body: tokenRequestParams + }); + if (!response.ok) { + throw await parseErrorResponse(response); + } + return auth_js_2.OAuthTokensSchema.parse(await response.json()); +} +/** + * Exchanges an authorization code for an access token with the given server. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Falls back to appropriate defaults when server metadata is unavailable + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, auth code, etc. + * @returns Promise resolving to OAuth tokens + * @throws {Error} When token exchange fails or authentication is invalid + */ +async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) { + const tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri); + return executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation, + addClientAuthentication, + resource, + fetchFn + }); +} +/** + * Exchange a refresh token for an updated access token. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Preserves the original refresh token if a new one is not returned + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, refresh token, etc. + * @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced) + * @throws {Error} When token refresh fails or authentication is invalid + */ +async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) { + const tokenRequestParams = new URLSearchParams({ + grant_type: 'refresh_token', + refresh_token: refreshToken + }); + const tokens = await executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation, + addClientAuthentication, + resource, + fetchFn + }); + // Preserve original refresh token if server didn't return a new one + return { refresh_token: refreshToken, ...tokens }; +} +/** + * Unified token fetching that works with any grant type via provider.prepareTokenRequest(). + * + * This function provides a single entry point for obtaining tokens regardless of the + * OAuth grant type. The provider's prepareTokenRequest() method determines which grant + * to use and supplies the grant-specific parameters. + * + * @param provider - OAuth client provider that implements prepareTokenRequest() + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration for the token request + * @returns Promise resolving to OAuth tokens + * @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails + * + * @example + * // Provider for client_credentials: + * class MyProvider implements OAuthClientProvider { + * prepareTokenRequest(scope) { + * const params = new URLSearchParams({ grant_type: 'client_credentials' }); + * if (scope) params.set('scope', scope); + * return params; + * } + * // ... other methods + * } + * + * const tokens = await fetchToken(provider, authServerUrl, { metadata }); + */ +async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) { + const scope = provider.clientMetadata.scope; + // Use provider's prepareTokenRequest if available, otherwise fall back to authorization_code + let tokenRequestParams; + if (provider.prepareTokenRequest) { + tokenRequestParams = await provider.prepareTokenRequest(scope); + } + // Default to authorization_code grant if no custom prepareTokenRequest + if (!tokenRequestParams) { + if (!authorizationCode) { + throw new Error('Either provider.prepareTokenRequest() or authorizationCode is required'); + } + if (!provider.redirectUrl) { + throw new Error('redirectUrl is required for authorization_code flow'); + } + const codeVerifier = await provider.codeVerifier(); + tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl); + } + const clientInformation = await provider.clientInformation(); + return executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation: clientInformation !== null && clientInformation !== void 0 ? clientInformation : undefined, + addClientAuthentication: provider.addClientAuthentication, + resource, + fetchFn + }); +} +/** + * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591. + */ +async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) { + let registrationUrl; + if (metadata) { + if (!metadata.registration_endpoint) { + throw new Error('Incompatible auth server: does not support dynamic client registration'); + } + registrationUrl = new URL(metadata.registration_endpoint); + } + else { + registrationUrl = new URL('/register', authorizationServerUrl); + } + const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(registrationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(clientMetadata) + }); + if (!response.ok) { + throw await parseErrorResponse(response); + } + return auth_js_2.OAuthClientInformationFullSchema.parse(await response.json()); +} +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/dist/cjs/client/auth.js.map b/dist/cjs/client/auth.js.map new file mode 100644 index 000000000..e6142a486 --- /dev/null +++ b/dist/cjs/client/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/client/auth.ts"],"names":[],"mappings":";;;;;;AA8NA,wDAiCC;AA+ED,gDAcC;AAQD,oBAyBC;AAsJD,gCAQC;AAED,8CAuBC;AAKD,oEA8BC;AA8BD,gEAsBC;AAQD,wFAoBC;AAgGD,sDAsCC;AAQD,gDAgDC;AAkBD,kFAkDC;AAKD,gDAmEC;AAaD,0EAWC;AAoED,sDAgCC;AAcD,oDAkCC;AA4BD,gCA8CC;AAKD,wCAqCC;AAjxCD,oEAA2C;AAC3C,0CAAsD;AACtD,+CAW2B;AAC3B,+CAK2B;AAC3B,2DAAyF;AACzF,wDAQkC;AAsKlC,MAAa,iBAAkB,SAAQ,KAAK;IACxC,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,CAAC,CAAC;IACrC,CAAC;CACJ;AAJD,8CAIC;AAID,SAAS,kBAAkB,CAAC,MAAc;IACtC,OAAO,CAAC,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAChD,MAAM,mCAAmC,GAAG,MAAM,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,SAAgB,sBAAsB,CAAC,iBAA8C,EAAE,gBAA0B;IAC7G,MAAM,eAAe,GAAG,iBAAiB,CAAC,aAAa,KAAK,SAAS,CAAC;IAEtE,qEAAqE;IACrE,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,eAAe,CAAC,CAAC,CAAC,oBAAoB,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/dist/cjs/client/index.d.ts b/dist/cjs/client/index.d.ts new file mode 100644 index 000000000..cb81a4123 --- /dev/null +++ b/dist/cjs/client/index.d.ts @@ -0,0 +1,481 @@ +import { Protocol, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js'; +import type { Transport } from '../shared/transport.js'; +import { type CallToolRequest, CallToolResultSchema, type ClientCapabilities, type ClientNotification, type ClientRequest, type ClientResult, type CompatibilityCallToolResultSchema, type CompleteRequest, type GetPromptRequest, type Implementation, type ListPromptsRequest, type ListResourcesRequest, type ListResourceTemplatesRequest, type ListToolsRequest, type LoggingLevel, type Notification, type ReadResourceRequest, type Request, type Result, type ServerCapabilities, type SubscribeRequest, type UnsubscribeRequest } from '../types.js'; +import type { jsonSchemaValidator } from '../validation/types.js'; +import { AnyObjectSchema, SchemaOutput } from '../server/zod-compat.js'; +import type { RequestHandlerExtra } from '../shared/protocol.js'; +import { ExperimentalClientTasks } from '../experimental/tasks/client.js'; +/** + * Determines which elicitation modes are supported based on declared client capabilities. + * + * According to the spec: + * - An empty elicitation capability object defaults to form mode support (backwards compatibility) + * - URL mode is only supported if explicitly declared + * + * @param capabilities - The client's elicitation capabilities + * @returns An object indicating which modes are supported + */ +export declare function getSupportedElicitationModes(capabilities: ClientCapabilities['elicitation']): { + supportsFormMode: boolean; + supportsUrlMode: boolean; +}; +export type ClientOptions = ProtocolOptions & { + /** + * Capabilities to advertise as being supported by this client. + */ + capabilities?: ClientCapabilities; + /** + * JSON Schema validator for tool output validation. + * + * The validator is used to validate structured content returned by tools + * against their declared output schemas. + * + * @default AjvJsonSchemaValidator + * + * @example + * ```typescript + * // ajv + * const client = new Client( + * { name: 'my-client', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new AjvJsonSchemaValidator() + * } + * ); + * + * // @cfworker/json-schema + * const client = new Client( + * { name: 'my-client', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new CfWorkerJsonSchemaValidator() + * } + * ); + * ``` + */ + jsonSchemaValidator?: jsonSchemaValidator; +}; +/** + * An MCP client on top of a pluggable transport. + * + * The client will automatically begin the initialization flow with the server when connect() is called. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed client + * const client = new Client({ + * name: "CustomClient", + * version: "1.0.0" + * }) + * ``` + */ +export declare class Client extends Protocol { + private _clientInfo; + private _serverCapabilities?; + private _serverVersion?; + private _capabilities; + private _instructions?; + private _jsonSchemaValidator; + private _cachedToolOutputValidators; + private _cachedKnownTaskTools; + private _cachedRequiredTaskTools; + private _experimental?; + /** + * Initializes this client with the given name and version information. + */ + constructor(_clientInfo: Implementation, options?: ClientOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalClientTasks; + }; + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities: ClientCapabilities): void; + /** + * Override request handler registration to enforce client-side validation for elicitation. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => ClientResult | ResultT | Promise): void; + protected assertCapability(capability: keyof ServerCapabilities, method: string): void; + connect(transport: Transport, options?: RequestOptions): Promise; + /** + * After initialization has completed, this will be populated with the server's reported capabilities. + */ + getServerCapabilities(): ServerCapabilities | undefined; + /** + * After initialization has completed, this will be populated with information about the server's name and version. + */ + getServerVersion(): Implementation | undefined; + /** + * After initialization has completed, this may be populated with information about the server's instructions. + */ + getInstructions(): string | undefined; + protected assertCapabilityForMethod(method: RequestT['method']): void; + protected assertNotificationCapability(method: NotificationT['method']): void; + protected assertRequestHandlerCapability(method: string): void; + protected assertTaskCapability(method: string): void; + protected assertTaskHandlerCapability(method: string): void; + ping(options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + complete(params: CompleteRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + completion: { + [x: string]: unknown; + values: string[]; + total?: number | undefined; + hasMore?: boolean | undefined; + }; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + setLoggingLevel(level: LoggingLevel, options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + getPrompt(params: GetPromptRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + messages: { + role: "user" | "assistant"; + content: { + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + description?: string | undefined; + }>; + listPrompts(params?: ListPromptsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + prompts: { + name: string; + description?: string | undefined; + arguments?: { + name: string; + description?: string | undefined; + required?: boolean | undefined; + }[] | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + listResources(params?: ListResourcesRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + resources: { + uri: string; + name: string; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + listResourceTemplates(params?: ListResourceTemplatesRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + resourceTemplates: { + uriTemplate: string; + name: string; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + readResource(params: ReadResourceRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + contents: ({ + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + subscribeResource(params: SubscribeRequest['params'], options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + unsubscribeResource(params: UnsubscribeRequest['params'], options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + /** + * Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema. + * + * For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead. + */ + callTool(params: CallToolRequest['params'], resultSchema?: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema, options?: RequestOptions): Promise<{ + [x: string]: unknown; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + structuredContent?: Record | undefined; + isError?: boolean | undefined; + } | { + [x: string]: unknown; + toolResult: unknown; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + private isToolTask; + /** + * Check if a tool requires task-based execution. + * Unlike isToolTask which includes 'optional' tools, this only checks for 'required'. + */ + private isToolTaskRequired; + /** + * Cache validators for tool output schemas. + * Called after listTools() to pre-compile validators for better performance. + */ + private cacheToolMetadata; + /** + * Get cached validator for a tool + */ + private getToolOutputValidator; + listTools(params?: ListToolsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + tools: { + inputSchema: { + [x: string]: unknown; + type: "object"; + properties?: Record | undefined; + required?: string[] | undefined; + }; + name: string; + description?: string | undefined; + outputSchema?: { + [x: string]: unknown; + type: "object"; + properties?: Record | undefined; + required?: string[] | undefined; + } | undefined; + annotations?: { + title?: string | undefined; + readOnlyHint?: boolean | undefined; + destructiveHint?: boolean | undefined; + idempotentHint?: boolean | undefined; + openWorldHint?: boolean | undefined; + } | undefined; + execution?: { + taskSupport?: "optional" | "required" | "forbidden" | undefined; + } | undefined; + _meta?: Record | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + sendRootsListChanged(): Promise; +} +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/index.d.ts.map b/dist/cjs/client/index.d.ts.map new file mode 100644 index 000000000..a0df292e3 --- /dev/null +++ b/dist/cjs/client/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACH,KAAK,eAAe,EACpB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iCAAiC,EACtC,KAAK,eAAe,EAIpB,KAAK,gBAAgB,EAErB,KAAK,cAAc,EAGnB,KAAK,kBAAkB,EAEvB,KAAK,oBAAoB,EAEzB,KAAK,4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AAmB,CAAC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;IAIxF;;;;OAIG;IACG,QAAQ,CACV,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,EACjC,YAAY,GAAE,OAAO,oBAAoB,GAAG,OAAO,iCAAwD,EAC3G,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkD5B,OAAO,CAAC,UAAU;IAQlB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAuBzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAIxB,SAAS,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IASvE,oBAAoB;CAG7B"} \ No newline at end of file diff --git a/dist/cjs/client/index.js b/dist/cjs/client/index.js new file mode 100644 index 000000000..6bfeb70f3 --- /dev/null +++ b/dist/cjs/client/index.js @@ -0,0 +1,546 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Client = void 0; +exports.getSupportedElicitationModes = getSupportedElicitationModes; +const protocol_js_1 = require("../shared/protocol.js"); +const types_js_1 = require("../types.js"); +const ajv_provider_js_1 = require("../validation/ajv-provider.js"); +const zod_compat_js_1 = require("../server/zod-compat.js"); +const client_js_1 = require("../experimental/tasks/client.js"); +const helpers_js_1 = require("../experimental/tasks/helpers.js"); +/** + * Elicitation default application helper. Applies defaults to the data based on the schema. + * + * @param schema - The schema to apply defaults to. + * @param data - The data to apply defaults to. + */ +function applyElicitationDefaults(schema, data) { + if (!schema || data === null || typeof data !== 'object') + return; + // Handle object properties + if (schema.type === 'object' && schema.properties && typeof schema.properties === 'object') { + const obj = data; + const props = schema.properties; + for (const key of Object.keys(props)) { + const propSchema = props[key]; + // If missing or explicitly undefined, apply default if present + if (obj[key] === undefined && Object.prototype.hasOwnProperty.call(propSchema, 'default')) { + obj[key] = propSchema.default; + } + // Recurse into existing nested objects/arrays + if (obj[key] !== undefined) { + applyElicitationDefaults(propSchema, obj[key]); + } + } + } + if (Array.isArray(schema.anyOf)) { + for (const sub of schema.anyOf) { + applyElicitationDefaults(sub, data); + } + } + // Combine schemas + if (Array.isArray(schema.oneOf)) { + for (const sub of schema.oneOf) { + applyElicitationDefaults(sub, data); + } + } +} +/** + * Determines which elicitation modes are supported based on declared client capabilities. + * + * According to the spec: + * - An empty elicitation capability object defaults to form mode support (backwards compatibility) + * - URL mode is only supported if explicitly declared + * + * @param capabilities - The client's elicitation capabilities + * @returns An object indicating which modes are supported + */ +function getSupportedElicitationModes(capabilities) { + if (!capabilities) { + return { supportsFormMode: false, supportsUrlMode: false }; + } + const hasFormCapability = capabilities.form !== undefined; + const hasUrlCapability = capabilities.url !== undefined; + // If neither form nor url are explicitly declared, form mode is supported (backwards compatibility) + const supportsFormMode = hasFormCapability || (!hasFormCapability && !hasUrlCapability); + const supportsUrlMode = hasUrlCapability; + return { supportsFormMode, supportsUrlMode }; +} +/** + * An MCP client on top of a pluggable transport. + * + * The client will automatically begin the initialization flow with the server when connect() is called. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed client + * const client = new Client({ + * name: "CustomClient", + * version: "1.0.0" + * }) + * ``` + */ +class Client extends protocol_js_1.Protocol { + /** + * Initializes this client with the given name and version information. + */ + constructor(_clientInfo, options) { + var _a, _b; + super(options); + this._clientInfo = _clientInfo; + this._cachedToolOutputValidators = new Map(); + this._cachedKnownTaskTools = new Set(); + this._cachedRequiredTaskTools = new Set(); + this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {}; + this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new ajv_provider_js_1.AjvJsonSchemaValidator(); + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new client_js_1.ExperimentalClientTasks(this) + }; + } + return this._experimental; + } + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities) { + if (this.transport) { + throw new Error('Cannot register capabilities after connecting to transport'); + } + this._capabilities = (0, protocol_js_1.mergeCapabilities)(this._capabilities, capabilities); + } + /** + * Override request handler registration to enforce client-side validation for elicitation. + */ + setRequestHandler(requestSchema, handler) { + var _a, _b, _c; + const shape = (0, zod_compat_js_1.getObjectShape)(requestSchema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value using type-safe property access + let methodValue; + if ((0, zod_compat_js_1.isZ4Schema)(methodSchema)) { + const v4Schema = methodSchema; + const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + methodValue = (_b = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b !== void 0 ? _b : v4Schema.value; + } + else { + const v3Schema = methodSchema; + const legacyDef = v3Schema._def; + methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value; + } + if (typeof methodValue !== 'string') { + throw new Error('Schema method literal must be a string'); + } + const method = methodValue; + if (method === 'elicitation/create') { + const wrappedHandler = async (request, extra) => { + var _a, _b, _c; + const validatedRequest = (0, zod_compat_js_1.safeParse)(types_js_1.ElicitRequestSchema, request); + if (!validatedRequest.success) { + // Type guard: if success is false, error is guaranteed to exist + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : 'form'; + const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation); + if (mode === 'form' && !supportsFormMode) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, 'Client does not support form-mode elicitation requests'); + } + if (mode === 'url' && !supportsUrlMode) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, 'Client does not support URL-mode elicitation requests'); + } + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = (0, zod_compat_js_1.safeParse)(types_js_1.CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against ElicitResultSchema + const validationResult = (0, zod_compat_js_1.safeParse)(types_js_1.ElicitResultSchema, result); + if (!validationResult.success) { + // Type guard: if success is false, error is guaranteed to exist + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`); + } + const validatedResult = validationResult.data; + const requestedSchema = mode === 'form' ? params.requestedSchema : undefined; + if (mode === 'form' && validatedResult.action === 'accept' && validatedResult.content && requestedSchema) { + if ((_c = (_b = this._capabilities.elicitation) === null || _b === void 0 ? void 0 : _b.form) === null || _c === void 0 ? void 0 : _c.applyDefaults) { + try { + applyElicitationDefaults(requestedSchema, validatedResult.content); + } + catch (_d) { + // gracefully ignore errors in default application + } + } + } + return validatedResult; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + if (method === 'sampling/createMessage') { + const wrappedHandler = async (request, extra) => { + const validatedRequest = (0, zod_compat_js_1.safeParse)(types_js_1.CreateMessageRequestSchema, request); + if (!validatedRequest.success) { + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = (0, zod_compat_js_1.safeParse)(types_js_1.CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against CreateMessageResultSchema + const validationResult = (0, zod_compat_js_1.safeParse)(types_js_1.CreateMessageResultSchema, result); + if (!validationResult.success) { + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`); + } + return validationResult.data; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + // Other handlers use default behavior + return super.setRequestHandler(requestSchema, handler); + } + assertCapability(capability, method) { + var _a; + if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) { + throw new Error(`Server does not support ${capability} (required for ${method})`); + } + } + async connect(transport, options) { + await super.connect(transport); + // When transport sessionId is already set this means we are trying to reconnect. + // In this case we don't need to initialize again. + if (transport.sessionId !== undefined) { + return; + } + try { + const result = await this.request({ + method: 'initialize', + params: { + protocolVersion: types_js_1.LATEST_PROTOCOL_VERSION, + capabilities: this._capabilities, + clientInfo: this._clientInfo + } + }, types_js_1.InitializeResultSchema, options); + if (result === undefined) { + throw new Error(`Server sent invalid initialize result: ${result}`); + } + if (!types_js_1.SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) { + throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`); + } + this._serverCapabilities = result.capabilities; + this._serverVersion = result.serverInfo; + // HTTP transports must set the protocol version in each header after initialization. + if (transport.setProtocolVersion) { + transport.setProtocolVersion(result.protocolVersion); + } + this._instructions = result.instructions; + await this.notification({ + method: 'notifications/initialized' + }); + } + catch (error) { + // Disconnect if initialization fails. + void this.close(); + throw error; + } + } + /** + * After initialization has completed, this will be populated with the server's reported capabilities. + */ + getServerCapabilities() { + return this._serverCapabilities; + } + /** + * After initialization has completed, this will be populated with information about the server's name and version. + */ + getServerVersion() { + return this._serverVersion; + } + /** + * After initialization has completed, this may be populated with information about the server's instructions. + */ + getInstructions() { + return this._instructions; + } + assertCapabilityForMethod(method) { + var _a, _b, _c, _d, _e; + switch (method) { + case 'logging/setLevel': + if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.logging)) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'prompts/get': + case 'prompts/list': + if (!((_b = this._serverCapabilities) === null || _b === void 0 ? void 0 : _b.prompts)) { + throw new Error(`Server does not support prompts (required for ${method})`); + } + break; + case 'resources/list': + case 'resources/templates/list': + case 'resources/read': + case 'resources/subscribe': + case 'resources/unsubscribe': + if (!((_c = this._serverCapabilities) === null || _c === void 0 ? void 0 : _c.resources)) { + throw new Error(`Server does not support resources (required for ${method})`); + } + if (method === 'resources/subscribe' && !this._serverCapabilities.resources.subscribe) { + throw new Error(`Server does not support resource subscriptions (required for ${method})`); + } + break; + case 'tools/call': + case 'tools/list': + if (!((_d = this._serverCapabilities) === null || _d === void 0 ? void 0 : _d.tools)) { + throw new Error(`Server does not support tools (required for ${method})`); + } + break; + case 'completion/complete': + if (!((_e = this._serverCapabilities) === null || _e === void 0 ? void 0 : _e.completions)) { + throw new Error(`Server does not support completions (required for ${method})`); + } + break; + case 'initialize': + // No specific capability required for initialize + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertNotificationCapability(method) { + var _a; + switch (method) { + case 'notifications/roots/list_changed': + if (!((_a = this._capabilities.roots) === null || _a === void 0 ? void 0 : _a.listChanged)) { + throw new Error(`Client does not support roots list changed notifications (required for ${method})`); + } + break; + case 'notifications/initialized': + // No specific capability required for initialized + break; + case 'notifications/cancelled': + // Cancellation notifications are always allowed + break; + case 'notifications/progress': + // Progress notifications are always allowed + break; + } + } + assertRequestHandlerCapability(method) { + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + switch (method) { + case 'sampling/createMessage': + if (!this._capabilities.sampling) { + throw new Error(`Client does not support sampling capability (required for ${method})`); + } + break; + case 'elicitation/create': + if (!this._capabilities.elicitation) { + throw new Error(`Client does not support elicitation capability (required for ${method})`); + } + break; + case 'roots/list': + if (!this._capabilities.roots) { + throw new Error(`Client does not support roots capability (required for ${method})`); + } + break; + case 'tasks/get': + case 'tasks/list': + case 'tasks/result': + case 'tasks/cancel': + if (!this._capabilities.tasks) { + throw new Error(`Client does not support tasks capability (required for ${method})`); + } + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertTaskCapability(method) { + var _a, _b; + (0, helpers_js_1.assertToolsCallTaskCapability)((_b = (_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests, method, 'Server'); + } + assertTaskHandlerCapability(method) { + var _a; + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + (0, helpers_js_1.assertClientRequestTaskCapability)((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, 'Client'); + } + async ping(options) { + return this.request({ method: 'ping' }, types_js_1.EmptyResultSchema, options); + } + async complete(params, options) { + return this.request({ method: 'completion/complete', params }, types_js_1.CompleteResultSchema, options); + } + async setLoggingLevel(level, options) { + return this.request({ method: 'logging/setLevel', params: { level } }, types_js_1.EmptyResultSchema, options); + } + async getPrompt(params, options) { + return this.request({ method: 'prompts/get', params }, types_js_1.GetPromptResultSchema, options); + } + async listPrompts(params, options) { + return this.request({ method: 'prompts/list', params }, types_js_1.ListPromptsResultSchema, options); + } + async listResources(params, options) { + return this.request({ method: 'resources/list', params }, types_js_1.ListResourcesResultSchema, options); + } + async listResourceTemplates(params, options) { + return this.request({ method: 'resources/templates/list', params }, types_js_1.ListResourceTemplatesResultSchema, options); + } + async readResource(params, options) { + return this.request({ method: 'resources/read', params }, types_js_1.ReadResourceResultSchema, options); + } + async subscribeResource(params, options) { + return this.request({ method: 'resources/subscribe', params }, types_js_1.EmptyResultSchema, options); + } + async unsubscribeResource(params, options) { + return this.request({ method: 'resources/unsubscribe', params }, types_js_1.EmptyResultSchema, options); + } + /** + * Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema. + * + * For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead. + */ + async callTool(params, resultSchema = types_js_1.CallToolResultSchema, options) { + // Guard: required-task tools need experimental API + if (this.isToolTaskRequired(params.name)) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`); + } + const result = await this.request({ method: 'tools/call', params }, resultSchema, options); + // Check if the tool has an outputSchema + const validator = this.getToolOutputValidator(params.name); + if (validator) { + // If tool has outputSchema, it MUST return structuredContent (unless it's an error) + if (!result.structuredContent && !result.isError) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`); + } + // Only validate structured content if present (not when there's an error) + if (result.structuredContent) { + try { + // Validate the structured content against the schema + const validationResult = validator(result.structuredContent); + if (!validationResult.valid) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`); + } + } + catch (error) { + if (error instanceof types_js_1.McpError) { + throw error; + } + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`); + } + } + } + return result; + } + isToolTask(toolName) { + var _a, _b, _c, _d; + if (!((_d = (_c = (_b = (_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests) === null || _c === void 0 ? void 0 : _c.tools) === null || _d === void 0 ? void 0 : _d.call)) { + return false; + } + return this._cachedKnownTaskTools.has(toolName); + } + /** + * Check if a tool requires task-based execution. + * Unlike isToolTask which includes 'optional' tools, this only checks for 'required'. + */ + isToolTaskRequired(toolName) { + return this._cachedRequiredTaskTools.has(toolName); + } + /** + * Cache validators for tool output schemas. + * Called after listTools() to pre-compile validators for better performance. + */ + cacheToolMetadata(tools) { + var _a; + this._cachedToolOutputValidators.clear(); + this._cachedKnownTaskTools.clear(); + this._cachedRequiredTaskTools.clear(); + for (const tool of tools) { + // If the tool has an outputSchema, create and cache the validator + if (tool.outputSchema) { + const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema); + this._cachedToolOutputValidators.set(tool.name, toolValidator); + } + // If the tool supports task-based execution, cache that information + const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport; + if (taskSupport === 'required' || taskSupport === 'optional') { + this._cachedKnownTaskTools.add(tool.name); + } + if (taskSupport === 'required') { + this._cachedRequiredTaskTools.add(tool.name); + } + } + } + /** + * Get cached validator for a tool + */ + getToolOutputValidator(toolName) { + return this._cachedToolOutputValidators.get(toolName); + } + async listTools(params, options) { + const result = await this.request({ method: 'tools/list', params }, types_js_1.ListToolsResultSchema, options); + // Cache the tools and their output schemas for future validation + this.cacheToolMetadata(result.tools); + return result; + } + async sendRootsListChanged() { + return this.notification({ method: 'notifications/roots/list_changed' }); + } +} +exports.Client = Client; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/client/index.js.map b/dist/cjs/client/index.js.map new file mode 100644 index 000000000..98ef92e97 --- /dev/null +++ b/dist/cjs/client/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":";;;AA+GA,oEAgBC;AA/HD,uDAA+G;AAG/G,0CA0CqB;AACrB,mEAAuE;AAEvE,2DAQiC;AAEjC,+DAA0E;AAC1E,iEAAoH;AAEpH;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,MAAkC,EAAE,IAAa;IAC/E,IAAI,CAAC,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO;IAEjE,2BAA2B;IAC3B,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACzF,MAAM,GAAG,GAAG,IAA+B,CAAC;QAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,UAAoE,CAAC;QAC1F,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,+DAA+D;YAC/D,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC;gBACxF,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC;YAClC,CAAC;YACD,8CAA8C;YAC9C,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBACzB,wBAAwB,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACnD,CAAC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GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACK,sBAAsB,CAAC,QAAgB;QAC3C,OAAO,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAmC,EAAE,OAAwB;QACzE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,gCAAqB,EAAE,OAAO,CAAC,CAAC;QAEpG,iEAAiE;QACjE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,oBAAoB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,kCAAkC,EAAE,CAAC,CAAC;IAC7E,CAAC;CACJ;AA1jBD,wBA0jBC"} \ No newline at end of file diff --git a/dist/cjs/client/middleware.d.ts b/dist/cjs/client/middleware.d.ts new file mode 100644 index 000000000..726ac578a --- /dev/null +++ b/dist/cjs/client/middleware.d.ts @@ -0,0 +1,169 @@ +import { OAuthClientProvider } from './auth.js'; +import { FetchLike } from '../shared/transport.js'; +/** + * Middleware function that wraps and enhances fetch functionality. + * Takes a fetch handler and returns an enhanced fetch handler. + */ +export type Middleware = (next: FetchLike) => FetchLike; +/** + * Creates a fetch wrapper that handles OAuth authentication automatically. + * + * This wrapper will: + * - Add Authorization headers with access tokens + * - Handle 401 responses by attempting re-authentication + * - Retry the original request after successful auth + * - Handle OAuth errors appropriately (InvalidClientError, etc.) + * + * The baseUrl parameter is optional and defaults to using the domain from the request URL. + * However, you should explicitly provide baseUrl when: + * - Making requests to multiple subdomains (e.g., api.example.com, cdn.example.com) + * - Using API paths that differ from OAuth discovery paths (e.g., requesting /api/v1/data but OAuth is at /) + * - The OAuth server is on a different domain than your API requests + * - You want to ensure consistent OAuth behavior regardless of request URLs + * + * For MCP transports, set baseUrl to the same URL you pass to the transport constructor. + * + * Note: This wrapper is designed for general-purpose fetch operations. + * MCP transports (SSE and StreamableHTTP) already have built-in OAuth handling + * and should not need this wrapper. + * + * @param provider - OAuth client provider for authentication + * @param baseUrl - Base URL for OAuth server discovery (defaults to request URL domain) + * @returns A fetch middleware function + */ +export declare const withOAuth: (provider: OAuthClientProvider, baseUrl?: string | URL) => Middleware; +/** + * Logger function type for HTTP requests + */ +export type RequestLogger = (input: { + method: string; + url: string | URL; + status: number; + statusText: string; + duration: number; + requestHeaders?: Headers; + responseHeaders?: Headers; + error?: Error; +}) => void; +/** + * Configuration options for the logging middleware + */ +export type LoggingOptions = { + /** + * Custom logger function, defaults to console logging + */ + logger?: RequestLogger; + /** + * Whether to include request headers in logs + * @default false + */ + includeRequestHeaders?: boolean; + /** + * Whether to include response headers in logs + * @default false + */ + includeResponseHeaders?: boolean; + /** + * Status level filter - only log requests with status >= this value + * Set to 0 to log all requests, 400 to log only errors + * @default 0 + */ + statusLevel?: number; +}; +/** + * Creates a fetch middleware that logs HTTP requests and responses. + * + * When called without arguments `withLogging()`, it uses the default logger that: + * - Logs successful requests (2xx) to `console.log` + * - Logs error responses (4xx/5xx) and network errors to `console.error` + * - Logs all requests regardless of status (statusLevel: 0) + * - Does not include request or response headers in logs + * - Measures and displays request duration in milliseconds + * + * Important: the default logger uses both `console.log` and `console.error` so it should not be used with + * `stdio` transports and applications. + * + * @param options - Logging configuration options + * @returns A fetch middleware function + */ +export declare const withLogging: (options?: LoggingOptions) => Middleware; +/** + * Composes multiple fetch middleware functions into a single middleware pipeline. + * Middleware are applied in the order they appear, creating a chain of handlers. + * + * @example + * ```typescript + * // Create a middleware pipeline that handles both OAuth and logging + * const enhancedFetch = applyMiddlewares( + * withOAuth(oauthProvider, 'https://api.example.com'), + * withLogging({ statusLevel: 400 }) + * )(fetch); + * + * // Use the enhanced fetch - it will handle auth and log errors + * const response = await enhancedFetch('https://api.example.com/data'); + * ``` + * + * @param middleware - Array of fetch middleware to compose into a pipeline + * @returns A single composed middleware function + */ +export declare const applyMiddlewares: (...middleware: Middleware[]) => Middleware; +/** + * Helper function to create custom fetch middleware with cleaner syntax. + * Provides the next handler and request details as separate parameters for easier access. + * + * @example + * ```typescript + * // Create custom authentication middleware + * const customAuthMiddleware = createMiddleware(async (next, input, init) => { + * const headers = new Headers(init?.headers); + * headers.set('X-Custom-Auth', 'my-token'); + * + * const response = await next(input, { ...init, headers }); + * + * if (response.status === 401) { + * console.log('Authentication failed'); + * } + * + * return response; + * }); + * + * // Create conditional middleware + * const conditionalMiddleware = createMiddleware(async (next, input, init) => { + * const url = typeof input === 'string' ? input : input.toString(); + * + * // Only add headers for API routes + * if (url.includes('/api/')) { + * const headers = new Headers(init?.headers); + * headers.set('X-API-Version', 'v2'); + * return next(input, { ...init, headers }); + * } + * + * // Pass through for non-API routes + * return next(input, init); + * }); + * + * // Create caching middleware + * const cacheMiddleware = createMiddleware(async (next, input, init) => { + * const cacheKey = typeof input === 'string' ? input : input.toString(); + * + * // Check cache first + * const cached = await getFromCache(cacheKey); + * if (cached) { + * return new Response(cached, { status: 200 }); + * } + * + * // Make request and cache result + * const response = await next(input, init); + * if (response.ok) { + * await saveToCache(cacheKey, await response.clone().text()); + * } + * + * return response; + * }); + * ``` + * + * @param handler - Function that receives the next handler and request parameters + * @returns A fetch middleware function + */ +export declare const createMiddleware: (handler: (next: FetchLike, input: string | URL, init?: RequestInit) => Promise) => Middleware; +//# sourceMappingURL=middleware.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/middleware.d.ts.map b/dist/cjs/client/middleware.d.ts.map new file mode 100644 index 000000000..88ac77806 --- /dev/null +++ b/dist/cjs/client/middleware.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,mBAAmB,EA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AE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,KAAG,UAE3H,CAAC"} \ No newline at end of file diff --git a/dist/cjs/client/middleware.js b/dist/cjs/client/middleware.js new file mode 100644 index 000000000..f5d9dc3ae --- /dev/null +++ b/dist/cjs/client/middleware.js @@ -0,0 +1,252 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createMiddleware = exports.applyMiddlewares = exports.withLogging = exports.withOAuth = void 0; +const auth_js_1 = require("./auth.js"); +/** + * Creates a fetch wrapper that handles OAuth authentication automatically. + * + * This wrapper will: + * - Add Authorization headers with access tokens + * - Handle 401 responses by attempting re-authentication + * - Retry the original request after successful auth + * - Handle OAuth errors appropriately (InvalidClientError, etc.) + * + * The baseUrl parameter is optional and defaults to using the domain from the request URL. + * However, you should explicitly provide baseUrl when: + * - Making requests to multiple subdomains (e.g., api.example.com, cdn.example.com) + * - Using API paths that differ from OAuth discovery paths (e.g., requesting /api/v1/data but OAuth is at /) + * - The OAuth server is on a different domain than your API requests + * - You want to ensure consistent OAuth behavior regardless of request URLs + * + * For MCP transports, set baseUrl to the same URL you pass to the transport constructor. + * + * Note: This wrapper is designed for general-purpose fetch operations. + * MCP transports (SSE and StreamableHTTP) already have built-in OAuth handling + * and should not need this wrapper. + * + * @param provider - OAuth client provider for authentication + * @param baseUrl - Base URL for OAuth server discovery (defaults to request URL domain) + * @returns A fetch middleware function + */ +const withOAuth = (provider, baseUrl) => next => { + return async (input, init) => { + const makeRequest = async () => { + const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers); + // Add authorization header if tokens are available + const tokens = await provider.tokens(); + if (tokens) { + headers.set('Authorization', `Bearer ${tokens.access_token}`); + } + return await next(input, { ...init, headers }); + }; + let response = await makeRequest(); + // Handle 401 responses by attempting re-authentication + if (response.status === 401) { + try { + const { resourceMetadataUrl, scope } = (0, auth_js_1.extractWWWAuthenticateParams)(response); + // Use provided baseUrl or extract from request URL + const serverUrl = baseUrl || (typeof input === 'string' ? new URL(input).origin : input.origin); + const result = await (0, auth_js_1.auth)(provider, { + serverUrl, + resourceMetadataUrl, + scope, + fetchFn: next + }); + if (result === 'REDIRECT') { + throw new auth_js_1.UnauthorizedError('Authentication requires user authorization - redirect initiated'); + } + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(`Authentication failed with result: ${result}`); + } + // Retry the request with fresh tokens + response = await makeRequest(); + } + catch (error) { + if (error instanceof auth_js_1.UnauthorizedError) { + throw error; + } + throw new auth_js_1.UnauthorizedError(`Failed to re-authenticate: ${error instanceof Error ? error.message : String(error)}`); + } + } + // If we still have a 401 after re-auth attempt, throw an error + if (response.status === 401) { + const url = typeof input === 'string' ? input : input.toString(); + throw new auth_js_1.UnauthorizedError(`Authentication failed for ${url}`); + } + return response; + }; +}; +exports.withOAuth = withOAuth; +/** + * Creates a fetch middleware that logs HTTP requests and responses. + * + * When called without arguments `withLogging()`, it uses the default logger that: + * - Logs successful requests (2xx) to `console.log` + * - Logs error responses (4xx/5xx) and network errors to `console.error` + * - Logs all requests regardless of status (statusLevel: 0) + * - Does not include request or response headers in logs + * - Measures and displays request duration in milliseconds + * + * Important: the default logger uses both `console.log` and `console.error` so it should not be used with + * `stdio` transports and applications. + * + * @param options - Logging configuration options + * @returns A fetch middleware function + */ +const withLogging = (options = {}) => { + const { logger, includeRequestHeaders = false, includeResponseHeaders = false, statusLevel = 0 } = options; + const defaultLogger = input => { + const { method, url, status, statusText, duration, requestHeaders, responseHeaders, error } = input; + let message = error + ? `HTTP ${method} ${url} failed: ${error.message} (${duration}ms)` + : `HTTP ${method} ${url} ${status} ${statusText} (${duration}ms)`; + // Add headers to message if requested + if (includeRequestHeaders && requestHeaders) { + const reqHeaders = Array.from(requestHeaders.entries()) + .map(([key, value]) => `${key}: ${value}`) + .join(', '); + message += `\n Request Headers: {${reqHeaders}}`; + } + if (includeResponseHeaders && responseHeaders) { + const resHeaders = Array.from(responseHeaders.entries()) + .map(([key, value]) => `${key}: ${value}`) + .join(', '); + message += `\n Response Headers: {${resHeaders}}`; + } + if (error || status >= 400) { + // eslint-disable-next-line no-console + console.error(message); + } + else { + // eslint-disable-next-line no-console + console.log(message); + } + }; + const logFn = logger || defaultLogger; + return next => async (input, init) => { + const startTime = performance.now(); + const method = (init === null || init === void 0 ? void 0 : init.method) || 'GET'; + const url = typeof input === 'string' ? input : input.toString(); + const requestHeaders = includeRequestHeaders ? new Headers(init === null || init === void 0 ? void 0 : init.headers) : undefined; + try { + const response = await next(input, init); + const duration = performance.now() - startTime; + // Only log if status meets the log level threshold + if (response.status >= statusLevel) { + logFn({ + method, + url, + status: response.status, + statusText: response.statusText, + duration, + requestHeaders, + responseHeaders: includeResponseHeaders ? response.headers : undefined + }); + } + return response; + } + catch (error) { + const duration = performance.now() - startTime; + // Always log errors regardless of log level + logFn({ + method, + url, + status: 0, + statusText: 'Network Error', + duration, + requestHeaders, + error: error + }); + throw error; + } + }; +}; +exports.withLogging = withLogging; +/** + * Composes multiple fetch middleware functions into a single middleware pipeline. + * Middleware are applied in the order they appear, creating a chain of handlers. + * + * @example + * ```typescript + * // Create a middleware pipeline that handles both OAuth and logging + * const enhancedFetch = applyMiddlewares( + * withOAuth(oauthProvider, 'https://api.example.com'), + * withLogging({ statusLevel: 400 }) + * )(fetch); + * + * // Use the enhanced fetch - it will handle auth and log errors + * const response = await enhancedFetch('https://api.example.com/data'); + * ``` + * + * @param middleware - Array of fetch middleware to compose into a pipeline + * @returns A single composed middleware function + */ +const applyMiddlewares = (...middleware) => { + return next => { + return middleware.reduce((handler, mw) => mw(handler), next); + }; +}; +exports.applyMiddlewares = applyMiddlewares; +/** + * Helper function to create custom fetch middleware with cleaner syntax. + * Provides the next handler and request details as separate parameters for easier access. + * + * @example + * ```typescript + * // Create custom authentication middleware + * const customAuthMiddleware = createMiddleware(async (next, input, init) => { + * const headers = new Headers(init?.headers); + * headers.set('X-Custom-Auth', 'my-token'); + * + * const response = await next(input, { ...init, headers }); + * + * if (response.status === 401) { + * console.log('Authentication failed'); + * } + * + * return response; + * }); + * + * // Create conditional middleware + * const conditionalMiddleware = createMiddleware(async (next, input, init) => { + * const url = typeof input === 'string' ? input : input.toString(); + * + * // Only add headers for API routes + * if (url.includes('/api/')) { + * const headers = new Headers(init?.headers); + * headers.set('X-API-Version', 'v2'); + * return next(input, { ...init, headers }); + * } + * + * // Pass through for non-API routes + * return next(input, init); + * }); + * + * // Create caching middleware + * const cacheMiddleware = createMiddleware(async (next, input, init) => { + * const cacheKey = typeof input === 'string' ? input : input.toString(); + * + * // Check cache first + * const cached = await getFromCache(cacheKey); + * if (cached) { + * return new Response(cached, { status: 200 }); + * } + * + * // Make request and cache result + * const response = await next(input, init); + * if (response.ok) { + * await saveToCache(cacheKey, await response.clone().text()); + * } + * + * return response; + * }); + * ``` + * + * @param handler - Function that receives the next handler and request parameters + * @returns A fetch middleware function + */ +const createMiddleware = (handler) => { + return next => (input, init) => handler(next, input, init); +}; +exports.createMiddleware = createMiddleware; +//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/cjs/client/middleware.js.map b/dist/cjs/client/middleware.js.map new file mode 100644 index 000000000..e68b40c98 --- /dev/null +++ b/dist/cjs/client/middleware.js.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/client/middleware.ts"],"names":[],"mappings":";;;AAAA,uCAAuG;AASvG;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,MAAM,SAAS,GAClB,CAAC,QAA6B,EAAE,OAAsB,EAAc,EAAE,CACtE,IAAI,CAAC,EAAE;IACH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,WAAW,GAAG,KAAK,IAAuB,EAAE;YAC9C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,CAAC;YAE3C,mDAAmD;YACnD,M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AAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC,CAAC;AACN,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACI,MAAM,gBAAgB,GAAG,CAAC,OAAwF,EAAc,EAAE;IACrI,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAqB,EAAE,IAAI,CAAC,CAAC;AAC/E,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B"} \ No newline at end of file diff --git a/dist/cjs/client/sse.d.ts b/dist/cjs/client/sse.d.ts new file mode 100644 index 000000000..acf99f1ea --- /dev/null +++ b/dist/cjs/client/sse.d.ts @@ -0,0 +1,81 @@ +import { type ErrorEvent, type EventSourceInit } from 'eventsource'; +import { Transport, FetchLike } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +import { OAuthClientProvider } from './auth.js'; +export declare class SseError extends Error { + readonly code: number | undefined; + readonly event: ErrorEvent; + constructor(code: number | undefined, message: string | undefined, event: ErrorEvent); +} +/** + * Configuration options for the `SSEClientTransport`. + */ +export type SSEClientTransportOptions = { + /** + * An OAuth client provider to use for authentication. + * + * When an `authProvider` is specified and the SSE connection is started: + * 1. The connection is attempted with any existing access token from the `authProvider`. + * 2. If the access token has expired, the `authProvider` is used to refresh the token. + * 3. If token refresh fails or no access token exists, and auth is required, `OAuthClientProvider.redirectToAuthorization` is called, and an `UnauthorizedError` will be thrown from `connect`/`start`. + * + * After the user has finished authorizing via their user agent, and is redirected back to the MCP client application, call `SSEClientTransport.finishAuth` with the authorization code before retrying the connection. + * + * If an `authProvider` is not provided, and auth is required, an `UnauthorizedError` will be thrown. + * + * `UnauthorizedError` might also be thrown when sending any message over the SSE transport, indicating that the session has expired, and needs to be re-authed and reconnected. + */ + authProvider?: OAuthClientProvider; + /** + * Customizes the initial SSE request to the server (the request that begins the stream). + * + * NOTE: Setting this property will prevent an `Authorization` header from + * being automatically attached to the SSE request, if an `authProvider` is + * also given. This can be worked around by setting the `Authorization` header + * manually. + */ + eventSourceInit?: EventSourceInit; + /** + * Customizes recurring POST requests to the server. + */ + requestInit?: RequestInit; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; +}; +/** + * Client transport for SSE: this will connect to a server using Server-Sent Events for receiving + * messages and make separate POST requests for sending messages. + * @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period. + */ +export declare class SSEClientTransport implements Transport { + private _eventSource?; + private _endpoint?; + private _abortController?; + private _url; + private _resourceMetadataUrl?; + private _scope?; + private _eventSourceInit?; + private _requestInit?; + private _authProvider?; + private _fetch?; + private _fetchWithInit; + private _protocolVersion?; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL, opts?: SSEClientTransportOptions); + private _authThenStart; + private _commonHeaders; + private _startOrAuth; + start(): Promise; + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + finishAuth(authorizationCode: string): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; + setProtocolVersion(version: string): void; +} +//# sourceMappingURL=sse.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/sse.d.ts.map b/dist/cjs/client/sse.d.ts.map new file mode 100644 index 000000000..1d38f0eb6 --- /dev/null +++ b/dist/cjs/client/sse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/client/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAA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C,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;gBAElC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,yBAAyB;YAWxC,cAAc;YAyBd,cAAc;IAe5B,OAAO,CAAC,YAAY;IAyEd,KAAK;IAQX;;OAEG;IACG,UAAU,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA+ClD,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG5C"} \ No newline at end of file diff --git a/dist/cjs/client/sse.js b/dist/cjs/client/sse.js new file mode 100644 index 000000000..45b021981 --- /dev/null +++ b/dist/cjs/client/sse.js @@ -0,0 +1,213 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SSEClientTransport = exports.SseError = void 0; +const eventsource_1 = require("eventsource"); +const transport_js_1 = require("../shared/transport.js"); +const types_js_1 = require("../types.js"); +const auth_js_1 = require("./auth.js"); +class SseError extends Error { + constructor(code, message, event) { + super(`SSE error: ${message}`); + this.code = code; + this.event = event; + } +} +exports.SseError = SseError; +/** + * Client transport for SSE: this will connect to a server using Server-Sent Events for receiving + * messages and make separate POST requests for sending messages. + * @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period. + */ +class SSEClientTransport { + constructor(url, opts) { + this._url = url; + this._resourceMetadataUrl = undefined; + this._scope = undefined; + this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit; + this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit; + this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider; + this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch; + this._fetchWithInit = (0, transport_js_1.createFetchWithInit)(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit); + } + async _authThenStart() { + var _a; + if (!this._authProvider) { + throw new auth_js_1.UnauthorizedError('No auth provider'); + } + let result; + try { + result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(); + } + return await this._startOrAuth(); + } + async _commonHeaders() { + var _a; + const headers = {}; + if (this._authProvider) { + const tokens = await this._authProvider.tokens(); + if (tokens) { + headers['Authorization'] = `Bearer ${tokens.access_token}`; + } + } + if (this._protocolVersion) { + headers['mcp-protocol-version'] = this._protocolVersion; + } + return new Headers({ ...headers, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers }); + } + _startOrAuth() { + var _a, _b, _c; + const fetchImpl = ((_c = (_b = (_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch) !== null && _b !== void 0 ? _b : this._fetch) !== null && _c !== void 0 ? _c : fetch); + return new Promise((resolve, reject) => { + this._eventSource = new eventsource_1.EventSource(this._url.href, { + ...this._eventSourceInit, + fetch: async (url, init) => { + const headers = await this._commonHeaders(); + headers.set('Accept', 'text/event-stream'); + const response = await fetchImpl(url, { + ...init, + headers + }); + if (response.status === 401 && response.headers.has('www-authenticate')) { + const { resourceMetadataUrl, scope } = (0, auth_js_1.extractWWWAuthenticateParams)(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + } + return response; + } + }); + this._abortController = new AbortController(); + this._eventSource.onerror = event => { + var _a; + if (event.code === 401 && this._authProvider) { + this._authThenStart().then(resolve, reject); + return; + } + const error = new SseError(event.code, event.message, event); + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + this._eventSource.onopen = () => { + // The connection is open, but we need to wait for the endpoint to be received. + }; + this._eventSource.addEventListener('endpoint', (event) => { + var _a; + const messageEvent = event; + try { + this._endpoint = new URL(messageEvent.data, this._url); + if (this._endpoint.origin !== this._url.origin) { + throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`); + } + } + catch (error) { + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + void this.close(); + return; + } + resolve(); + }); + this._eventSource.onmessage = (event) => { + var _a, _b; + const messageEvent = event; + let message; + try { + message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data)); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + return; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message); + }; + }); + } + async start() { + if (this._eventSource) { + throw new Error('SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return await this._startOrAuth(); + } + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + async finishAuth(authorizationCode) { + if (!this._authProvider) { + throw new auth_js_1.UnauthorizedError('No auth provider'); + } + const result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + authorizationCode, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError('Failed to authorize'); + } + } + async close() { + var _a, _b, _c; + (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort(); + (_b = this._eventSource) === null || _b === void 0 ? void 0 : _b.close(); + (_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this); + } + async send(message) { + var _a, _b, _c; + if (!this._endpoint) { + throw new Error('Not connected'); + } + try { + const headers = await this._commonHeaders(); + headers.set('content-type', 'application/json'); + const init = { + ...this._requestInit, + method: 'POST', + headers, + body: JSON.stringify(message), + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._endpoint, init); + if (!response.ok) { + const text = await response.text().catch(() => null); + if (response.status === 401 && this._authProvider) { + const { resourceMetadataUrl, scope } = (0, auth_js_1.extractWWWAuthenticateParams)(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + const result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(); + } + // Purposely _not_ awaited, so we don't call onerror twice + return this.send(message); + } + throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`); + } + } + catch (error) { + (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error); + throw error; + } + } + setProtocolVersion(version) { + this._protocolVersion = version; + } +} +exports.SSEClientTransport = SSEClientTransport; +//# sourceMappingURL=sse.js.map \ No newline at end of file diff --git a/dist/cjs/client/sse.js.map b/dist/cjs/client/sse.js.map new file mode 100644 index 000000000..adb265a15 --- /dev/null +++ b/dist/cjs/client/sse.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/client/sse.ts"],"names":[],"mappings":";;;AAAA,6CAAiF;AACjF,yDAAmF;AACnF,0CAAmE;AACnE,uCAAmH;AAEnH,MAAa,QAAS,SAAQ,KAAK;IAC/B,YACoB,IAAwB,EACxC,OAA2B,EACX,KAAiB;QAEjC,KAAK,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;QAJf,SAAI,GAAJ,IAAI,CAAoB;QAExB,UAAK,GAAL,KAAK,CAAY;IAGrC,CAAC;CACJ;AARD,4BAQC;AA2CD;;;;GAIG;AACH,MAAa,kBAAkB;IAkB3B,YAAY,GAAQ,EAAE,IAAgC;QAClD,IAAI,CAAC,IAAI,GAAG,GAAG,CAA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;IACpC,CAAC;CACJ;AAlOD,gDAkOC"} \ No newline at end of file diff --git a/dist/cjs/client/stdio.d.ts b/dist/cjs/client/stdio.d.ts new file mode 100644 index 000000000..58d0b6ccb --- /dev/null +++ b/dist/cjs/client/stdio.d.ts @@ -0,0 +1,78 @@ +import { IOType } from 'node:child_process'; +import { Stream } from 'node:stream'; +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +export type StdioServerParameters = { + /** + * The executable to run to start the server. + */ + command: string; + /** + * Command line arguments to pass to the executable. + */ + args?: string[]; + /** + * The environment to use when spawning the process. + * + * If not specified, the result of getDefaultEnvironment() will be used. + */ + env?: Record; + /** + * How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn`. + * + * The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr. + */ + stderr?: IOType | Stream | number; + /** + * The working directory to use when spawning the process. + * + * If not specified, the current working directory will be inherited. + */ + cwd?: string; +}; +/** + * Environment variables to inherit by default, if an environment is not explicitly given. + */ +export declare const DEFAULT_INHERITED_ENV_VARS: string[]; +/** + * Returns a default environment object including only environment variables deemed safe to inherit. + */ +export declare function getDefaultEnvironment(): Record; +/** + * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. + * + * This transport is only available in Node.js environments. + */ +export declare class StdioClientTransport implements Transport { + private _process?; + private _abortController; + private _readBuffer; + private _serverParams; + private _stderrStream; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(server: StdioServerParameters); + /** + * Starts the server process and prepares to communicate with it. + */ + start(): Promise; + /** + * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped". + * + * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to + * attach listeners before the start method is invoked. This prevents loss of any early + * error output emitted by the child process. + */ + get stderr(): Stream | null; + /** + * The child process pid spawned by this transport. + * + * This is only available after the transport has been started. + */ + get pid(): number | null; + private processReadBuffer; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/stdio.d.ts.map b/dist/cjs/client/stdio.d.ts.map new file mode 100644 index 000000000..44f6de451 --- /dev/null +++ b/dist/cjs/client/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/client/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,MAAM,EAAe,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,qBAAqB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAElC;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,UAiBuB,CAAC;AAE/D;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkB9D;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,CAAe;IAChC,OAAO,CAAC,gBAAgB,CAA0C;IAClE,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;gBAElC,MAAM,EAAE,qBAAqB;IAOzC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4D5B;;;;;;OAMG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,CAM1B;IAED;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED,OAAO,CAAC,iBAAiB;IAenB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAc/C"} \ No newline at end of file diff --git a/dist/cjs/client/stdio.js b/dist/cjs/client/stdio.js new file mode 100644 index 000000000..95d6f94f3 --- /dev/null +++ b/dist/cjs/client/stdio.js @@ -0,0 +1,184 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StdioClientTransport = exports.DEFAULT_INHERITED_ENV_VARS = void 0; +exports.getDefaultEnvironment = getDefaultEnvironment; +const cross_spawn_1 = __importDefault(require("cross-spawn")); +const node_process_1 = __importDefault(require("node:process")); +const node_stream_1 = require("node:stream"); +const stdio_js_1 = require("../shared/stdio.js"); +/** + * Environment variables to inherit by default, if an environment is not explicitly given. + */ +exports.DEFAULT_INHERITED_ENV_VARS = node_process_1.default.platform === 'win32' + ? [ + 'APPDATA', + 'HOMEDRIVE', + 'HOMEPATH', + 'LOCALAPPDATA', + 'PATH', + 'PROCESSOR_ARCHITECTURE', + 'SYSTEMDRIVE', + 'SYSTEMROOT', + 'TEMP', + 'USERNAME', + 'USERPROFILE', + 'PROGRAMFILES' + ] + : /* list inspired by the default env inheritance of sudo */ + ['HOME', 'LOGNAME', 'PATH', 'SHELL', 'TERM', 'USER']; +/** + * Returns a default environment object including only environment variables deemed safe to inherit. + */ +function getDefaultEnvironment() { + const env = {}; + for (const key of exports.DEFAULT_INHERITED_ENV_VARS) { + const value = node_process_1.default.env[key]; + if (value === undefined) { + continue; + } + if (value.startsWith('()')) { + // Skip functions, which are a security risk. + continue; + } + env[key] = value; + } + return env; +} +/** + * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. + * + * This transport is only available in Node.js environments. + */ +class StdioClientTransport { + constructor(server) { + this._abortController = new AbortController(); + this._readBuffer = new stdio_js_1.ReadBuffer(); + this._stderrStream = null; + this._serverParams = server; + if (server.stderr === 'pipe' || server.stderr === 'overlapped') { + this._stderrStream = new node_stream_1.PassThrough(); + } + } + /** + * Starts the server process and prepares to communicate with it. + */ + async start() { + if (this._process) { + throw new Error('StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return new Promise((resolve, reject) => { + var _a, _b, _c, _d, _e; + this._process = (0, cross_spawn_1.default)(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== void 0 ? _a : [], { + // merge default env with server env because mcp server needs some env vars + env: { + ...getDefaultEnvironment(), + ...this._serverParams.env + }, + stdio: ['pipe', 'pipe', (_b = this._serverParams.stderr) !== null && _b !== void 0 ? _b : 'inherit'], + shell: false, + signal: this._abortController.signal, + windowsHide: node_process_1.default.platform === 'win32' && isElectron(), + cwd: this._serverParams.cwd + }); + this._process.on('error', error => { + var _a, _b; + if (error.name === 'AbortError') { + // Expected when close() is called. + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + return; + } + reject(error); + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + }); + this._process.on('spawn', () => { + resolve(); + }); + this._process.on('close', _code => { + var _a; + this._process = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }); + (_c = this._process.stdin) === null || _c === void 0 ? void 0 : _c.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + (_d = this._process.stdout) === null || _d === void 0 ? void 0 : _d.on('data', chunk => { + this._readBuffer.append(chunk); + this.processReadBuffer(); + }); + (_e = this._process.stdout) === null || _e === void 0 ? void 0 : _e.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + if (this._stderrStream && this._process.stderr) { + this._process.stderr.pipe(this._stderrStream); + } + }); + } + /** + * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped". + * + * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to + * attach listeners before the start method is invoked. This prevents loss of any early + * error output emitted by the child process. + */ + get stderr() { + var _a, _b; + if (this._stderrStream) { + return this._stderrStream; + } + return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.stderr) !== null && _b !== void 0 ? _b : null; + } + /** + * The child process pid spawned by this transport. + * + * This is only available after the transport has been started. + */ + get pid() { + var _a, _b; + return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.pid) !== null && _b !== void 0 ? _b : null; + } + processReadBuffer() { + var _a, _b; + while (true) { + try { + const message = this._readBuffer.readMessage(); + if (message === null) { + break; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + async close() { + this._abortController.abort(); + this._process = undefined; + this._readBuffer.clear(); + } + send(message) { + return new Promise(resolve => { + var _a; + if (!((_a = this._process) === null || _a === void 0 ? void 0 : _a.stdin)) { + throw new Error('Not connected'); + } + const json = (0, stdio_js_1.serializeMessage)(message); + if (this._process.stdin.write(json)) { + resolve(); + } + else { + this._process.stdin.once('drain', resolve); + } + }); + } +} +exports.StdioClientTransport = StdioClientTransport; +function isElectron() { + return 'type' in node_process_1.default; +} +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/cjs/client/stdio.js.map b/dist/cjs/client/stdio.js.map new file mode 100644 index 000000000..3b84737a1 --- /dev/null +++ b/dist/cjs/client/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/client/stdio.ts"],"names":[],"mappings":";;;;;;AAkEA,sDAkBC;AAnFD,8DAAgC;AAChC,gEAAmC;AACnC,6CAAkD;AAClD,iDAAkE;AAqClE;;GAEG;AACU,QAAA,0BAA0B,GACnC,sBAAO,CAAC,QAAQ,KAAK,OAAO;IACxB,CAAC,CAAC;QACI,SAAS;QACT,WAAW;QACX,UAAU;QACV,cAAc;QACd,MAAM;QACN,wBAAwB;QACxB,aAAa;QACb,YAAY;QACZ,MAAM;QACN,UAAU;QACV,aAAa;QACb,cAAc;KACjB;IACH,CAAC,CAAC,0DAA0D;QAC1D,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/D;;GAEG;AACH,SAAgB,qBAAqB;IACjC,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,KAAK,MAAM,GAAG,IAAI,kCAA0B,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,sBAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS;QACb,CAAC;QAED,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,6CAA6C;YAC7C,SAAS;QACb,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAa,oBAAoB;IAW7B,YAAY,MAA6B;QATjC,qBAAgB,GAAoB,IAAI,eAAe,EAAE,CAAC;QAC1D,gBAAW,GAAe,IAAI,qBAAU,EAAE,CAAC;QAE3C,kBAAa,GAAuB,IAAI,CAAC;QAO7C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;QAC5B,IAAI,MAA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,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA5ID,oDA4IC;AAED,SAAS,UAAU;IACf,OAAO,MAAM,IAAI,sBAAO,CAAC;AAC7B,CAAC"} \ No newline at end of file diff --git a/dist/cjs/client/streamableHttp.d.ts b/dist/cjs/client/streamableHttp.d.ts new file mode 100644 index 000000000..8488d7b1d --- /dev/null +++ b/dist/cjs/client/streamableHttp.d.ts @@ -0,0 +1,170 @@ +import { Transport, FetchLike } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +import { OAuthClientProvider } from './auth.js'; +export declare class StreamableHTTPError extends Error { + readonly code: number | undefined; + constructor(code: number | undefined, message: string | undefined); +} +/** + * Options for starting or authenticating an SSE connection + */ +export interface StartSSEOptions { + /** + * The resumption token used to continue long-running requests that were interrupted. + * + * This allows clients to reconnect and continue from where they left off. + */ + resumptionToken?: string; + /** + * A callback that is invoked when the resumption token changes. + * + * This allows clients to persist the latest token for potential reconnection. + */ + onresumptiontoken?: (token: string) => void; + /** + * Override Message ID to associate with the replay message + * so that response can be associate with the new resumed request. + */ + replayMessageId?: string | number; +} +/** + * Configuration options for reconnection behavior of the StreamableHTTPClientTransport. + */ +export interface StreamableHTTPReconnectionOptions { + /** + * Maximum backoff time between reconnection attempts in milliseconds. + * Default is 30000 (30 seconds). + */ + maxReconnectionDelay: number; + /** + * Initial backoff time between reconnection attempts in milliseconds. + * Default is 1000 (1 second). + */ + initialReconnectionDelay: number; + /** + * The factor by which the reconnection delay increases after each attempt. + * Default is 1.5. + */ + reconnectionDelayGrowFactor: number; + /** + * Maximum number of reconnection attempts before giving up. + * Default is 2. + */ + maxRetries: number; +} +/** + * Configuration options for the `StreamableHTTPClientTransport`. + */ +export type StreamableHTTPClientTransportOptions = { + /** + * An OAuth client provider to use for authentication. + * + * When an `authProvider` is specified and the connection is started: + * 1. The connection is attempted with any existing access token from the `authProvider`. + * 2. If the access token has expired, the `authProvider` is used to refresh the token. + * 3. If token refresh fails or no access token exists, and auth is required, `OAuthClientProvider.redirectToAuthorization` is called, and an `UnauthorizedError` will be thrown from `connect`/`start`. + * + * After the user has finished authorizing via their user agent, and is redirected back to the MCP client application, call `StreamableHTTPClientTransport.finishAuth` with the authorization code before retrying the connection. + * + * If an `authProvider` is not provided, and auth is required, an `UnauthorizedError` will be thrown. + * + * `UnauthorizedError` might also be thrown when sending any message over the transport, indicating that the session has expired, and needs to be re-authed and reconnected. + */ + authProvider?: OAuthClientProvider; + /** + * Customizes HTTP requests to the server. + */ + requestInit?: RequestInit; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; + /** + * Options to configure the reconnection behavior. + */ + reconnectionOptions?: StreamableHTTPReconnectionOptions; + /** + * Session ID for the connection. This is used to identify the session on the server. + * When not provided and connecting to a server that supports session IDs, the server will generate a new session ID. + */ + sessionId?: string; +}; +/** + * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events + * for receiving messages. + */ +export declare class StreamableHTTPClientTransport implements Transport { + private _abortController?; + private _url; + private _resourceMetadataUrl?; + private _scope?; + private _requestInit?; + private _authProvider?; + private _fetch?; + private _fetchWithInit; + private _sessionId?; + private _reconnectionOptions; + private _protocolVersion?; + private _hasCompletedAuthFlow; + private _lastUpscopingHeader?; + private _serverRetryMs?; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL, opts?: StreamableHTTPClientTransportOptions); + private _authThenStart; + private _commonHeaders; + private _startOrAuthSse; + /** + * Calculates the next reconnection delay using backoff algorithm + * + * @param attempt Current reconnection attempt count for the specific stream + * @returns Time to wait in milliseconds before next reconnection attempt + */ + private _getNextReconnectionDelay; + /** + * Schedule a reconnection attempt using server-provided retry interval or backoff + * + * @param lastEventId The ID of the last received event for resumability + * @param attemptCount Current reconnection attempt count for this specific stream + */ + private _scheduleReconnection; + private _handleSseStream; + start(): Promise; + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + finishAuth(authorizationCode: string): Promise; + close(): Promise; + send(message: JSONRPCMessage | JSONRPCMessage[], options?: { + resumptionToken?: string; + onresumptiontoken?: (token: string) => void; + }): Promise; + get sessionId(): string | undefined; + /** + * Terminates the current session by sending a DELETE request to the server. + * + * Clients that no longer need a particular session + * (e.g., because the user is leaving the client application) SHOULD send an + * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly + * terminate the session. + * + * The server MAY respond with HTTP 405 Method Not Allowed, indicating that + * the server does not allow clients to terminate sessions. + */ + terminateSession(): Promise; + setProtocolVersion(version: string): void; + get protocolVersion(): string | undefined; + /** + * Resume an SSE stream from a previous event ID. + * Opens a GET SSE connection with Last-Event-ID header to replay missed events. + * + * @param lastEventId The event ID to resume from + * @param options Optional callback to receive new resumption tokens + */ + resumeStream(lastEventId: string, options?: { + onresumptiontoken?: (token: string) => void; + }): Promise; +} +//# sourceMappingURL=streamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/streamableHttp.d.ts.map b/dist/cjs/client/streamableHttp.d.ts.map new file mode 100644 index 000000000..f9472e54a --- /dev/null +++ b/dist/cjs/client/streamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.d.ts","sourceRoot":"","sources":["../../../src/client/streamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAyC,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAkE,cAAc,EAAwB,MAAM,aAAa,CAAC;AACnI,OAAO,EAAkD,mBAAmB,EAAqB,MAAM,WAAW,CAAC;AAWnH,qBAAa,mBAAoB,SAAQ,KAAK;aAEtB,IAAI,EAAE,MAAM,GAAG,SAAS;gBAAxB,IAAI,EAAE,MAAM,GAAG,SAAS,E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,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAMpH"} \ No newline at end of file diff --git a/dist/cjs/client/streamableHttp.js b/dist/cjs/client/streamableHttp.js new file mode 100644 index 000000000..318be57b7 --- /dev/null +++ b/dist/cjs/client/streamableHttp.js @@ -0,0 +1,473 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StreamableHTTPClientTransport = exports.StreamableHTTPError = void 0; +const transport_js_1 = require("../shared/transport.js"); +const types_js_1 = require("../types.js"); +const auth_js_1 = require("./auth.js"); +const stream_1 = require("eventsource-parser/stream"); +// Default reconnection options for StreamableHTTP connections +const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = { + initialReconnectionDelay: 1000, + maxReconnectionDelay: 30000, + reconnectionDelayGrowFactor: 1.5, + maxRetries: 2 +}; +class StreamableHTTPError extends Error { + constructor(code, message) { + super(`Streamable HTTP error: ${message}`); + this.code = code; + } +} +exports.StreamableHTTPError = StreamableHTTPError; +/** + * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events + * for receiving messages. + */ +class StreamableHTTPClientTransport { + constructor(url, opts) { + var _a; + this._hasCompletedAuthFlow = false; // Circuit breaker: detect auth success followed by immediate 401 + this._url = url; + this._resourceMetadataUrl = undefined; + this._scope = undefined; + this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit; + this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider; + this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch; + this._fetchWithInit = (0, transport_js_1.createFetchWithInit)(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit); + this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId; + this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS; + } + async _authThenStart() { + var _a; + if (!this._authProvider) { + throw new auth_js_1.UnauthorizedError('No auth provider'); + } + let result; + try { + result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(); + } + return await this._startOrAuthSse({ resumptionToken: undefined }); + } + async _commonHeaders() { + var _a; + const headers = {}; + if (this._authProvider) { + const tokens = await this._authProvider.tokens(); + if (tokens) { + headers['Authorization'] = `Bearer ${tokens.access_token}`; + } + } + if (this._sessionId) { + headers['mcp-session-id'] = this._sessionId; + } + if (this._protocolVersion) { + headers['mcp-protocol-version'] = this._protocolVersion; + } + const extraHeaders = (0, transport_js_1.normalizeHeaders)((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers); + return new Headers({ + ...headers, + ...extraHeaders + }); + } + async _startOrAuthSse(options) { + var _a, _b, _c, _d; + const { resumptionToken } = options; + try { + // Try to open an initial SSE stream with GET to listen for server messages + // This is optional according to the spec - server may not support it + const headers = await this._commonHeaders(); + headers.set('Accept', 'text/event-stream'); + // Include Last-Event-ID header for resumable streams if provided + if (resumptionToken) { + headers.set('last-event-id', resumptionToken); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, { + method: 'GET', + headers, + signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal + }); + if (!response.ok) { + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + if (response.status === 401 && this._authProvider) { + // Need to authenticate + return await this._authThenStart(); + } + // 405 indicates that the server does not offer an SSE stream at GET endpoint + // This is an expected case that should not trigger an error + if (response.status === 405) { + return; + } + throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`); + } + this._handleSseStream(response.body, options, true); + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + throw error; + } + } + /** + * Calculates the next reconnection delay using backoff algorithm + * + * @param attempt Current reconnection attempt count for the specific stream + * @returns Time to wait in milliseconds before next reconnection attempt + */ + _getNextReconnectionDelay(attempt) { + // Use server-provided retry value if available + if (this._serverRetryMs !== undefined) { + return this._serverRetryMs; + } + // Fall back to exponential backoff + const initialDelay = this._reconnectionOptions.initialReconnectionDelay; + const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor; + const maxDelay = this._reconnectionOptions.maxReconnectionDelay; + // Cap at maximum delay + return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay); + } + /** + * Schedule a reconnection attempt using server-provided retry interval or backoff + * + * @param lastEventId The ID of the last received event for resumability + * @param attemptCount Current reconnection attempt count for this specific stream + */ + _scheduleReconnection(options, attemptCount = 0) { + var _a; + // Use provided options or default options + const maxRetries = this._reconnectionOptions.maxRetries; + // Check if we've exceeded maximum retry attempts + if (maxRetries > 0 && attemptCount >= maxRetries) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`)); + return; + } + // Calculate next delay based on current attempt count + const delay = this._getNextReconnectionDelay(attemptCount); + // Schedule the reconnection + setTimeout(() => { + // Use the last event ID to resume where we left off + this._startOrAuthSse(options).catch(error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`)); + // Schedule another attempt if this one failed, incrementing the attempt counter + this._scheduleReconnection(options, attemptCount + 1); + }); + }, delay); + } + _handleSseStream(stream, options, isReconnectable) { + if (!stream) { + return; + } + const { onresumptiontoken, replayMessageId } = options; + let lastEventId; + // Track whether we've received a priming event (event with ID) + // Per spec, server SHOULD send a priming event with ID before closing + let hasPrimingEvent = false; + const processStream = async () => { + var _a, _b, _c, _d; + // this is the closest we can get to trying to catch network errors + // if something happens reader will throw + try { + // Create a pipeline: binary stream -> text decoder -> SSE parser + const reader = stream + .pipeThrough(new TextDecoderStream()) + .pipeThrough(new stream_1.EventSourceParserStream({ + onRetry: (retryMs) => { + // Capture server-provided retry value for reconnection timing + this._serverRetryMs = retryMs; + } + })) + .getReader(); + while (true) { + const { value: event, done } = await reader.read(); + if (done) { + break; + } + // Update last event ID if provided + if (event.id) { + lastEventId = event.id; + // Mark that we've received a priming event - stream is now resumable + hasPrimingEvent = true; + onresumptiontoken === null || onresumptiontoken === void 0 ? void 0 : onresumptiontoken(event.id); + } + // Skip events with no data (priming events, keep-alives) + if (!event.data) { + continue; + } + if (!event.event || event.event === 'message') { + try { + const message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(event.data)); + if (replayMessageId !== undefined && (0, types_js_1.isJSONRPCResponse)(message)) { + message.id = replayMessageId; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + // Handle graceful server-side disconnect + // Server may close connection after sending event ID and retry field + // Reconnect if: already reconnectable (GET stream) OR received a priming event (POST stream with event ID) + const canResume = isReconnectable || hasPrimingEvent; + if (canResume && this._abortController && !this._abortController.signal.aborted) { + this._scheduleReconnection({ + resumptionToken: lastEventId, + onresumptiontoken, + replayMessageId + }, 0); + } + } + catch (error) { + // Handle stream errors - likely a network disconnect + (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`)); + // Attempt to reconnect if the stream disconnects unexpectedly and we aren't closing + // Reconnect if: already reconnectable (GET stream) OR received a priming event (POST stream with event ID) + const canResume = isReconnectable || hasPrimingEvent; + if (canResume && this._abortController && !this._abortController.signal.aborted) { + // Use the exponential backoff reconnection strategy + try { + this._scheduleReconnection({ + resumptionToken: lastEventId, + onresumptiontoken, + replayMessageId + }, 0); + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error instanceof Error ? error.message : String(error)}`)); + } + } + } + }; + processStream(); + } + async start() { + if (this._abortController) { + throw new Error('StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + this._abortController = new AbortController(); + } + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + async finishAuth(authorizationCode) { + if (!this._authProvider) { + throw new auth_js_1.UnauthorizedError('No auth provider'); + } + const result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + authorizationCode, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError('Failed to authorize'); + } + } + async close() { + var _a, _b; + // Abort any pending requests + (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort(); + (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this); + } + async send(message, options) { + var _a, _b, _c, _d, _e; + try { + const { resumptionToken, onresumptiontoken } = options || {}; + if (resumptionToken) { + // If we have at last event ID, we need to reconnect the SSE stream + this._startOrAuthSse({ resumptionToken, replayMessageId: (0, types_js_1.isJSONRPCRequest)(message) ? message.id : undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); }); + return; + } + const headers = await this._commonHeaders(); + headers.set('content-type', 'application/json'); + headers.set('accept', 'application/json, text/event-stream'); + const init = { + ...this._requestInit, + method: 'POST', + headers, + body: JSON.stringify(message), + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init); + // Handle session ID received during initialization + const sessionId = response.headers.get('mcp-session-id'); + if (sessionId) { + this._sessionId = sessionId; + } + if (!response.ok) { + const text = await response.text().catch(() => null); + if (response.status === 401 && this._authProvider) { + // Prevent infinite recursion when server returns 401 after successful auth + if (this._hasCompletedAuthFlow) { + throw new StreamableHTTPError(401, 'Server returned 401 after successful authentication'); + } + const { resourceMetadataUrl, scope } = (0, auth_js_1.extractWWWAuthenticateParams)(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + const result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(); + } + // Mark that we completed auth flow + this._hasCompletedAuthFlow = true; + // Purposely _not_ awaited, so we don't call onerror twice + return this.send(message); + } + if (response.status === 403 && this._authProvider) { + const { resourceMetadataUrl, scope, error } = (0, auth_js_1.extractWWWAuthenticateParams)(response); + if (error === 'insufficient_scope') { + const wwwAuthHeader = response.headers.get('WWW-Authenticate'); + // Check if we've already tried upscoping with this header to prevent infinite loops. + if (this._lastUpscopingHeader === wwwAuthHeader) { + throw new StreamableHTTPError(403, 'Server returned 403 after trying upscoping'); + } + if (scope) { + this._scope = scope; + } + if (resourceMetadataUrl) { + this._resourceMetadataUrl = resourceMetadataUrl; + } + // Mark that upscoping was tried. + this._lastUpscopingHeader = wwwAuthHeader !== null && wwwAuthHeader !== void 0 ? wwwAuthHeader : undefined; + const result = await (0, auth_js_1.auth)(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetch + }); + if (result !== 'AUTHORIZED') { + throw new auth_js_1.UnauthorizedError(); + } + return this.send(message); + } + } + throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`); + } + // Reset auth loop flag on successful response + this._hasCompletedAuthFlow = false; + this._lastUpscopingHeader = undefined; + // If the response is 202 Accepted, there's no body to process + if (response.status === 202) { + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + // if the accepted notification is initialized, we start the SSE stream + // if it's supported by the server + if ((0, types_js_1.isInitializedNotification)(message)) { + // Start without a lastEventId since this is a fresh connection + this._startOrAuthSse({ resumptionToken: undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); }); + } + return; + } + // Get original message(s) for detecting request IDs + const messages = Array.isArray(message) ? message : [message]; + const hasRequests = messages.filter(msg => 'method' in msg && 'id' in msg && msg.id !== undefined).length > 0; + // Check the response type + const contentType = response.headers.get('content-type'); + if (hasRequests) { + if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/event-stream')) { + // Handle SSE stream responses for requests + // We use the same handler as standalone streams, which now supports + // reconnection with the last event ID + this._handleSseStream(response.body, { onresumptiontoken }, false); + } + else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) { + // For non-streaming servers, we might get direct JSON responses + const data = await response.json(); + const responseMessages = Array.isArray(data) + ? data.map(msg => types_js_1.JSONRPCMessageSchema.parse(msg)) + : [types_js_1.JSONRPCMessageSchema.parse(data)]; + for (const msg of responseMessages) { + (_d = this.onmessage) === null || _d === void 0 ? void 0 : _d.call(this, msg); + } + } + else { + throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`); + } + } + } + catch (error) { + (_e = this.onerror) === null || _e === void 0 ? void 0 : _e.call(this, error); + throw error; + } + } + get sessionId() { + return this._sessionId; + } + /** + * Terminates the current session by sending a DELETE request to the server. + * + * Clients that no longer need a particular session + * (e.g., because the user is leaving the client application) SHOULD send an + * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly + * terminate the session. + * + * The server MAY respond with HTTP 405 Method Not Allowed, indicating that + * the server does not allow clients to terminate sessions. + */ + async terminateSession() { + var _a, _b, _c, _d; + if (!this._sessionId) { + return; // No session to terminate + } + try { + const headers = await this._commonHeaders(); + const init = { + ...this._requestInit, + method: 'DELETE', + headers, + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init); + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + // We specifically handle 405 as a valid response according to the spec, + // meaning the server does not support explicit session termination + if (!response.ok && response.status !== 405) { + throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`); + } + this._sessionId = undefined; + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + throw error; + } + } + setProtocolVersion(version) { + this._protocolVersion = version; + } + get protocolVersion() { + return this._protocolVersion; + } + /** + * Resume an SSE stream from a previous event ID. + * Opens a GET SSE connection with Last-Event-ID header to replay missed events. + * + * @param lastEventId The event ID to resume from + * @param options Optional callback to receive new resumption tokens + */ + async resumeStream(lastEventId, options) { + await this._startOrAuthSse({ + resumptionToken: lastEventId, + onresumptiontoken: options === null || options === void 0 ? void 0 : options.onresumptiontoken + }); + } +} +exports.StreamableHTTPClientTransport = StreamableHTTPClientTransport; +//# sourceMappingURL=streamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/client/streamableHttp.js.map b/dist/cjs/client/streamableHttp.js.map new file mode 100644 index 000000000..ccec93c85 --- /dev/null +++ b/dist/cjs/client/streamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.js","sourceRoot":"","sources":["../../../src/client/streamableHttp.ts"],"names":[],"mappings":";;;AAAA,yDAAqG;AACrG,0CAAmI;AACnI,uCAAmH;AACnH,sDAAoE;AAEpE,8DAA8D;AAC9D,MAAM,4CAA4C,GAAsC;IACpF,wBAAwB,EAAE,IAAI;IAC9B,oBAAoB,EAAE,KAAK;IAC3B,2BAA2B,EAAE,GAAG;IAChC,UAAU,EAAE,CAAC;CAChB,CAAC;AAEF,MAAa,mBAAoB,SAAQ,KAAK;IAC1C,YACoB,IAAwB,EACxC,OAA2B;QAE3B,KAAK,CAAC,0BAA0B,OAAO,EAAE,CAAC,CAAC;QAH3B,SAAI,GAAJ,IAAI,CAAoB;IAI5C,CAAC;CACJ;AAPD,kDAOC;AAkGD;;;;GAIG;AACH,MAAa,6BAA6B;IA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000000000..78f95de3b --- /dev/null +++ b/dist/cjs/client/websocket.d.ts @@ -0,0 +1,17 @@ +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +/** + * Client transport for WebSocket: this will connect to a server over the WebSocket protocol. + */ +export declare class WebSocketClientTransport implements Transport { + private _socket?; + private _url; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL); + start(): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=websocket.d.ts.map \ No newline at end of file diff --git a/dist/cjs/client/websocket.d.ts.map b/dist/cjs/client/websocket.d.ts.map new file mode 100644 index 000000000..2882d9822 --- /dev/null +++ b/dist/cjs/client/websocket.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/client/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AAInE;;GAEG;AACH,qBAAa,wBAAyB,YAAW,SAAS;IACtD,OAAO,CAAC,OAAO,CAAC,CAAY;IAC5B,OAAO,CAAC,IAAI,CAAM;IAElB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;gBAElC,GAAG,EAAE,GAAG;IAIpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsChB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAW/C"} \ No newline at end of file diff --git a/dist/cjs/client/websocket.js b/dist/cjs/client/websocket.js new file mode 100644 index 000000000..e2c94d065 --- /dev/null +++ b/dist/cjs/client/websocket.js @@ -0,0 +1,63 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.WebSocketClientTransport = void 0; +const types_js_1 = require("../types.js"); +const SUBPROTOCOL = 'mcp'; +/** + * Client transport for WebSocket: this will connect to a server over the WebSocket protocol. + */ +class WebSocketClientTransport { + constructor(url) { + this._url = url; + } + start() { + if (this._socket) { + throw new Error('WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return new Promise((resolve, reject) => { + this._socket = new WebSocket(this._url, SUBPROTOCOL); + this._socket.onerror = event => { + var _a; + const error = 'error' in event ? event.error : new Error(`WebSocket error: ${JSON.stringify(event)}`); + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + this._socket.onopen = () => { + resolve(); + }; + this._socket.onclose = () => { + var _a; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }; + this._socket.onmessage = (event) => { + var _a, _b; + let message; + try { + message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(event.data)); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + return; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message); + }; + }); + } + async close() { + var _a; + (_a = this._socket) === null || _a === void 0 ? void 0 : _a.close(); + } + send(message) { + return new Promise((resolve, reject) => { + var _a; + if (!this._socket) { + reject(new Error('Not connected')); + return; + } + (_a = this._socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(message)); + resolve(); + }); + } +} +exports.WebSocketClientTransport = WebSocketClientTransport; +//# sourceMappingURL=websocket.js.map \ No newline at end of file diff --git a/dist/cjs/client/websocket.js.map b/dist/cjs/client/websocket.js.map new file mode 100644 index 000000000..4094d2a22 --- /dev/null +++ b/dist/cjs/client/websocket.js.map @@ -0,0 +1 @@ +{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/client/websocket.ts"],"names":[],"mappings":";;;AACA,0CAAmE;AAEnE,MAAM,WA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b,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;oBAC/B,OAAO;gBACX,CAAC;gBAED,MAAA,IAAI,CAAC,SAAS,qDAAG,OAAO,CAAC,CAAC;YAC9B,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,MAAA,IAAI,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC,OAAuB;QACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAChB,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;gBACnC,OAAO;YACX,CAAC;YAED,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAjED,4DAiEC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/elicitationUrlExample.d.ts b/dist/cjs/examples/client/elicitationUrlExample.d.ts new file mode 100644 index 000000000..611f6eba2 --- /dev/null +++ b/dist/cjs/examples/client/elicitationUrlExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationUrlExample.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/elicitationUrlExample.d.ts.map b/dist/cjs/examples/client/elicitationUrlExample.d.ts.map new file mode 100644 index 000000000..e749adfb9 --- /dev/null +++ b/dist/cjs/examples/client/elicitationUrlExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/elicitationUrlExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/elicitationUrlExample.js b/dist/cjs/examples/client/elicitationUrlExample.js new file mode 100644 index 000000000..fac53f048 --- /dev/null +++ b/dist/cjs/examples/client/elicitationUrlExample.js @@ -0,0 +1,693 @@ +"use strict"; +// Run with: npx tsx src/examples/client/elicitationUrlExample.ts +// +// This example demonstrates how to use URL elicitation to securely +// collect user input in a remote (HTTP) server. +// URL elicitation allows servers to prompt the end-user to open a URL in their browser +// to collect sensitive information. +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const node_readline_1 = require("node:readline"); +const types_js_1 = require("../../types.js"); +const metadataUtils_js_1 = require("../../shared/metadataUtils.js"); +const node_child_process_1 = require("node:child_process"); +const simpleOAuthClientProvider_js_1 = require("./simpleOAuthClientProvider.js"); +const auth_js_1 = require("../../client/auth.js"); +const node_http_1 = require("node:http"); +// Set up OAuth (required for this example) +const OAUTH_CALLBACK_PORT = 8090; // Use different port than auth server (3001) +const OAUTH_CALLBACK_URL = `http://localhost:${OAUTH_CALLBACK_PORT}/callback`; +let oauthProvider = undefined; +console.log('Getting OAuth token...'); +const clientMetadata = { + client_name: 'Elicitation MCP Client', + redirect_uris: [OAUTH_CALLBACK_URL], + grant_types: ['authorization_code', 'refresh_token'], + response_types: ['code'], + token_endpoint_auth_method: 'client_secret_post', + scope: 'mcp:tools' +}; +oauthProvider = new simpleOAuthClientProvider_js_1.InMemoryOAuthClientProvider(OAUTH_CALLBACK_URL, clientMetadata, (redirectUrl) => { + console.log(`🌐 Opening browser for OAuth redirect: ${redirectUrl.toString()}`); + openBrowser(redirectUrl.toString()); +}); +// Create readline interface for user input +const readline = (0, node_readline_1.createInterface)({ + input: process.stdin, + output: process.stdout +}); +let abortCommand = new AbortController(); +// Global client and transport for interactive commands +let client = null; +let transport = null; +let serverUrl = 'http://localhost:3000/mcp'; +let sessionId = undefined; +let isProcessingCommand = false; +let isProcessingElicitations = false; +const elicitationQueue = []; +let elicitationQueueSignal = null; +let elicitationsCompleteSignal = null; +// Map to track pending URL elicitations waiting for completion notifications +const pendingURLElicitations = new Map(); +async function main() { + console.log('MCP Interactive Client'); + console.log('====================='); + // Connect to server immediately with default settings + await connect(); + // Start the elicitation loop in the background + elicitationLoop().catch(error => { + console.error('Unexpected error in elicitation loop:', error); + process.exit(1); + }); + // Short delay allowing the server to send any SSE elicitations on connection + await new Promise(resolve => setTimeout(resolve, 200)); + // Wait until we are done processing any initial elicitations + await waitForElicitationsToComplete(); + // Print help and start the command loop + printHelp(); + await commandLoop(); +} +async function waitForElicitationsToComplete() { + // Wait until the queue is empty and nothing is being processed + while (elicitationQueue.length > 0 || isProcessingElicitations) { + await new Promise(resolve => setTimeout(resolve, 100)); + } +} +function printHelp() { + console.log('\nAvailable commands:'); + console.log(' connect [url] - Connect to MCP server (default: http://localhost:3000/mcp)'); + console.log(' disconnect - Disconnect from server'); + console.log(' terminate-session - Terminate the current session'); + console.log(' reconnect - Reconnect to the server'); + console.log(' list-tools - List available tools'); + console.log(' call-tool [args] - Call a tool with optional JSON arguments'); + console.log(' payment-confirm - Test URL elicitation via error response with payment-confirm tool'); + console.log(' third-party-auth - Test tool that requires third-party OAuth credentials'); + console.log(' help - Show this help'); + console.log(' quit - Exit the program'); +} +async function commandLoop() { + await new Promise(resolve => { + if (!isProcessingElicitations) { + resolve(); + } + else { + elicitationsCompleteSignal = resolve; + } + }); + readline.question('\n> ', { signal: abortCommand.signal }, async (input) => { + var _a; + isProcessingCommand = true; + const args = input.trim().split(/\s+/); + const command = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + try { + switch (command) { + case 'connect': + await connect(args[1]); + break; + case 'disconnect': + await disconnect(); + break; + case 'terminate-session': + await terminateSession(); + break; + case 'reconnect': + await reconnect(); + break; + case 'list-tools': + await listTools(); + break; + case 'call-tool': + if (args.length < 2) { + console.log('Usage: call-tool [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_b) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callTool(toolName, toolArgs); + } + break; + case 'payment-confirm': + await callPaymentConfirmTool(); + break; + case 'third-party-auth': + await callThirdPartyAuthTool(); + break; + case 'help': + printHelp(); + break; + case 'quit': + case 'exit': + await cleanup(); + return; + default: + if (command) { + console.log(`Unknown command: ${command}`); + } + break; + } + } + catch (error) { + console.error(`Error executing command: ${error}`); + } + finally { + isProcessingCommand = false; + } + // Process another command after we've processed the this one + await commandLoop(); + }); +} +async function elicitationLoop() { + while (true) { + // Wait until we have elicitations to process + await new Promise(resolve => { + if (elicitationQueue.length > 0) { + resolve(); + } + else { + elicitationQueueSignal = resolve; + } + }); + isProcessingElicitations = true; + abortCommand.abort(); // Abort the command loop if it's running + // Process all queued elicitations + while (elicitationQueue.length > 0) { + const queued = elicitationQueue.shift(); + console.log(`📤 Processing queued elicitation (${elicitationQueue.length} remaining)`); + try { + const result = await handleElicitationRequest(queued.request); + queued.resolve(result); + } + catch (error) { + queued.reject(error instanceof Error ? error : new Error(String(error))); + } + } + console.log('✅ All queued elicitations processed. Resuming command loop...\n'); + isProcessingElicitations = false; + // Reset the abort controller for the next command loop + abortCommand = new AbortController(); + // Resume the command loop + if (elicitationsCompleteSignal) { + elicitationsCompleteSignal(); + elicitationsCompleteSignal = null; + } + } +} +async function openBrowser(url) { + const command = `open "${url}"`; + (0, node_child_process_1.exec)(command, error => { + if (error) { + console.error(`Failed to open browser: ${error.message}`); + console.log(`Please manually open: ${url}`); + } + }); +} +/** + * Enqueues an elicitation request and returns the result. + * + * This function is used so that our CLI (which can only handle one input request at a time) + * can handle elicitation requests and the command loop. + * + * @param request - The elicitation request to be handled + * @returns The elicitation result + */ +async function elicitationRequestHandler(request) { + // If we are processing a command, handle this elicitation immediately + if (isProcessingCommand) { + console.log('📋 Processing elicitation immediately (during command execution)'); + return await handleElicitationRequest(request); + } + // Otherwise, queue the request to be handled by the elicitation loop + console.log(`📥 Queueing elicitation request (queue size will be: ${elicitationQueue.length + 1})`); + return new Promise((resolve, reject) => { + elicitationQueue.push({ + request, + resolve, + reject + }); + // Signal the elicitation loop that there's work to do + if (elicitationQueueSignal) { + elicitationQueueSignal(); + elicitationQueueSignal = null; + } + }); +} +/** + * Handles an elicitation request. + * + * This function is used to handle the elicitation request and return the result. + * + * @param request - The elicitation request to be handled + * @returns The elicitation result + */ +async function handleElicitationRequest(request) { + const mode = request.params.mode; + console.log('\n🔔 Elicitation Request Received:'); + console.log(`Mode: ${mode}`); + if (mode === 'url') { + return { + action: await handleURLElicitation(request.params) + }; + } + else { + // Should not happen because the client declares its capabilities to the server, + // but being defensive is a good practice: + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Unsupported elicitation mode: ${mode}`); + } +} +/** + * Handles a URL elicitation by opening the URL in the browser. + * + * Note: This is a shared code for both request handlers and error handlers. + * As a result of sharing schema, there is no big forking of logic for the client. + * + * @param params - The URL elicitation request parameters + * @returns The action to take (accept, cancel, or decline) + */ +async function handleURLElicitation(params) { + const url = params.url; + const elicitationId = params.elicitationId; + const message = params.message; + console.log(`🆔 Elicitation ID: ${elicitationId}`); // Print for illustration + // Parse URL to show domain for security + let domain = 'unknown domain'; + try { + const parsedUrl = new URL(url); + domain = parsedUrl.hostname; + } + catch (_a) { + console.error('Invalid URL provided by server'); + return 'decline'; + } + // Example security warning to help prevent phishing attacks + console.log('\n⚠️ \x1b[33mSECURITY WARNING\x1b[0m ⚠️'); + console.log('\x1b[33mThe server is requesting you to open an external URL.\x1b[0m'); + console.log('\x1b[33mOnly proceed if you trust this server and understand why it needs this.\x1b[0m\n'); + console.log(`🌐 Target domain: \x1b[36m${domain}\x1b[0m`); + console.log(`🔗 Full URL: \x1b[36m${url}\x1b[0m`); + console.log(`\nℹ️ Server's reason:\n\n\x1b[36m${message}\x1b[0m\n`); + // 1. Ask for user consent to open the URL + const consent = await new Promise(resolve => { + readline.question('\nDo you want to open this URL in your browser? (y/n): ', input => { + resolve(input.trim().toLowerCase()); + }); + }); + // 2. If user did not consent, return appropriate result + if (consent === 'no' || consent === 'n') { + console.log('❌ URL navigation declined.'); + return 'decline'; + } + else if (consent !== 'yes' && consent !== 'y') { + console.log('🚫 Invalid response. Cancelling elicitation.'); + return 'cancel'; + } + // 3. Wait for completion notification in the background + const completionPromise = new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + pendingURLElicitations.delete(elicitationId); + console.log(`\x1b[31m❌ Elicitation ${elicitationId} timed out waiting for completion.\x1b[0m`); + reject(new Error('Elicitation completion timeout')); + }, 5 * 60 * 1000); // 5 minute timeout + pendingURLElicitations.set(elicitationId, { + resolve: () => { + clearTimeout(timeout); + resolve(); + }, + reject, + timeout + }); + }); + completionPromise.catch(error => { + console.error('Background completion wait failed:', error); + }); + // 4. Open the URL in the browser + console.log(`\n🚀 Opening browser to: ${url}`); + await openBrowser(url); + console.log('\n⏳ Waiting for you to complete the interaction in your browser...'); + console.log(' The server will send a notification once you complete the action.'); + // 5. Acknowledge the user accepted the elicitation + return 'accept'; +} +/** + * Example OAuth callback handler - in production, use a more robust approach + * for handling callbacks and storing tokens + */ +/** + * Starts a temporary HTTP server to receive the OAuth callback + */ +async function waitForOAuthCallback() { + return new Promise((resolve, reject) => { + const server = (0, node_http_1.createServer)((req, res) => { + // Ignore favicon requests + if (req.url === '/favicon.ico') { + res.writeHead(404); + res.end(); + return; + } + console.log(`📥 Received callback: ${req.url}`); + const parsedUrl = new URL(req.url || '', 'http://localhost'); + const code = parsedUrl.searchParams.get('code'); + const error = parsedUrl.searchParams.get('error'); + if (code) { + console.log(`✅ Authorization code received: ${code === null || code === void 0 ? void 0 : code.substring(0, 10)}...`); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Successful!

+

This simulates successful authorization of the MCP client, which now has an access token for the MCP server.

+

This window will close automatically in 10 seconds.

+ + + + `); + resolve(code); + setTimeout(() => server.close(), 15000); + } + else if (error) { + console.log(`❌ Authorization error: ${error}`); + res.writeHead(400, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Failed

+

Error: ${error}

+ + + `); + reject(new Error(`OAuth authorization failed: ${error}`)); + } + else { + console.log(`❌ No authorization code or error in callback`); + res.writeHead(400); + res.end('Bad request'); + reject(new Error('No authorization code provided')); + } + }); + server.listen(OAUTH_CALLBACK_PORT, () => { + console.log(`OAuth callback server started on http://localhost:${OAUTH_CALLBACK_PORT}`); + }); + }); +} +/** + * Attempts to connect to the MCP server with OAuth authentication. + * Handles OAuth flow recursively if authorization is required. + */ +async function attemptConnection(oauthProvider) { + console.log('🚢 Creating transport with OAuth provider...'); + const baseUrl = new URL(serverUrl); + transport = new streamableHttp_js_1.StreamableHTTPClientTransport(baseUrl, { + sessionId: sessionId, + authProvider: oauthProvider + }); + console.log('🚢 Transport created'); + try { + console.log('🔌 Attempting connection (this will trigger OAuth redirect if needed)...'); + await client.connect(transport); + sessionId = transport.sessionId; + console.log('Transport created with session ID:', sessionId); + console.log('✅ Connected successfully'); + } + catch (error) { + if (error instanceof auth_js_1.UnauthorizedError) { + console.log('🔐 OAuth required - waiting for authorization...'); + const callbackPromise = waitForOAuthCallback(); + const authCode = await callbackPromise; + await transport.finishAuth(authCode); + console.log('🔐 Authorization code received:', authCode); + console.log('🔌 Reconnecting with authenticated transport...'); + // Recursively retry connection after OAuth completion + await attemptConnection(oauthProvider); + } + else { + console.error('❌ Connection failed with non-auth error:', error); + throw error; + } + } +} +async function connect(url) { + if (client) { + console.log('Already connected. Disconnect first.'); + return; + } + if (url) { + serverUrl = url; + } + console.log(`🔗 Attempting to connect to ${serverUrl}...`); + // Create a new client with elicitation capability + console.log('👤 Creating MCP client...'); + client = new index_js_1.Client({ + name: 'example-client', + version: '1.0.0' + }, { + capabilities: { + elicitation: { + // Only URL elicitation is supported in this demo + // (see server/elicitationExample.ts for a demo of form mode elicitation) + url: {} + } + } + }); + console.log('👤 Client created'); + // Set up elicitation request handler with proper validation + client.setRequestHandler(types_js_1.ElicitRequestSchema, elicitationRequestHandler); + // Set up notification handler for elicitation completion + client.setNotificationHandler(types_js_1.ElicitationCompleteNotificationSchema, notification => { + const { elicitationId } = notification.params; + const pending = pendingURLElicitations.get(elicitationId); + if (pending) { + clearTimeout(pending.timeout); + pendingURLElicitations.delete(elicitationId); + console.log(`\x1b[32m✅ Elicitation ${elicitationId} completed!\x1b[0m`); + pending.resolve(); + } + else { + // Shouldn't happen - discard it! + console.warn(`Received completion notification for unknown elicitation: ${elicitationId}`); + } + }); + try { + console.log('🔐 Starting OAuth flow...'); + await attemptConnection(oauthProvider); + console.log('Connected to MCP server'); + // Set up error handler after connection is established so we don't double log errors + client.onerror = error => { + console.error('\x1b[31mClient error:', error, '\x1b[0m'); + }; + } + catch (error) { + console.error('Failed to connect:', error); + client = null; + transport = null; + return; + } +} +async function disconnect() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + await transport.close(); + console.log('Disconnected from MCP server'); + client = null; + transport = null; + } + catch (error) { + console.error('Error disconnecting:', error); + } +} +async function terminateSession() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + console.log('Terminating session with ID:', transport.sessionId); + await transport.terminateSession(); + console.log('Session terminated successfully'); + // Check if sessionId was cleared after termination + if (!transport.sessionId) { + console.log('Session ID has been cleared'); + sessionId = undefined; + // Also close the transport and clear client objects + await transport.close(); + console.log('Transport closed after session termination'); + client = null; + transport = null; + } + else { + console.log('Server responded with 405 Method Not Allowed (session termination not supported)'); + console.log('Session ID is still active:', transport.sessionId); + } + } + catch (error) { + console.error('Error terminating session:', error); + } +} +async function reconnect() { + if (client) { + await disconnect(); + } + await connect(); +} +async function listTools() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, types_js_1.ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - id: ${tool.name}, name: ${(0, metadataUtils_js_1.getDisplayName)(tool)}, description: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server (${error})`); + } +} +async function callTool(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name, + arguments: args + } + }; + console.log(`Calling tool '${name}' with args:`, args); + const result = await client.request(request, types_js_1.CallToolResultSchema); + console.log('Tool result:'); + const resourceLinks = []; + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else if (item.type === 'resource_link') { + const resourceLink = item; + resourceLinks.push(resourceLink); + console.log(` 📁 Resource Link: ${resourceLink.name}`); + console.log(` URI: ${resourceLink.uri}`); + if (resourceLink.mimeType) { + console.log(` Type: ${resourceLink.mimeType}`); + } + if (resourceLink.description) { + console.log(` Description: ${resourceLink.description}`); + } + } + else if (item.type === 'resource') { + console.log(` [Embedded Resource: ${item.resource.uri}]`); + } + else if (item.type === 'image') { + console.log(` [Image: ${item.mimeType}]`); + } + else if (item.type === 'audio') { + console.log(` [Audio: ${item.mimeType}]`); + } + else { + console.log(` [Unknown content type]:`, item); + } + }); + // Offer to read resource links + if (resourceLinks.length > 0) { + console.log(`\nFound ${resourceLinks.length} resource link(s). Use 'read-resource ' to read their content.`); + } + } + catch (error) { + if (error instanceof types_js_1.UrlElicitationRequiredError) { + console.log('\n🔔 Elicitation Required Error Received:'); + console.log(`Message: ${error.message}`); + for (const e of error.elicitations) { + await handleURLElicitation(e); // For the error handler, we discard the action result because we don't respond to an error response + } + return; + } + console.log(`Error calling tool ${name}: ${error}`); + } +} +async function cleanup() { + if (client && transport) { + try { + // First try to terminate the session gracefully + if (transport.sessionId) { + try { + console.log('Terminating session before exit...'); + await transport.terminateSession(); + console.log('Session terminated successfully'); + } + catch (error) { + console.error('Error terminating session:', error); + } + } + // Then close the transport + await transport.close(); + } + catch (error) { + console.error('Error closing transport:', error); + } + } + process.stdin.setRawMode(false); + readline.close(); + console.log('\nGoodbye!'); + process.exit(0); +} +async function callPaymentConfirmTool() { + console.log('Calling payment-confirm tool...'); + await callTool('payment-confirm', { cartId: 'cart_123' }); +} +async function callThirdPartyAuthTool() { + console.log('Calling third-party-auth tool...'); + await callTool('third-party-auth', { param1: 'test' }); +} +// Set up raw mode for keyboard input to capture Escape key +process.stdin.setRawMode(true); +process.stdin.on('data', async (data) => { + // Check for Escape key (27) + if (data.length === 1 && data[0] === 27) { + console.log('\nESC key pressed. Disconnecting from server...'); + // Abort current operation and disconnect from server + if (client && transport) { + await disconnect(); + console.log('Disconnected. Press Enter to continue.'); + } + else { + console.log('Not connected to server.'); + } + // Re-display the prompt + process.stdout.write('> '); + } +}); +// Handle Ctrl+C +process.on('SIGINT', async () => { + console.log('\nReceived SIGINT. Cleaning up...'); + await cleanup(); +}); +// Start the interactive client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=elicitationUrlExample.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/elicitationUrlExample.js.map b/dist/cjs/examples/client/elicitationUrlExample.js.map new file mode 100644 index 000000000..b17808ca7 --- /dev/null +++ b/dist/cjs/examples/client/elicitationUrlExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.js","sourceRoot":"","sources":["../../../../src/examples/client/elicitationUrlExample.ts"],"names":[],"mappings":";AAAA,iEAAiE;AACjE,EAAE;AACF,mEAAmE;AACnE,gDAAgD;AAChD,uFAAuF;AACvF,oCAAoC;;AAEpC,oDAA+C;AAC/C,sEAA+E;AAC/E,iDAAgD;AAChD,6CAcwB;AACxB,oEAA+D;AAE/D,2DAA0C;AAC1C,iFAA6E;AAC7E,kDAAyD;AACzD,yCAAyC;AAEzC,2CAA2C;AAC3C,MAAM,mBAAmB,GAAG,IAAI,CAAC,CAAC,6CAA6C;AAC/E,MAAM,kBAAkB,GAAG,oBAAoB,mBAAmB,WAAW,CAAC;AAC9E,IAAI,aAAa,GAA4C,SAAS,CAAC;AAEvE,OAAO,CAAC,GAAG,CAAC,wBAA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Parallel.d.ts b/dist/cjs/examples/client/multipleClientsParallel.d.ts new file mode 100644 index 000000000..0ac5af8e5 --- /dev/null +++ b/dist/cjs/examples/client/multipleClientsParallel.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=multipleClientsParallel.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/multipleClientsParallel.d.ts.map b/dist/cjs/examples/client/multipleClientsParallel.d.ts.map new file mode 100644 index 000000000..91051dc94 --- /dev/null +++ b/dist/cjs/examples/client/multipleClientsParallel.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multipleClientsParallel.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/multipleClientsParallel.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/multipleClientsParallel.js b/dist/cjs/examples/client/multipleClientsParallel.js new file mode 100644 index 000000000..5cfbb2f4d --- /dev/null +++ b/dist/cjs/examples/client/multipleClientsParallel.js @@ -0,0 +1,134 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +/** + * Multiple Clients MCP Example + * + * This client demonstrates how to: + * 1. Create multiple MCP clients in parallel + * 2. Each client calls a single tool + * 3. Track notifications from each client independently + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function createAndRunClient(config) { + console.log(`[${config.id}] Creating client: ${config.name}`); + const client = new index_js_1.Client({ + name: config.name, + version: '1.0.0' + }); + const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(serverUrl)); + // Set up client-specific error handler + client.onerror = error => { + console.error(`[${config.id}] Client error:`, error); + }; + // Set up client-specific notification handler + client.setNotificationHandler(types_js_1.LoggingMessageNotificationSchema, notification => { + console.log(`[${config.id}] Notification: ${notification.params.data}`); + }); + try { + // Connect to the server + await client.connect(transport); + console.log(`[${config.id}] Connected to MCP server`); + // Call the specified tool + console.log(`[${config.id}] Calling tool: ${config.toolName}`); + const toolRequest = { + method: 'tools/call', + params: { + name: config.toolName, + arguments: { + ...config.toolArguments, + // Add client ID to arguments for identification in notifications + caller: config.id + } + } + }; + const result = await client.request(toolRequest, types_js_1.CallToolResultSchema); + console.log(`[${config.id}] Tool call completed`); + // Keep the connection open for a bit to receive notifications + await new Promise(resolve => setTimeout(resolve, 5000)); + // Disconnect + await transport.close(); + console.log(`[${config.id}] Disconnected from MCP server`); + return { id: config.id, result }; + } + catch (error) { + console.error(`[${config.id}] Error:`, error); + throw error; + } +} +async function main() { + console.log('MCP Multiple Clients Example'); + console.log('============================'); + console.log(`Server URL: ${serverUrl}`); + console.log(''); + try { + // Define client configurations + const clientConfigs = [ + { + id: 'client1', + name: 'basic-client-1', + toolName: 'start-notification-stream', + toolArguments: { + interval: 3, // 1 second between notifications + count: 5 // Send 5 notifications + } + }, + { + id: 'client2', + name: 'basic-client-2', + toolName: 'start-notification-stream', + toolArguments: { + interval: 2, // 2 seconds between notifications + count: 3 // Send 3 notifications + } + }, + { + id: 'client3', + name: 'basic-client-3', + toolName: 'start-notification-stream', + toolArguments: { + interval: 1, // 0.5 second between notifications + count: 8 // Send 8 notifications + } + } + ]; + // Start all clients in parallel + console.log(`Starting ${clientConfigs.length} clients in parallel...`); + console.log(''); + const clientPromises = clientConfigs.map(config => createAndRunClient(config)); + const results = await Promise.all(clientPromises); + // Display results from all clients + console.log('\n=== Final Results ==='); + results.forEach(({ id, result }) => { + console.log(`\n[${id}] Tool result:`); + if (Array.isArray(result.content)) { + result.content.forEach((item) => { + if (item.type === 'text' && item.text) { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + else { + console.log(` Unexpected result format:`, result); + } + }); + console.log('\n=== All clients completed successfully ==='); + } + catch (error) { + console.error('Error running multiple clients:', error); + process.exit(1); + } +} +// Start the example +main().catch((error) => { + console.error('Error running MCP multiple clients example:', error); + process.exit(1); +}); +//# sourceMappingURL=multipleClientsParallel.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/multipleClientsParallel.js.map b/dist/cjs/examples/client/multipleClientsParallel.js.map new file mode 100644 index 000000000..05812d11a --- /dev/null +++ b/dist/cjs/examples/client/multipleClientsParallel.js.map @@ -0,0 +1 @@ +{"version":3,"file":"multipleClientsParallel.js","sourceRoot":"","sources":["../../../../src/examples/client/multipleClientsParallel.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,sEAA+E;AAC/E,6CAAyH;AAEzH;;;;;;;GAOG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,2BAA2B,CAAC;AASzD,KAAK,UAAU,kBAAkB,CAAC,MAAoB;IAClD,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAE9D,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,OAAO;KACnB,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,iDAA6B,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAExE,uCAAuC;IACvC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC;IAEF,8CAA8C;IAC9C,MAAM,CAAC,sBAAsB,CAAC,2CAAgC,EAAE,YAAY,CAAC,EAAE;QAC3E,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,mBAAmB,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC,CA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OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACtC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBAChC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAqC,EAAE,EAAE;oBAC7D,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;wBACpC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBAClC,CAAC;yBAAM,CAAC;wBACJ,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,WAAW,EAAE,IAAI,CAAC,CAAC;oBACjD,CAAC;gBACL,CAAC,CAAC,CAAC;YACP,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC;YACvD,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,oBAAoB;AACpB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;IACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/parallelToolCallsClient.d.ts b/dist/cjs/examples/client/parallelToolCallsClient.d.ts new file mode 100644 index 000000000..e93d4d69d --- /dev/null +++ b/dist/cjs/examples/client/parallelToolCallsClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=parallelToolCallsClient.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/parallelToolCallsClient.d.ts.map b/dist/cjs/examples/client/parallelToolCallsClient.d.ts.map new file mode 100644 index 000000000..25a3b820c --- /dev/null +++ b/dist/cjs/examples/client/parallelToolCallsClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"parallelToolCallsClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/parallelToolCallsClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/parallelToolCallsClient.js b/dist/cjs/examples/client/parallelToolCallsClient.js new file mode 100644 index 000000000..e5a9829e9 --- /dev/null +++ b/dist/cjs/examples/client/parallelToolCallsClient.js @@ -0,0 +1,176 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +/** + * Parallel Tool Calls MCP Client + * + * This client demonstrates how to: + * 1. Start multiple tool calls in parallel + * 2. Track notifications from each tool call using a caller parameter + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function main() { + console.log('MCP Parallel Tool Calls Client'); + console.log('=============================='); + console.log(`Connecting to server at: ${serverUrl}`); + let client; + let transport; + try { + // Create client with streamable HTTP transport + client = new index_js_1.Client({ + name: 'parallel-tool-calls-client', + version: '1.0.0' + }); + client.onerror = error => { + console.error('Client error:', error); + }; + // Connect to the server + transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(serverUrl)); + await client.connect(transport); + console.log('Successfully connected to MCP server'); + // Set up notification handler with caller identification + client.setNotificationHandler(types_js_1.LoggingMessageNotificationSchema, notification => { + console.log(`Notification: ${notification.params.data}`); + }); + console.log('List tools'); + const toolsRequest = await listTools(client); + console.log('Tools: ', toolsRequest); + // 2. Start multiple notification tools in parallel + console.log('\n=== Starting Multiple Notification Streams in Parallel ==='); + const toolResults = await startParallelNotificationTools(client); + // Log the results from each tool call + for (const [caller, result] of Object.entries(toolResults)) { + console.log(`\n=== Tool result for ${caller} ===`); + result.content.forEach((item) => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + // 3. Wait for all notifications (10 seconds) + console.log('\n=== Waiting for all notifications ==='); + await new Promise(resolve => setTimeout(resolve, 10000)); + // 4. Disconnect + console.log('\n=== Disconnecting ==='); + await transport.close(); + console.log('Disconnected from MCP server'); + } + catch (error) { + console.error('Error running client:', error); + process.exit(1); + } +} +/** + * List available tools on the server + */ +async function listTools(client) { + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, types_js_1.ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - ${tool.name}: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server: ${error}`); + } +} +/** + * Start multiple notification tools in parallel with different configurations + * Each tool call includes a caller parameter to identify its notifications + */ +async function startParallelNotificationTools(client) { + try { + // Define multiple tool calls with different configurations + const toolCalls = [ + { + caller: 'fast-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 2, // 0.5 second between notifications + count: 10, // Send 10 notifications + caller: 'fast-notifier' // Identify this tool call + } + } + } + }, + { + caller: 'slow-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 5, // 2 seconds between notifications + count: 5, // Send 5 notifications + caller: 'slow-notifier' // Identify this tool call + } + } + } + }, + { + caller: 'burst-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 1, // 0.1 second between notifications + count: 3, // Send just 3 notifications + caller: 'burst-notifier' // Identify this tool call + } + } + } + } + ]; + console.log(`Starting ${toolCalls.length} notification tools in parallel...`); + // Start all tool calls in parallel + const toolPromises = toolCalls.map(({ caller, request }) => { + console.log(`Starting tool call for ${caller}...`); + return client + .request(request, types_js_1.CallToolResultSchema) + .then(result => ({ caller, result })) + .catch(error => { + console.error(`Error in tool call for ${caller}:`, error); + throw error; + }); + }); + // Wait for all tool calls to complete + const results = await Promise.all(toolPromises); + // Organize results by caller + const resultsByTool = {}; + results.forEach(({ caller, result }) => { + resultsByTool[caller] = result; + }); + return resultsByTool; + } + catch (error) { + console.error(`Error starting parallel notification tools:`, error); + throw error; + } +} +// Start the client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=parallelToolCallsClient.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/parallelToolCallsClient.js.map b/dist/cjs/examples/client/parallelToolCallsClient.js.map new file mode 100644 index 000000000..dabdf4895 --- /dev/null +++ b/dist/cjs/examples/client/parallelToolCallsClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"parallelToolCallsClient.js","sourceRoot":"","sources":["../../../../src/examples/client/parallelToolCallsClient.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,sEAA+E;AAC/E,6CAMwB;AAExB;;;;;;GAMG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,2BAA2B,CAAC;AAEzD,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,EAAE,CAAC,CAAC;IAErD,IAAI,MAAc,CAAC;IACnB,IAAI,SAAwC,CAAC;IAE7C,IAAI,CAAC;QACD,+CA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CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleClientCredentials.d.ts b/dist/cjs/examples/client/simpleClientCredentials.d.ts new file mode 100644 index 000000000..876d25d3a --- /dev/null +++ b/dist/cjs/examples/client/simpleClientCredentials.d.ts @@ -0,0 +1,20 @@ +#!/usr/bin/env node +/** + * Example demonstrating client_credentials grant for machine-to-machine authentication. + * + * Supports two authentication methods based on environment variables: + * + * 1. client_secret_basic (default): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_SECRET - OAuth client secret (required) + * + * 2. private_key_jwt (when MCP_CLIENT_PRIVATE_KEY_PEM is set): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_PRIVATE_KEY_PEM - PEM-encoded private key for JWT signing (required) + * MCP_CLIENT_ALGORITHM - Signing algorithm (default: RS256) + * + * Common: + * MCP_SERVER_URL - Server URL (default: http://localhost:3000/mcp) + */ +export {}; +//# sourceMappingURL=simpleClientCredentials.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleClientCredentials.d.ts.map b/dist/cjs/examples/client/simpleClientCredentials.d.ts.map new file mode 100644 index 000000000..7a935db41 --- /dev/null +++ b/dist/cjs/examples/client/simpleClientCredentials.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleClientCredentials.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleClientCredentials.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;GAgBG"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleClientCredentials.js b/dist/cjs/examples/client/simpleClientCredentials.js new file mode 100644 index 000000000..0b251b1a1 --- /dev/null +++ b/dist/cjs/examples/client/simpleClientCredentials.js @@ -0,0 +1,70 @@ +#!/usr/bin/env node +"use strict"; +/** + * Example demonstrating client_credentials grant for machine-to-machine authentication. + * + * Supports two authentication methods based on environment variables: + * + * 1. client_secret_basic (default): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_SECRET - OAuth client secret (required) + * + * 2. private_key_jwt (when MCP_CLIENT_PRIVATE_KEY_PEM is set): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_PRIVATE_KEY_PEM - PEM-encoded private key for JWT signing (required) + * MCP_CLIENT_ALGORITHM - Signing algorithm (default: RS256) + * + * Common: + * MCP_SERVER_URL - Server URL (default: http://localhost:3000/mcp) + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const auth_extensions_js_1 = require("../../client/auth-extensions.js"); +const DEFAULT_SERVER_URL = process.env.MCP_SERVER_URL || 'http://localhost:3000/mcp'; +function createProvider() { + const clientId = process.env.MCP_CLIENT_ID; + if (!clientId) { + console.error('MCP_CLIENT_ID environment variable is required'); + process.exit(1); + } + // If private key is provided, use private_key_jwt authentication + const privateKeyPem = process.env.MCP_CLIENT_PRIVATE_KEY_PEM; + if (privateKeyPem) { + const algorithm = process.env.MCP_CLIENT_ALGORITHM || 'RS256'; + console.log('Using private_key_jwt authentication'); + return new auth_extensions_js_1.PrivateKeyJwtProvider({ + clientId, + privateKey: privateKeyPem, + algorithm + }); + } + // Otherwise, use client_secret_basic authentication + const clientSecret = process.env.MCP_CLIENT_SECRET; + if (!clientSecret) { + console.error('MCP_CLIENT_SECRET or MCP_CLIENT_PRIVATE_KEY_PEM environment variable is required'); + process.exit(1); + } + console.log('Using client_secret_basic authentication'); + return new auth_extensions_js_1.ClientCredentialsProvider({ + clientId, + clientSecret + }); +} +async function main() { + const provider = createProvider(); + const client = new index_js_1.Client({ name: 'client-credentials-example', version: '1.0.0' }, { capabilities: {} }); + const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(DEFAULT_SERVER_URL), { + authProvider: provider + }); + await client.connect(transport); + console.log('Connected successfully.'); + const tools = await client.listTools(); + console.log('Available tools:', tools.tools.map(t => t.name).join(', ') || '(none)'); + await transport.close(); +} +main().catch(err => { + console.error(err); + process.exit(1); +}); +//# sourceMappingURL=simpleClientCredentials.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleClientCredentials.js.map b/dist/cjs/examples/client/simpleClientCredentials.js.map new file mode 100644 index 000000000..65e4b525b --- /dev/null +++ b/dist/cjs/examples/client/simpleClientCredentials.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleClientCredentials.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleClientCredentials.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;GAgBG;;AAEH,oDAA+C;AAC/C,sEAA+E;AAC/E,wEAAmG;AAGnG,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,2BAA2B,CAAC;AAErF,SAAS,cAAc;IACnB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,iEAAiE;IACjE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;IAC7D,IAAI,aAAa,EAAE,CAAC;QAChB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QACpD,OAAO,IAAI,0CAAqB,CAAC;YAC7B,QAAQ;YACR,UAAU,EAAE,aAAa;YACzB,SAAS;SACZ,CAAC,CAAC;IACP,CAAC;IAED,oDAAoD;IACpD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACnD,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAC;QAClG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,OAAO,IAAI,8CAAyB,CAAC;QACjC,QAAQ;QACR,YAAY;KACf,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,IAAI;IACf,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAC;IAElC,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC,EAAE,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IAE1G,MAAM,SAAS,GAAG,IAAI,iDAA6B,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,EAAE;QAC7E,YAAY,EAAE,QAAQ;KACzB,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC;IAErF,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClient.d.ts b/dist/cjs/examples/client/simpleOAuthClient.d.ts new file mode 100644 index 000000000..e4b43dbc0 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClient.d.ts @@ -0,0 +1,3 @@ +#!/usr/bin/env node +export {}; +//# sourceMappingURL=simpleOAuthClient.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClient.d.ts.map b/dist/cjs/examples/client/simpleOAuthClient.d.ts.map new file mode 100644 index 000000000..c09eef86e --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClient.js b/dist/cjs/examples/client/simpleOAuthClient.js new file mode 100644 index 000000000..d4042e529 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClient.js @@ -0,0 +1,413 @@ +#!/usr/bin/env node +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const node_http_1 = require("node:http"); +const node_readline_1 = require("node:readline"); +const node_url_1 = require("node:url"); +const node_child_process_1 = require("node:child_process"); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +const auth_js_1 = require("../../client/auth.js"); +const simpleOAuthClientProvider_js_1 = require("./simpleOAuthClientProvider.js"); +// Configuration +const DEFAULT_SERVER_URL = 'http://localhost:3000/mcp'; +const CALLBACK_PORT = 8090; // Use different port than auth server (3001) +const CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`; +/** + * Interactive MCP client with OAuth authentication + * Demonstrates the complete OAuth flow with browser-based authorization + */ +class InteractiveOAuthClient { + constructor(serverUrl, clientMetadataUrl) { + this.serverUrl = serverUrl; + this.clientMetadataUrl = clientMetadataUrl; + this.client = null; + this.rl = (0, node_readline_1.createInterface)({ + input: process.stdin, + output: process.stdout + }); + } + /** + * Prompts user for input via readline + */ + async question(query) { + return new Promise(resolve => { + this.rl.question(query, resolve); + }); + } + /** + * Opens the authorization URL in the user's default browser + */ + async openBrowser(url) { + console.log(`🌐 Opening browser for authorization: ${url}`); + const command = `open "${url}"`; + (0, node_child_process_1.exec)(command, error => { + if (error) { + console.error(`Failed to open browser: ${error.message}`); + console.log(`Please manually open: ${url}`); + } + }); + } + /** + * Example OAuth callback handler - in production, use a more robust approach + * for handling callbacks and storing tokens + */ + /** + * Starts a temporary HTTP server to receive the OAuth callback + */ + async waitForOAuthCallback() { + return new Promise((resolve, reject) => { + const server = (0, node_http_1.createServer)((req, res) => { + // Ignore favicon requests + if (req.url === '/favicon.ico') { + res.writeHead(404); + res.end(); + return; + } + console.log(`📥 Received callback: ${req.url}`); + const parsedUrl = new node_url_1.URL(req.url || '', 'http://localhost'); + const code = parsedUrl.searchParams.get('code'); + const error = parsedUrl.searchParams.get('error'); + if (code) { + console.log(`✅ Authorization code received: ${code === null || code === void 0 ? void 0 : code.substring(0, 10)}...`); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Successful!

+

You can close this window and return to the terminal.

+ + + + `); + resolve(code); + setTimeout(() => server.close(), 3000); + } + else if (error) { + console.log(`❌ Authorization error: ${error}`); + res.writeHead(400, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Failed

+

Error: ${error}

+ + + `); + reject(new Error(`OAuth authorization failed: ${error}`)); + } + else { + console.log(`❌ No authorization code or error in callback`); + res.writeHead(400); + res.end('Bad request'); + reject(new Error('No authorization code provided')); + } + }); + server.listen(CALLBACK_PORT, () => { + console.log(`OAuth callback server started on http://localhost:${CALLBACK_PORT}`); + }); + }); + } + async attemptConnection(oauthProvider) { + console.log('🚢 Creating transport with OAuth provider...'); + const baseUrl = new node_url_1.URL(this.serverUrl); + const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(baseUrl, { + authProvider: oauthProvider + }); + console.log('🚢 Transport created'); + try { + console.log('🔌 Attempting connection (this will trigger OAuth redirect)...'); + await this.client.connect(transport); + console.log('✅ Connected successfully'); + } + catch (error) { + if (error instanceof auth_js_1.UnauthorizedError) { + console.log('🔐 OAuth required - waiting for authorization...'); + const callbackPromise = this.waitForOAuthCallback(); + const authCode = await callbackPromise; + await transport.finishAuth(authCode); + console.log('🔐 Authorization code received:', authCode); + console.log('🔌 Reconnecting with authenticated transport...'); + await this.attemptConnection(oauthProvider); + } + else { + console.error('❌ Connection failed with non-auth error:', error); + throw error; + } + } + } + /** + * Establishes connection to the MCP server with OAuth authentication + */ + async connect() { + console.log(`🔗 Attempting to connect to ${this.serverUrl}...`); + const clientMetadata = { + client_name: 'Simple OAuth MCP Client', + redirect_uris: [CALLBACK_URL], + grant_types: ['authorization_code', 'refresh_token'], + response_types: ['code'], + token_endpoint_auth_method: 'client_secret_post' + }; + console.log('🔐 Creating OAuth provider...'); + const oauthProvider = new simpleOAuthClientProvider_js_1.InMemoryOAuthClientProvider(CALLBACK_URL, clientMetadata, (redirectUrl) => { + console.log(`📌 OAuth redirect handler called - opening browser`); + console.log(`Opening browser to: ${redirectUrl.toString()}`); + this.openBrowser(redirectUrl.toString()); + }, this.clientMetadataUrl); + console.log('🔐 OAuth provider created'); + console.log('👤 Creating MCP client...'); + this.client = new index_js_1.Client({ + name: 'simple-oauth-client', + version: '1.0.0' + }, { capabilities: {} }); + console.log('👤 Client created'); + console.log('🔐 Starting OAuth flow...'); + await this.attemptConnection(oauthProvider); + // Start interactive loop + await this.interactiveLoop(); + } + /** + * Main interactive loop for user commands + */ + async interactiveLoop() { + console.log('\n🎯 Interactive MCP Client with OAuth'); + console.log('Commands:'); + console.log(' list - List available tools'); + console.log(' call [args] - Call a tool'); + console.log(' stream [args] - Call a tool with streaming (shows task status)'); + console.log(' quit - Exit the client'); + console.log(); + while (true) { + try { + const command = await this.question('mcp> '); + if (!command.trim()) { + continue; + } + if (command === 'quit') { + console.log('\n👋 Goodbye!'); + this.close(); + process.exit(0); + } + else if (command === 'list') { + await this.listTools(); + } + else if (command.startsWith('call ')) { + await this.handleCallTool(command); + } + else if (command.startsWith('stream ')) { + await this.handleStreamTool(command); + } + else { + console.log("❌ Unknown command. Try 'list', 'call ', 'stream ', or 'quit'"); + } + } + catch (error) { + if (error instanceof Error && error.message === 'SIGINT') { + console.log('\n\n👋 Goodbye!'); + break; + } + console.error('❌ Error:', error); + } + } + } + async listTools() { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + const request = { + method: 'tools/list', + params: {} + }; + const result = await this.client.request(request, types_js_1.ListToolsResultSchema); + if (result.tools && result.tools.length > 0) { + console.log('\n📋 Available tools:'); + result.tools.forEach((tool, index) => { + console.log(`${index + 1}. ${tool.name}`); + if (tool.description) { + console.log(` Description: ${tool.description}`); + } + console.log(); + }); + } + else { + console.log('No tools available'); + } + } + catch (error) { + console.error('❌ Failed to list tools:', error); + } + } + async handleCallTool(command) { + const parts = command.split(/\s+/); + const toolName = parts[1]; + if (!toolName) { + console.log('❌ Please specify a tool name'); + return; + } + // Parse arguments (simple JSON-like format) + let toolArgs = {}; + if (parts.length > 2) { + const argsString = parts.slice(2).join(' '); + try { + toolArgs = JSON.parse(argsString); + } + catch (_a) { + console.log('❌ Invalid arguments format (expected JSON)'); + return; + } + } + await this.callTool(toolName, toolArgs); + } + async callTool(toolName, toolArgs) { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name: toolName, + arguments: toolArgs + } + }; + const result = await this.client.request(request, types_js_1.CallToolResultSchema); + console.log(`\n🔧 Tool '${toolName}' result:`); + if (result.content) { + result.content.forEach(content => { + if (content.type === 'text') { + console.log(content.text); + } + else { + console.log(content); + } + }); + } + else { + console.log(result); + } + } + catch (error) { + console.error(`❌ Failed to call tool '${toolName}':`, error); + } + } + async handleStreamTool(command) { + const parts = command.split(/\s+/); + const toolName = parts[1]; + if (!toolName) { + console.log('❌ Please specify a tool name'); + return; + } + // Parse arguments (simple JSON-like format) + let toolArgs = {}; + if (parts.length > 2) { + const argsString = parts.slice(2).join(' '); + try { + toolArgs = JSON.parse(argsString); + } + catch (_a) { + console.log('❌ Invalid arguments format (expected JSON)'); + return; + } + } + await this.streamTool(toolName, toolArgs); + } + async streamTool(toolName, toolArgs) { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + // Using the experimental tasks API - WARNING: may change without notice + console.log(`\n🔧 Streaming tool '${toolName}'...`); + const stream = this.client.experimental.tasks.callToolStream({ + name: toolName, + arguments: toolArgs + }, types_js_1.CallToolResultSchema, { + task: { + taskId: `task-${Date.now()}`, + ttl: 60000 + } + }); + // Iterate through all messages yielded by the generator + for await (const message of stream) { + switch (message.type) { + case 'taskCreated': + console.log(`✓ Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`⟳ Status: ${message.task.status}`); + if (message.task.statusMessage) { + console.log(` ${message.task.statusMessage}`); + } + break; + case 'result': + console.log('✓ Completed!'); + message.result.content.forEach(content => { + if (content.type === 'text') { + console.log(content.text); + } + else { + console.log(content); + } + }); + break; + case 'error': + console.log('✗ Error:'); + console.log(` ${message.error.message}`); + break; + } + } + } + catch (error) { + console.error(`❌ Failed to stream tool '${toolName}':`, error); + } + } + close() { + this.rl.close(); + if (this.client) { + // Note: Client doesn't have a close method in the current implementation + // This would typically close the transport connection + } + } +} +/** + * Main entry point + */ +async function main() { + const args = process.argv.slice(2); + const serverUrl = args[0] || DEFAULT_SERVER_URL; + const clientMetadataUrl = args[1]; + console.log('🚀 Simple MCP OAuth Client'); + console.log(`Connecting to: ${serverUrl}`); + if (clientMetadataUrl) { + console.log(`Client Metadata URL: ${clientMetadataUrl}`); + } + console.log(); + const client = new InteractiveOAuthClient(serverUrl, clientMetadataUrl); + // Handle graceful shutdown + process.on('SIGINT', () => { + console.log('\n\n👋 Goodbye!'); + client.close(); + process.exit(0); + }); + try { + await client.connect(); + } + catch (error) { + console.error('Failed to start client:', error); + process.exit(1); + } + finally { + client.close(); + } +} +// Run if this file is executed directly +main().catch(error => { + console.error('Unhandled error:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleOAuthClient.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClient.js.map b/dist/cjs/examples/client/simpleOAuthClient.js.map new file mode 100644 index 000000000..f72e52416 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClient.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClient.ts"],"names":[],"mappings":";;;AAEA,yCAAyC;AACzC,iDAAgD;AAChD,uCAA+B;AAC/B,2DAA0C;AAC1C,oDAA+C;AAC/C,sEAA+E;AAE/E,6CAAgH;AAChH,kDAAyD;AACzD,iFAA6E;AAE7E,gBAAgB;AAChB,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,6CAA6C;AACzE,MAAM,YAAY,GAAG,oBAAoB,aAAa,WAAW,CAAC;AAElE;;;GAGG;AACH,MAAM,sBAAsB;IAOxB,YACY,SAAiB,EACjB,iBAA0B;QAD1B,cAAS,GAAT,SAAS,CAAQ;QACjB,sBAAiB,GAAjB,iBAAiB,CAAS;QAR9B,WAAM,GAAkB,IAAI,CAAC;QACpB,OAAE,GAAG,IAAA,+BAAe,EAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACzB,CAAC,CAAC;IAKA,CAAC;IAEJ;;OAEG;IACK,KAAK,CAAC,QAAQ,CAAC,KAAa;QAChC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YACzB,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,WAAW,CAAC,GAAW;QACjC,OAAO,CAAC,GAAG,CAAC,yCAAyC,GAAG,EAAE,CAAC,CAAC;QAE5D,MAAM,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC;QAEhC,IAAA,yBAAI,EAAC,OAAO,EAAE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CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;AACL,CAAC;AAED,wCAAwC;AACxC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts b/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts new file mode 100644 index 000000000..092616cf5 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts @@ -0,0 +1,26 @@ +import { OAuthClientProvider } from '../../client/auth.js'; +import { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from '../../shared/auth.js'; +/** + * In-memory OAuth client provider for demonstration purposes + * In production, you should persist tokens securely + */ +export declare class InMemoryOAuthClientProvider implements OAuthClientProvider { + private readonly _redirectUrl; + private readonly _clientMetadata; + readonly clientMetadataUrl?: string | undefined; + private _clientInformation?; + private _tokens?; + private _codeVerifier?; + constructor(_redirectUrl: string | URL, _clientMetadata: OAuthClientMetadata, onRedirect?: (url: URL) => void, clientMetadataUrl?: string | undefined); + private _onRedirect; + get redirectUrl(): string | URL; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformationMixed | undefined; + saveClientInformation(clientInformation: OAuthClientInformationMixed): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(authorizationUrl: URL): void; + saveCodeVerifier(codeVerifier: string): void; + codeVerifier(): string; +} +//# sourceMappingURL=simpleOAuthClientProvider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts.map b/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts.map new file mode 100644 index 000000000..21efe9444 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClientProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAErG;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IAM/D,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe;aAEhB,iBAAiB,CAAC,EAAE,MAAM;IAR9C,OAAO,CAAC,kBAAkB,CAAC,CAA8B;IACzD,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAS;gBAGV,YAAY,EAAE,MAAM,GAAG,GAAG,EAC1B,eAAe,EAAE,mBAAmB,EACrD,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,EACf,iBAAiB,CAAC,EAAE,MAAM,YAAA;IAS9C,OAAO,CAAC,WAAW,CAAqB;IAExC,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,CAE9B;IAED,IAAI,cAAc,IAAI,mBAAmB,CAExC;IAED,iBAAiB,IAAI,2BAA2B,GAAG,SAAS;IAI5D,qBAAqB,CAAC,iBAAiB,EAAE,2BAA2B,GAAG,IAAI;IAI3E,MAAM,IAAI,WAAW,GAAG,SAAS;IAIjC,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIrC,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,IAAI;IAIpD,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAI5C,YAAY,IAAI,MAAM;CAMzB"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClientProvider.js b/dist/cjs/examples/client/simpleOAuthClientProvider.js new file mode 100644 index 000000000..58959bbfc --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClientProvider.js @@ -0,0 +1,51 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemoryOAuthClientProvider = void 0; +/** + * In-memory OAuth client provider for demonstration purposes + * In production, you should persist tokens securely + */ +class InMemoryOAuthClientProvider { + constructor(_redirectUrl, _clientMetadata, onRedirect, clientMetadataUrl) { + this._redirectUrl = _redirectUrl; + this._clientMetadata = _clientMetadata; + this.clientMetadataUrl = clientMetadataUrl; + this._onRedirect = + onRedirect || + (url => { + console.log(`Redirect to: ${url.toString()}`); + }); + } + get redirectUrl() { + return this._redirectUrl; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInformation; + } + saveClientInformation(clientInformation) { + this._clientInformation = clientInformation; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization(authorizationUrl) { + this._onRedirect(authorizationUrl); + } + saveCodeVerifier(codeVerifier) { + this._codeVerifier = codeVerifier; + } + codeVerifier() { + if (!this._codeVerifier) { + throw new Error('No code verifier saved'); + } + return this._codeVerifier; + } +} +exports.InMemoryOAuthClientProvider = InMemoryOAuthClientProvider; +//# sourceMappingURL=simpleOAuthClientProvider.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleOAuthClientProvider.js.map b/dist/cjs/examples/client/simpleOAuthClientProvider.js.map new file mode 100644 index 000000000..10771f8e5 --- /dev/null +++ b/dist/cjs/examples/client/simpleOAuthClientProvider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClientProvider.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClientProvider.ts"],"names":[],"mappings":";;;AAGA;;;GAGG;AACH,MAAa,2BAA2B;IAKpC,YACqB,YAA0B,EAC1B,eAAoC,EACrD,UAA+B,EACf,iBAA0B;QAHzB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,oBAAe,GAAf,eAAe,CAAqB;QAErC,sBAAiB,GAAjB,iBAAiB,CAAS;QAE1C,IAAI,CAAC,WAAW;YACZ,UAAU;gBACV,CAAC,GAAG,CAAC,EAAE;oBACH,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAClD,CAAC,CAAC,CAAC;IACX,CAAC;IAID,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED,qBAAqB,CAAC,iBAA8C;QAChE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChD,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,MAAmB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,uBAAuB,CAAC,gBAAqB;QACzC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB,CAAC,YAAoB;QACjC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACtC,CAAC;IAED,YAAY;QACR,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;CACJ;AA1DD,kEA0DC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleStreamableHttp.d.ts b/dist/cjs/examples/client/simpleStreamableHttp.d.ts new file mode 100644 index 000000000..a20be42ca --- /dev/null +++ b/dist/cjs/examples/client/simpleStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleStreamableHttp.d.ts.map b/dist/cjs/examples/client/simpleStreamableHttp.d.ts.map new file mode 100644 index 000000000..28406b0c1 --- /dev/null +++ b/dist/cjs/examples/client/simpleStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleStreamableHttp.js b/dist/cjs/examples/client/simpleStreamableHttp.js new file mode 100644 index 000000000..cc3675498 --- /dev/null +++ b/dist/cjs/examples/client/simpleStreamableHttp.js @@ -0,0 +1,820 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const node_readline_1 = require("node:readline"); +const types_js_1 = require("../../types.js"); +const metadataUtils_js_1 = require("../../shared/metadataUtils.js"); +const ajv_1 = require("ajv"); +// Create readline interface for user input +const readline = (0, node_readline_1.createInterface)({ + input: process.stdin, + output: process.stdout +}); +// Track received notifications for debugging resumability +let notificationCount = 0; +// Global client and transport for interactive commands +let client = null; +let transport = null; +let serverUrl = 'http://localhost:3000/mcp'; +let notificationsToolLastEventId = undefined; +let sessionId = undefined; +async function main() { + console.log('MCP Interactive Client'); + console.log('====================='); + // Connect to server immediately with default settings + await connect(); + // Print help and start the command loop + printHelp(); + commandLoop(); +} +function printHelp() { + console.log('\nAvailable commands:'); + console.log(' connect [url] - Connect to MCP server (default: http://localhost:3000/mcp)'); + console.log(' disconnect - Disconnect from server'); + console.log(' terminate-session - Terminate the current session'); + console.log(' reconnect - Reconnect to the server'); + console.log(' list-tools - List available tools'); + console.log(' call-tool [args] - Call a tool with optional JSON arguments'); + console.log(' call-tool-task [args] - Call a tool with task-based execution (example: call-tool-task delay {"duration":3000})'); + console.log(' greet [name] - Call the greet tool'); + console.log(' multi-greet [name] - Call the multi-greet tool with notifications'); + console.log(' collect-info [type] - Test form elicitation with collect-user-info tool (contact/preferences/feedback)'); + console.log(' start-notifications [interval] [count] - Start periodic notifications'); + console.log(' run-notifications-tool-with-resumability [interval] [count] - Run notification tool with resumability'); + console.log(' list-prompts - List available prompts'); + console.log(' get-prompt [name] [args] - Get a prompt with optional JSON arguments'); + console.log(' list-resources - List available resources'); + console.log(' read-resource - Read a specific resource by URI'); + console.log(' help - Show this help'); + console.log(' quit - Exit the program'); +} +function commandLoop() { + readline.question('\n> ', async (input) => { + var _a; + const args = input.trim().split(/\s+/); + const command = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + try { + switch (command) { + case 'connect': + await connect(args[1]); + break; + case 'disconnect': + await disconnect(); + break; + case 'terminate-session': + await terminateSession(); + break; + case 'reconnect': + await reconnect(); + break; + case 'list-tools': + await listTools(); + break; + case 'call-tool': + if (args.length < 2) { + console.log('Usage: call-tool [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_b) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callTool(toolName, toolArgs); + } + break; + case 'greet': + await callGreetTool(args[1] || 'MCP User'); + break; + case 'multi-greet': + await callMultiGreetTool(args[1] || 'MCP User'); + break; + case 'collect-info': + await callCollectInfoTool(args[1] || 'contact'); + break; + case 'start-notifications': { + const interval = args[1] ? parseInt(args[1], 10) : 2000; + const count = args[2] ? parseInt(args[2], 10) : 10; + await startNotifications(interval, count); + break; + } + case 'run-notifications-tool-with-resumability': { + const interval = args[1] ? parseInt(args[1], 10) : 2000; + const count = args[2] ? parseInt(args[2], 10) : 10; + await runNotificationsToolWithResumability(interval, count); + break; + } + case 'call-tool-task': + if (args.length < 2) { + console.log('Usage: call-tool-task [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_c) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callToolTask(toolName, toolArgs); + } + break; + case 'list-prompts': + await listPrompts(); + break; + case 'get-prompt': + if (args.length < 2) { + console.log('Usage: get-prompt [args]'); + } + else { + const promptName = args[1]; + let promptArgs = {}; + if (args.length > 2) { + try { + promptArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_d) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await getPrompt(promptName, promptArgs); + } + break; + case 'list-resources': + await listResources(); + break; + case 'read-resource': + if (args.length < 2) { + console.log('Usage: read-resource '); + } + else { + await readResource(args[1]); + } + break; + case 'help': + printHelp(); + break; + case 'quit': + case 'exit': + await cleanup(); + return; + default: + if (command) { + console.log(`Unknown command: ${command}`); + } + break; + } + } + catch (error) { + console.error(`Error executing command: ${error}`); + } + // Continue the command loop + commandLoop(); + }); +} +async function connect(url) { + if (client) { + console.log('Already connected. Disconnect first.'); + return; + } + if (url) { + serverUrl = url; + } + console.log(`Connecting to ${serverUrl}...`); + try { + // Create a new client with form elicitation capability + client = new index_js_1.Client({ + name: 'example-client', + version: '1.0.0' + }, { + capabilities: { + elicitation: { + form: {} + } + } + }); + client.onerror = error => { + console.error('\x1b[31mClient error:', error, '\x1b[0m'); + }; + // Set up elicitation request handler with proper validation + client.setRequestHandler(types_js_1.ElicitRequestSchema, async (request) => { + var _a, _b, _c; + if (request.params.mode !== 'form') { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Unsupported elicitation mode: ${request.params.mode}`); + } + console.log('\n🔔 Elicitation (form) Request Received:'); + console.log(`Message: ${request.params.message}`); + console.log(`Related Task: ${(_b = (_a = request.params._meta) === null || _a === void 0 ? void 0 : _a[types_js_1.RELATED_TASK_META_KEY]) === null || _b === void 0 ? void 0 : _b.taskId}`); + console.log('Requested Schema:'); + console.log(JSON.stringify(request.params.requestedSchema, null, 2)); + const schema = request.params.requestedSchema; + const properties = schema.properties; + const required = schema.required || []; + // Set up AJV validator for the requested schema + const ajv = new ajv_1.Ajv(); + const validate = ajv.compile(schema); + let attempts = 0; + const maxAttempts = 3; + while (attempts < maxAttempts) { + attempts++; + console.log(`\nPlease provide the following information (attempt ${attempts}/${maxAttempts}):`); + const content = {}; + let inputCancelled = false; + // Collect input for each field + for (const [fieldName, fieldSchema] of Object.entries(properties)) { + const field = fieldSchema; + const isRequired = required.includes(fieldName); + let prompt = `${field.title || fieldName}`; + // Add helpful information to the prompt + if (field.description) { + prompt += ` (${field.description})`; + } + if (field.enum) { + prompt += ` [options: ${field.enum.join(', ')}]`; + } + if (field.type === 'number' || field.type === 'integer') { + if (field.minimum !== undefined && field.maximum !== undefined) { + prompt += ` [${field.minimum}-${field.maximum}]`; + } + else if (field.minimum !== undefined) { + prompt += ` [min: ${field.minimum}]`; + } + else if (field.maximum !== undefined) { + prompt += ` [max: ${field.maximum}]`; + } + } + if (field.type === 'string' && field.format) { + prompt += ` [format: ${field.format}]`; + } + if (isRequired) { + prompt += ' *required*'; + } + if (field.default !== undefined) { + prompt += ` [default: ${field.default}]`; + } + prompt += ': '; + const answer = await new Promise(resolve => { + readline.question(prompt, input => { + resolve(input.trim()); + }); + }); + // Check for cancellation + if (answer.toLowerCase() === 'cancel' || answer.toLowerCase() === 'c') { + inputCancelled = true; + break; + } + // Parse and validate the input + try { + if (answer === '' && field.default !== undefined) { + content[fieldName] = field.default; + } + else if (answer === '' && !isRequired) { + // Skip optional empty fields + continue; + } + else if (answer === '') { + throw new Error(`${fieldName} is required`); + } + else { + // Parse the value based on type + let parsedValue; + if (field.type === 'boolean') { + parsedValue = answer.toLowerCase() === 'true' || answer.toLowerCase() === 'yes' || answer === '1'; + } + else if (field.type === 'number') { + parsedValue = parseFloat(answer); + if (isNaN(parsedValue)) { + throw new Error(`${fieldName} must be a valid number`); + } + } + else if (field.type === 'integer') { + parsedValue = parseInt(answer, 10); + if (isNaN(parsedValue)) { + throw new Error(`${fieldName} must be a valid integer`); + } + } + else if (field.enum) { + if (!field.enum.includes(answer)) { + throw new Error(`${fieldName} must be one of: ${field.enum.join(', ')}`); + } + parsedValue = answer; + } + else { + parsedValue = answer; + } + content[fieldName] = parsedValue; + } + } + catch (error) { + console.log(`❌ Error: ${error}`); + // Continue to next attempt + break; + } + } + if (inputCancelled) { + return { action: 'cancel' }; + } + // If we didn't complete all fields due to an error, try again + if (Object.keys(content).length !== + Object.keys(properties).filter(name => required.includes(name) || content[name] !== undefined).length) { + if (attempts < maxAttempts) { + console.log('Please try again...'); + continue; + } + else { + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + } + } + // Validate the complete object against the schema + const isValid = validate(content); + if (!isValid) { + console.log('❌ Validation errors:'); + (_c = validate.errors) === null || _c === void 0 ? void 0 : _c.forEach(error => { + console.log(` - ${error.instancePath || 'root'}: ${error.message}`); + }); + if (attempts < maxAttempts) { + console.log('Please correct the errors and try again...'); + continue; + } + else { + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + } + } + // Show the collected data and ask for confirmation + console.log('\n✅ Collected data:'); + console.log(JSON.stringify(content, null, 2)); + const confirmAnswer = await new Promise(resolve => { + readline.question('\nSubmit this information? (yes/no/cancel): ', input => { + resolve(input.trim().toLowerCase()); + }); + }); + if (confirmAnswer === 'yes' || confirmAnswer === 'y') { + return { + action: 'accept', + content + }; + } + else if (confirmAnswer === 'cancel' || confirmAnswer === 'c') { + return { action: 'cancel' }; + } + else if (confirmAnswer === 'no' || confirmAnswer === 'n') { + if (attempts < maxAttempts) { + console.log('Please re-enter the information...'); + continue; + } + else { + return { action: 'decline' }; + } + } + } + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + }); + transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(serverUrl), { + sessionId: sessionId + }); + // Set up notification handlers + client.setNotificationHandler(types_js_1.LoggingMessageNotificationSchema, notification => { + notificationCount++; + console.log(`\nNotification #${notificationCount}: ${notification.params.level} - ${notification.params.data}`); + // Re-display the prompt + process.stdout.write('> '); + }); + client.setNotificationHandler(types_js_1.ResourceListChangedNotificationSchema, async (_) => { + console.log(`\nResource list changed notification received!`); + try { + if (!client) { + console.log('Client disconnected, cannot fetch resources'); + return; + } + const resourcesResult = await client.request({ + method: 'resources/list', + params: {} + }, types_js_1.ListResourcesResultSchema); + console.log('Available resources count:', resourcesResult.resources.length); + } + catch (_a) { + console.log('Failed to list resources after change notification'); + } + // Re-display the prompt + process.stdout.write('> '); + }); + // Connect the client + await client.connect(transport); + sessionId = transport.sessionId; + console.log('Transport created with session ID:', sessionId); + console.log('Connected to MCP server'); + } + catch (error) { + console.error('Failed to connect:', error); + client = null; + transport = null; + } +} +async function disconnect() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + await transport.close(); + console.log('Disconnected from MCP server'); + client = null; + transport = null; + } + catch (error) { + console.error('Error disconnecting:', error); + } +} +async function terminateSession() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + console.log('Terminating session with ID:', transport.sessionId); + await transport.terminateSession(); + console.log('Session terminated successfully'); + // Check if sessionId was cleared after termination + if (!transport.sessionId) { + console.log('Session ID has been cleared'); + sessionId = undefined; + // Also close the transport and clear client objects + await transport.close(); + console.log('Transport closed after session termination'); + client = null; + transport = null; + } + else { + console.log('Server responded with 405 Method Not Allowed (session termination not supported)'); + console.log('Session ID is still active:', transport.sessionId); + } + } + catch (error) { + console.error('Error terminating session:', error); + } +} +async function reconnect() { + if (client) { + await disconnect(); + } + await connect(); +} +async function listTools() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, types_js_1.ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - id: ${tool.name}, name: ${(0, metadataUtils_js_1.getDisplayName)(tool)}, description: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server (${error})`); + } +} +async function callTool(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name, + arguments: args + } + }; + console.log(`Calling tool '${name}' with args:`, args); + const result = await client.request(request, types_js_1.CallToolResultSchema); + console.log('Tool result:'); + const resourceLinks = []; + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else if (item.type === 'resource_link') { + const resourceLink = item; + resourceLinks.push(resourceLink); + console.log(` 📁 Resource Link: ${resourceLink.name}`); + console.log(` URI: ${resourceLink.uri}`); + if (resourceLink.mimeType) { + console.log(` Type: ${resourceLink.mimeType}`); + } + if (resourceLink.description) { + console.log(` Description: ${resourceLink.description}`); + } + } + else if (item.type === 'resource') { + console.log(` [Embedded Resource: ${item.resource.uri}]`); + } + else if (item.type === 'image') { + console.log(` [Image: ${item.mimeType}]`); + } + else if (item.type === 'audio') { + console.log(` [Audio: ${item.mimeType}]`); + } + else { + console.log(` [Unknown content type]:`, item); + } + }); + // Offer to read resource links + if (resourceLinks.length > 0) { + console.log(`\nFound ${resourceLinks.length} resource link(s). Use 'read-resource ' to read their content.`); + } + } + catch (error) { + console.log(`Error calling tool ${name}: ${error}`); + } +} +async function callGreetTool(name) { + await callTool('greet', { name }); +} +async function callMultiGreetTool(name) { + console.log('Calling multi-greet tool with notifications...'); + await callTool('multi-greet', { name }); +} +async function callCollectInfoTool(infoType) { + console.log(`Testing form elicitation with collect-user-info tool (${infoType})...`); + await callTool('collect-user-info', { infoType }); +} +async function startNotifications(interval, count) { + console.log(`Starting notification stream: interval=${interval}ms, count=${count || 'unlimited'}`); + await callTool('start-notification-stream', { interval, count }); +} +async function runNotificationsToolWithResumability(interval, count) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + console.log(`Starting notification stream with resumability: interval=${interval}ms, count=${count || 'unlimited'}`); + console.log(`Using resumption token: ${notificationsToolLastEventId || 'none'}`); + const request = { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { interval, count } + } + }; + const onLastEventIdUpdate = (event) => { + notificationsToolLastEventId = event; + console.log(`Updated resumption token: ${event}`); + }; + const result = await client.request(request, types_js_1.CallToolResultSchema, { + resumptionToken: notificationsToolLastEventId, + onresumptiontoken: onLastEventIdUpdate + }); + console.log('Tool result:'); + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + catch (error) { + console.log(`Error starting notification stream: ${error}`); + } +} +async function listPrompts() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const promptsRequest = { + method: 'prompts/list', + params: {} + }; + const promptsResult = await client.request(promptsRequest, types_js_1.ListPromptsResultSchema); + console.log('Available prompts:'); + if (promptsResult.prompts.length === 0) { + console.log(' No prompts available'); + } + else { + for (const prompt of promptsResult.prompts) { + console.log(` - id: ${prompt.name}, name: ${(0, metadataUtils_js_1.getDisplayName)(prompt)}, description: ${prompt.description}`); + } + } + } + catch (error) { + console.log(`Prompts not supported by this server (${error})`); + } +} +async function getPrompt(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const promptRequest = { + method: 'prompts/get', + params: { + name, + arguments: args + } + }; + const promptResult = await client.request(promptRequest, types_js_1.GetPromptResultSchema); + console.log('Prompt template:'); + promptResult.messages.forEach((msg, index) => { + console.log(` [${index + 1}] ${msg.role}: ${msg.content.type === 'text' ? msg.content.text : JSON.stringify(msg.content)}`); + }); + } + catch (error) { + console.log(`Error getting prompt ${name}: ${error}`); + } +} +async function listResources() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const resourcesRequest = { + method: 'resources/list', + params: {} + }; + const resourcesResult = await client.request(resourcesRequest, types_js_1.ListResourcesResultSchema); + console.log('Available resources:'); + if (resourcesResult.resources.length === 0) { + console.log(' No resources available'); + } + else { + for (const resource of resourcesResult.resources) { + console.log(` - id: ${resource.name}, name: ${(0, metadataUtils_js_1.getDisplayName)(resource)}, description: ${resource.uri}`); + } + } + } + catch (error) { + console.log(`Resources not supported by this server (${error})`); + } +} +async function readResource(uri) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'resources/read', + params: { uri } + }; + console.log(`Reading resource: ${uri}`); + const result = await client.request(request, types_js_1.ReadResourceResultSchema); + console.log('Resource contents:'); + for (const content of result.contents) { + console.log(` URI: ${content.uri}`); + if (content.mimeType) { + console.log(` Type: ${content.mimeType}`); + } + if ('text' in content && typeof content.text === 'string') { + console.log(' Content:'); + console.log(' ---'); + console.log(content.text + .split('\n') + .map((line) => ' ' + line) + .join('\n')); + console.log(' ---'); + } + else if ('blob' in content && typeof content.blob === 'string') { + console.log(` [Binary data: ${content.blob.length} bytes]`); + } + } + } + catch (error) { + console.log(`Error reading resource ${uri}: ${error}`); + } +} +async function callToolTask(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + console.log(`Calling tool '${name}' with task-based execution...`); + console.log('Arguments:', args); + // Use task-based execution - call now, fetch later + // Using the experimental tasks API - WARNING: may change without notice + console.log('This will return immediately while processing continues in the background...'); + try { + // Call the tool with task metadata using streaming API + const stream = client.experimental.tasks.callToolStream({ + name, + arguments: args + }, types_js_1.CallToolResultSchema, { + task: { + ttl: 60000 // Keep results for 60 seconds + } + }); + console.log('Waiting for task completion...'); + let lastStatus = ''; + for await (const message of stream) { + switch (message.type) { + case 'taskCreated': + console.log('Task created successfully with ID:', message.task.taskId); + break; + case 'taskStatus': + if (lastStatus !== message.task.status) { + console.log(` ${message.task.status}${message.task.statusMessage ? ` - ${message.task.statusMessage}` : ''}`); + } + lastStatus = message.task.status; + break; + case 'result': + console.log('Task completed!'); + console.log('Tool result:'); + message.result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + }); + break; + case 'error': + throw message.error; + } + } + } + catch (error) { + console.log(`Error with task-based execution: ${error}`); + } +} +async function cleanup() { + if (client && transport) { + try { + // First try to terminate the session gracefully + if (transport.sessionId) { + try { + console.log('Terminating session before exit...'); + await transport.terminateSession(); + console.log('Session terminated successfully'); + } + catch (error) { + console.error('Error terminating session:', error); + } + } + // Then close the transport + await transport.close(); + } + catch (error) { + console.error('Error closing transport:', error); + } + } + process.stdin.setRawMode(false); + readline.close(); + console.log('\nGoodbye!'); + process.exit(0); +} +// Set up raw mode for keyboard input to capture Escape key +process.stdin.setRawMode(true); +process.stdin.on('data', async (data) => { + // Check for Escape key (27) + if (data.length === 1 && data[0] === 27) { + console.log('\nESC key pressed. Disconnecting from server...'); + // Abort current operation and disconnect from server + if (client && transport) { + await disconnect(); + console.log('Disconnected. Press Enter to continue.'); + } + else { + console.log('Not connected to server.'); + } + // Re-display the prompt + process.stdout.write('> '); + } +}); +// Handle Ctrl+C +process.on('SIGINT', async () => { + console.log('\nReceived SIGINT. Cleaning up...'); + await cleanup(); +}); +// Start the interactive client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleStreamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleStreamableHttp.js.map b/dist/cjs/examples/client/simpleStreamableHttp.js.map new file mode 100644 index 000000000..94f718988 --- /dev/null +++ b/dist/cjs/examples/client/simpleStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleStreamableHttp.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,sEAA+E;AAC/E,iDAAgD;AAChD,6CAoBwB;AACxB,oEAA+D;AAC/D,6BAA0B;AAE1B,2CAA2C;AAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAe,EAAC;IA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YACnB,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC5C,CAAC;QAED,wBAAwB;QACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,gBAAgB;AAChB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,MAAM,OAAO,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,+BAA+B;AAC/B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts b/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts new file mode 100644 index 000000000..c79406602 --- /dev/null +++ b/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts @@ -0,0 +1,10 @@ +/** + * Simple interactive task client demonstrating elicitation and sampling responses. + * + * This client connects to simpleTaskInteractive.ts server and demonstrates: + * - Handling elicitation requests (y/n confirmation) + * - Handling sampling requests (returns a hardcoded haiku) + * - Using task-based tool execution with streaming + */ +export {}; +//# sourceMappingURL=simpleTaskInteractiveClient.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts.map b/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts.map new file mode 100644 index 000000000..89b73386e --- /dev/null +++ b/dist/cjs/examples/client/simpleTaskInteractiveClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractiveClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleTaskInteractiveClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"} \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleTaskInteractiveClient.js b/dist/cjs/examples/client/simpleTaskInteractiveClient.js new file mode 100644 index 000000000..724f6a93a --- /dev/null +++ b/dist/cjs/examples/client/simpleTaskInteractiveClient.js @@ -0,0 +1,158 @@ +"use strict"; +/** + * Simple interactive task client demonstrating elicitation and sampling responses. + * + * This client connects to simpleTaskInteractive.ts server and demonstrates: + * - Handling elicitation requests (y/n confirmation) + * - Handling sampling requests (returns a hardcoded haiku) + * - Using task-based tool execution with streaming + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const node_readline_1 = require("node:readline"); +const types_js_1 = require("../../types.js"); +// Create readline interface for user input +const readline = (0, node_readline_1.createInterface)({ + input: process.stdin, + output: process.stdout +}); +function question(prompt) { + return new Promise(resolve => { + readline.question(prompt, answer => { + resolve(answer.trim()); + }); + }); +} +function getTextContent(result) { + var _a; + const textContent = result.content.find((c) => c.type === 'text'); + return (_a = textContent === null || textContent === void 0 ? void 0 : textContent.text) !== null && _a !== void 0 ? _a : '(no text)'; +} +async function elicitationCallback(params) { + console.log(`\n[Elicitation] Server asks: ${params.message}`); + // Simple terminal prompt for y/n + const response = await question('Your response (y/n): '); + const confirmed = ['y', 'yes', 'true', '1'].includes(response.toLowerCase()); + console.log(`[Elicitation] Responding with: confirm=${confirmed}`); + return { action: 'accept', content: { confirm: confirmed } }; +} +async function samplingCallback(params) { + // Get the prompt from the first message + let prompt = 'unknown'; + if (params.messages && params.messages.length > 0) { + const firstMessage = params.messages[0]; + const content = firstMessage.content; + if (typeof content === 'object' && !Array.isArray(content) && content.type === 'text' && 'text' in content) { + prompt = content.text; + } + else if (Array.isArray(content)) { + const textPart = content.find(c => c.type === 'text' && 'text' in c); + if (textPart && 'text' in textPart) { + prompt = textPart.text; + } + } + } + console.log(`\n[Sampling] Server requests LLM completion for: ${prompt}`); + // Return a hardcoded haiku (in real use, call your LLM here) + const haiku = `Cherry blossoms fall +Softly on the quiet pond +Spring whispers goodbye`; + console.log('[Sampling] Responding with haiku'); + return { + model: 'mock-haiku-model', + role: 'assistant', + content: { type: 'text', text: haiku } + }; +} +async function run(url) { + console.log('Simple Task Interactive Client'); + console.log('=============================='); + console.log(`Connecting to ${url}...`); + // Create client with elicitation and sampling capabilities + const client = new index_js_1.Client({ name: 'simple-task-interactive-client', version: '1.0.0' }, { + capabilities: { + elicitation: { form: {} }, + sampling: {} + } + }); + // Set up elicitation request handler + client.setRequestHandler(types_js_1.ElicitRequestSchema, async (request) => { + if (request.params.mode && request.params.mode !== 'form') { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Unsupported elicitation mode: ${request.params.mode}`); + } + return elicitationCallback(request.params); + }); + // Set up sampling request handler + client.setRequestHandler(types_js_1.CreateMessageRequestSchema, async (request) => { + return samplingCallback(request.params); + }); + // Connect to server + const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(url)); + await client.connect(transport); + console.log('Connected!\n'); + // List tools + const toolsResult = await client.listTools(); + console.log(`Available tools: ${toolsResult.tools.map(t => t.name).join(', ')}`); + // Demo 1: Elicitation (confirm_delete) + console.log('\n--- Demo 1: Elicitation ---'); + console.log('Calling confirm_delete tool...'); + const confirmStream = client.experimental.tasks.callToolStream({ name: 'confirm_delete', arguments: { filename: 'important.txt' } }, types_js_1.CallToolResultSchema, { task: { ttl: 60000 } }); + for await (const message of confirmStream) { + switch (message.type) { + case 'taskCreated': + console.log(`Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`Task status: ${message.task.status}`); + break; + case 'result': + console.log(`Result: ${getTextContent(message.result)}`); + break; + case 'error': + console.error(`Error: ${message.error}`); + break; + } + } + // Demo 2: Sampling (write_haiku) + console.log('\n--- Demo 2: Sampling ---'); + console.log('Calling write_haiku tool...'); + const haikuStream = client.experimental.tasks.callToolStream({ name: 'write_haiku', arguments: { topic: 'autumn leaves' } }, types_js_1.CallToolResultSchema, { + task: { ttl: 60000 } + }); + for await (const message of haikuStream) { + switch (message.type) { + case 'taskCreated': + console.log(`Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`Task status: ${message.task.status}`); + break; + case 'result': + console.log(`Result:\n${getTextContent(message.result)}`); + break; + case 'error': + console.error(`Error: ${message.error}`); + break; + } + } + // Cleanup + console.log('\nDemo complete. Closing connection...'); + await transport.close(); + readline.close(); +} +// Parse command line arguments +const args = process.argv.slice(2); +let url = 'http://localhost:8000/mcp'; +for (let i = 0; i < args.length; i++) { + if (args[i] === '--url' && args[i + 1]) { + url = args[i + 1]; + i++; + } +} +// Run the client +run(url).catch(error => { + console.error('Error running client:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleTaskInteractiveClient.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/simpleTaskInteractiveClient.js.map b/dist/cjs/examples/client/simpleTaskInteractiveClient.js.map new file mode 100644 index 000000000..57009a3d6 --- /dev/null +++ b/dist/cjs/examples/client/simpleTaskInteractiveClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractiveClient.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleTaskInteractiveClient.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAEH,oDAA+C;AAC/C,sEAA+E;AAC/E,iDAAgD;AAChD,6CASwB;AAExB,2CAA2C;AAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAe,EAAC;IAC7B,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACzB,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,MAAc;IAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACzB,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE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AAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/ssePollingClient.d.ts b/dist/cjs/examples/client/ssePollingClient.d.ts new file mode 100644 index 000000000..134b4b0cf --- /dev/null +++ b/dist/cjs/examples/client/ssePollingClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=ssePollingClient.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/ssePollingClient.d.ts.map b/dist/cjs/examples/client/ssePollingClient.d.ts.map new file mode 100644 index 000000000..59e4153d2 --- /dev/null +++ b/dist/cjs/examples/client/ssePollingClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/ssePollingClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/ssePollingClient.js b/dist/cjs/examples/client/ssePollingClient.js new file mode 100644 index 000000000..a529ae55b --- /dev/null +++ b/dist/cjs/examples/client/ssePollingClient.js @@ -0,0 +1,95 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * SSE Polling Example Client (SEP-1699) + * + * This example demonstrates client-side behavior during server-initiated + * SSE stream disconnection and automatic reconnection. + * + * Key features demonstrated: + * - Automatic reconnection when server closes SSE stream + * - Event replay via Last-Event-ID header + * - Resumption token tracking via onresumptiontoken callback + * + * Run with: npx tsx src/examples/client/ssePollingClient.ts + * Requires: ssePollingExample.ts server running on port 3001 + */ +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +const SERVER_URL = 'http://localhost:3001/mcp'; +async function main() { + console.log('SSE Polling Example Client'); + console.log('=========================='); + console.log(`Connecting to ${SERVER_URL}...`); + console.log(''); + // Create transport with reconnection options + const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(SERVER_URL), { + // Use default reconnection options - SDK handles automatic reconnection + }); + // Track the last event ID for debugging + let lastEventId; + // Set up transport error handler to observe disconnections + // Filter out expected errors from SSE reconnection + transport.onerror = error => { + // Skip abort errors during intentional close + if (error.message.includes('AbortError')) + return; + // Show SSE disconnect (expected when server closes stream) + if (error.message.includes('Unexpected end of JSON')) { + console.log('[Transport] SSE stream disconnected - client will auto-reconnect'); + return; + } + console.log(`[Transport] Error: ${error.message}`); + }; + // Set up transport close handler + transport.onclose = () => { + console.log('[Transport] Connection closed'); + }; + // Create and connect client + const client = new index_js_1.Client({ + name: 'sse-polling-client', + version: '1.0.0' + }); + // Set up notification handler to receive progress updates + client.setNotificationHandler(types_js_1.LoggingMessageNotificationSchema, notification => { + const data = notification.params.data; + console.log(`[Notification] ${data}`); + }); + try { + await client.connect(transport); + console.log('[Client] Connected successfully'); + console.log(''); + // Call the long-task tool + console.log('[Client] Calling long-task tool...'); + console.log('[Client] Server will disconnect mid-task to demonstrate polling'); + console.log(''); + const result = await client.request({ + method: 'tools/call', + params: { + name: 'long-task', + arguments: {} + } + }, types_js_1.CallToolResultSchema, { + // Track resumption tokens for debugging + onresumptiontoken: token => { + lastEventId = token; + console.log(`[Event ID] ${token}`); + } + }); + console.log(''); + console.log('[Client] Tool completed!'); + console.log(`[Result] ${JSON.stringify(result.content, null, 2)}`); + console.log(''); + console.log(`[Debug] Final event ID: ${lastEventId}`); + } + catch (error) { + console.error('[Error]', error); + } + finally { + await transport.close(); + console.log('[Client] Disconnected'); + } +} +main().catch(console.error); +//# sourceMappingURL=ssePollingClient.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/ssePollingClient.js.map b/dist/cjs/examples/client/ssePollingClient.js.map new file mode 100644 index 000000000..bcc881d98 --- /dev/null +++ b/dist/cjs/examples/client/ssePollingClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingClient.js","sourceRoot":"","sources":["../../../../src/examples/client/ssePollingClient.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;GAaG;AACH,oDAA+C;AAC/C,sEAA+E;AAC/E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C,SAAS,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;YAAS,CAAC;QACP,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACzC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts new file mode 100644 index 000000000..c2679e669 --- /dev/null +++ b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=streamableHttpWithSseFallbackClient.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts.map b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts.map new file mode 100644 index 000000000..b79ae2a72 --- /dev/null +++ b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttpWithSseFallbackClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/streamableHttpWithSseFallbackClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js new file mode 100644 index 000000000..bf3e9a885 --- /dev/null +++ b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js @@ -0,0 +1,168 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_js_1 = require("../../client/index.js"); +const streamableHttp_js_1 = require("../../client/streamableHttp.js"); +const sse_js_1 = require("../../client/sse.js"); +const types_js_1 = require("../../types.js"); +/** + * Simplified Backwards Compatible MCP Client + * + * This client demonstrates backward compatibility with both: + * 1. Modern servers using Streamable HTTP transport (protocol version 2025-03-26) + * 2. Older servers using HTTP+SSE transport (protocol version 2024-11-05) + * + * Following the MCP specification for backwards compatibility: + * - Attempts to POST an initialize request to the server URL first (modern transport) + * - If that fails with 4xx status, falls back to GET request for SSE stream (older transport) + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function main() { + console.log('MCP Backwards Compatible Client'); + console.log('==============================='); + console.log(`Connecting to server at: ${serverUrl}`); + let client; + let transport; + try { + // Try connecting with automatic transport detection + const connection = await connectWithBackwardsCompatibility(serverUrl); + client = connection.client; + transport = connection.transport; + // Set up notification handler + client.setNotificationHandler(types_js_1.LoggingMessageNotificationSchema, notification => { + console.log(`Notification: ${notification.params.level} - ${notification.params.data}`); + }); + // DEMO WORKFLOW: + // 1. List available tools + console.log('\n=== Listing Available Tools ==='); + await listTools(client); + // 2. Call the notification tool + console.log('\n=== Starting Notification Stream ==='); + await startNotificationTool(client); + // 3. Wait for all notifications (5 seconds) + console.log('\n=== Waiting for all notifications ==='); + await new Promise(resolve => setTimeout(resolve, 5000)); + // 4. Disconnect + console.log('\n=== Disconnecting ==='); + await transport.close(); + console.log('Disconnected from MCP server'); + } + catch (error) { + console.error('Error running client:', error); + process.exit(1); + } +} +/** + * Connect to an MCP server with backwards compatibility + * Following the spec for client backward compatibility + */ +async function connectWithBackwardsCompatibility(url) { + console.log('1. Trying Streamable HTTP transport first...'); + // Step 1: Try Streamable HTTP transport first + const client = new index_js_1.Client({ + name: 'backwards-compatible-client', + version: '1.0.0' + }); + client.onerror = error => { + console.error('Client error:', error); + }; + const baseUrl = new URL(url); + try { + // Create modern transport + const streamableTransport = new streamableHttp_js_1.StreamableHTTPClientTransport(baseUrl); + await client.connect(streamableTransport); + console.log('Successfully connected using modern Streamable HTTP transport.'); + return { + client, + transport: streamableTransport, + transportType: 'streamable-http' + }; + } + catch (error) { + // Step 2: If transport fails, try the older SSE transport + console.log(`StreamableHttp transport connection failed: ${error}`); + console.log('2. Falling back to deprecated HTTP+SSE transport...'); + try { + // Create SSE transport pointing to /sse endpoint + const sseTransport = new sse_js_1.SSEClientTransport(baseUrl); + const sseClient = new index_js_1.Client({ + name: 'backwards-compatible-client', + version: '1.0.0' + }); + await sseClient.connect(sseTransport); + console.log('Successfully connected using deprecated HTTP+SSE transport.'); + return { + client: sseClient, + transport: sseTransport, + transportType: 'sse' + }; + } + catch (sseError) { + console.error(`Failed to connect with either transport method:\n1. Streamable HTTP error: ${error}\n2. SSE error: ${sseError}`); + throw new Error('Could not connect to server with any available transport'); + } + } +} +/** + * List available tools on the server + */ +async function listTools(client) { + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, types_js_1.ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - ${tool.name}: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server: ${error}`); + } +} +/** + * Start a notification stream by calling the notification tool + */ +async function startNotificationTool(client) { + try { + // Call the notification tool using reasonable defaults + const request = { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 1000, // 1 second between notifications + count: 5 // Send 5 notifications + } + } + }; + console.log('Calling notification tool...'); + const result = await client.request(request, types_js_1.CallToolResultSchema); + console.log('Tool result:'); + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + catch (error) { + console.log(`Error calling notification tool: ${error}`); + } +} +// Start the client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=streamableHttpWithSseFallbackClient.js.map \ No newline at end of file diff --git a/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js.map b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js.map new file mode 100644 index 000000000..f3bec99c5 --- /dev/null +++ b/dist/cjs/examples/client/streamableHttpWithSseFallbackClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttpWithSseFallbackClient.js","sourceRoot":"","sources":["../../../../src/examples/client/streamableHttpWithSseFallbackClient.ts"],"names":[],"mappings":";;AAAA,oDAA+C;AAC/C,sEAA+E;AAC/E,gDAAyD;AACzD,6CAMwB;AAExB;;;;;;;;;;GAUG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,2BAA2B,CAAC;AAEzD,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,EAAE,CAAC,CAAC;IAErD,IAAI,MAAc,CAAC;IACnB,IAAI,SAA6D,CAAC;IAElE,IAAI,CAAC;QACD,oDAAoD;QACpD,MAAM,UAAU,GAAG,MAAM,iCAAiC,CAAC,SAAS,CAAC,CAAC;QACtE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAC3B,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QAEjC,8BAA8B;QAC9B,MAAM,CAAC,sBAAsB,CAAC,2CAAgC,EAAE,YAAY,CAAC,EAAE;YAC3E,OAAO,CAAC,GAAG,CAAC,iBAAiB,YAAY,CAAC,MAAM,CAAC,KAAK,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5F,CAAC,CAAC,CAAC;QAEH,iBAAiB;QACjB,0BAA0B;QAC1B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;QAExB,gCAAgC;QAChC,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,MAAM,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAEpC,4CAA4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I,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts b/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts new file mode 100644 index 000000000..218aeac8b --- /dev/null +++ b/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts @@ -0,0 +1,78 @@ +import { AuthorizationParams, OAuthServerProvider } from '../../server/auth/provider.js'; +import { OAuthRegisteredClientsStore } from '../../server/auth/clients.js'; +import { OAuthClientInformationFull, OAuthMetadata, OAuthTokens } from '../../shared/auth.js'; +import { Response } from 'express'; +import { AuthInfo } from '../../server/auth/types.js'; +export declare class DemoInMemoryClientsStore implements OAuthRegisteredClientsStore { + private clients; + getClient(clientId: string): Promise<{ + redirect_uris: string[]; + client_id: string; + token_endpoint_auth_method?: string | undefined; + grant_types?: string[] | undefined; + response_types?: string[] | undefined; + client_name?: string | undefined; + client_uri?: string | undefined; + logo_uri?: string | undefined; + scope?: string | undefined; + contacts?: string[] | undefined; + tos_uri?: string | undefined; + policy_uri?: string | undefined; + jwks_uri?: string | undefined; + jwks?: any; + software_id?: string | undefined; + software_version?: string | undefined; + software_statement?: string | undefined; + client_secret?: string | undefined; + client_id_issued_at?: number | undefined; + client_secret_expires_at?: number | undefined; + } | undefined>; + registerClient(clientMetadata: OAuthClientInformationFull): Promise<{ + redirect_uris: string[]; + client_id: string; + token_endpoint_auth_method?: string | undefined; + grant_types?: string[] | undefined; + response_types?: string[] | undefined; + client_name?: string | undefined; + client_uri?: string | undefined; + logo_uri?: string | undefined; + scope?: string | undefined; + contacts?: string[] | undefined; + tos_uri?: string | undefined; + policy_uri?: string | undefined; + jwks_uri?: string | undefined; + jwks?: any; + software_id?: string | undefined; + software_version?: string | undefined; + software_statement?: string | undefined; + client_secret?: string | undefined; + client_id_issued_at?: number | undefined; + client_secret_expires_at?: number | undefined; + }>; +} +/** + * 🚨 DEMO ONLY - NOT FOR PRODUCTION + * + * This example demonstrates MCP OAuth flow but lacks some of the features required for production use, + * for example: + * - Persistent token storage + * - Rate limiting + */ +export declare class DemoInMemoryAuthProvider implements OAuthServerProvider { + private validateResource?; + clientsStore: DemoInMemoryClientsStore; + private codes; + private tokens; + constructor(validateResource?: ((resource?: URL) => boolean) | undefined); + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise; + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, _codeVerifier?: string): Promise; + exchangeRefreshToken(_client: OAuthClientInformationFull, _refreshToken: string, _scopes?: string[], _resource?: URL): Promise; + verifyAccessToken(token: string): Promise; +} +export declare const setupAuthServer: ({ authServerUrl, mcpServerUrl, strictResource }: { + authServerUrl: URL; + mcpServerUrl: URL; + strictResource: boolean; +}) => OAuthMetadata; +//# sourceMappingURL=demoInMemoryOAuthProvider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts.map b/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts.map new file mode 100644 index 000000000..8a4a43fe8 --- /dev/null +++ b/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"demoInMemoryOAuthProvider.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/demoInMemoryOAuthProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAg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ClB,cAAc,EAAE,OAAO,CAAC;CAC3B,KAAG,aA+EH,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/demoInMemoryOAuthProvider.js b/dist/cjs/examples/server/demoInMemoryOAuthProvider.js new file mode 100644 index 000000000..c439a3403 --- /dev/null +++ b/dist/cjs/examples/server/demoInMemoryOAuthProvider.js @@ -0,0 +1,205 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.setupAuthServer = exports.DemoInMemoryAuthProvider = exports.DemoInMemoryClientsStore = void 0; +const node_crypto_1 = require("node:crypto"); +const express_1 = __importDefault(require("express")); +const router_js_1 = require("../../server/auth/router.js"); +const auth_utils_js_1 = require("../../shared/auth-utils.js"); +const errors_js_1 = require("../../server/auth/errors.js"); +class DemoInMemoryClientsStore { + constructor() { + this.clients = new Map(); + } + async getClient(clientId) { + return this.clients.get(clientId); + } + async registerClient(clientMetadata) { + this.clients.set(clientMetadata.client_id, clientMetadata); + return clientMetadata; + } +} +exports.DemoInMemoryClientsStore = DemoInMemoryClientsStore; +/** + * 🚨 DEMO ONLY - NOT FOR PRODUCTION + * + * This example demonstrates MCP OAuth flow but lacks some of the features required for production use, + * for example: + * - Persistent token storage + * - Rate limiting + */ +class DemoInMemoryAuthProvider { + constructor(validateResource) { + this.validateResource = validateResource; + this.clientsStore = new DemoInMemoryClientsStore(); + this.codes = new Map(); + this.tokens = new Map(); + } + async authorize(client, params, res) { + const code = (0, node_crypto_1.randomUUID)(); + const searchParams = new URLSearchParams({ + code + }); + if (params.state !== undefined) { + searchParams.set('state', params.state); + } + this.codes.set(code, { + client, + params + }); + // Simulate a user login + // Set a secure HTTP-only session cookie with authorization info + if (res.cookie) { + const authCookieData = { + userId: 'demo_user', + name: 'Demo User', + timestamp: Date.now() + }; + res.cookie('demo_session', JSON.stringify(authCookieData), { + httpOnly: true, + secure: false, // In production, this should be true + sameSite: 'lax', + maxAge: 24 * 60 * 60 * 1000, // 24 hours - for demo purposes + path: '/' // Available to all routes + }); + } + if (!client.redirect_uris.includes(params.redirectUri)) { + throw new errors_js_1.InvalidRequestError('Unregistered redirect_uri'); + } + const targetUrl = new URL(params.redirectUri); + targetUrl.search = searchParams.toString(); + res.redirect(targetUrl.toString()); + } + async challengeForAuthorizationCode(client, authorizationCode) { + // Store the challenge with the code data + const codeData = this.codes.get(authorizationCode); + if (!codeData) { + throw new Error('Invalid authorization code'); + } + return codeData.params.codeChallenge; + } + async exchangeAuthorizationCode(client, authorizationCode, + // Note: code verifier is checked in token.ts by default + // it's unused here for that reason. + _codeVerifier) { + const codeData = this.codes.get(authorizationCode); + if (!codeData) { + throw new Error('Invalid authorization code'); + } + if (codeData.client.client_id !== client.client_id) { + throw new Error(`Authorization code was not issued to this client, ${codeData.client.client_id} != ${client.client_id}`); + } + if (this.validateResource && !this.validateResource(codeData.params.resource)) { + throw new Error(`Invalid resource: ${codeData.params.resource}`); + } + this.codes.delete(authorizationCode); + const token = (0, node_crypto_1.randomUUID)(); + const tokenData = { + token, + clientId: client.client_id, + scopes: codeData.params.scopes || [], + expiresAt: Date.now() + 3600000, // 1 hour + resource: codeData.params.resource, + type: 'access' + }; + this.tokens.set(token, tokenData); + return { + access_token: token, + token_type: 'bearer', + expires_in: 3600, + scope: (codeData.params.scopes || []).join(' ') + }; + } + async exchangeRefreshToken(_client, _refreshToken, _scopes, _resource) { + throw new Error('Not implemented for example demo'); + } + async verifyAccessToken(token) { + const tokenData = this.tokens.get(token); + if (!tokenData || !tokenData.expiresAt || tokenData.expiresAt < Date.now()) { + throw new Error('Invalid or expired token'); + } + return { + token, + clientId: tokenData.clientId, + scopes: tokenData.scopes, + expiresAt: Math.floor(tokenData.expiresAt / 1000), + resource: tokenData.resource + }; + } +} +exports.DemoInMemoryAuthProvider = DemoInMemoryAuthProvider; +const setupAuthServer = ({ authServerUrl, mcpServerUrl, strictResource }) => { + // Create separate auth server app + // NOTE: This is a separate app on a separate port to illustrate + // how to separate an OAuth Authorization Server from a Resource + // server in the SDK. The SDK is not intended to be provide a standalone + // authorization server. + const validateResource = strictResource + ? (resource) => { + if (!resource) + return false; + const expectedResource = (0, auth_utils_js_1.resourceUrlFromServerUrl)(mcpServerUrl); + return resource.toString() === expectedResource.toString(); + } + : undefined; + const provider = new DemoInMemoryAuthProvider(validateResource); + const authApp = (0, express_1.default)(); + authApp.use(express_1.default.json()); + // For introspection requests + authApp.use(express_1.default.urlencoded()); + // Add OAuth routes to the auth server + // NOTE: this will also add a protected resource metadata route, + // but it won't be used, so leave it. + authApp.use((0, router_js_1.mcpAuthRouter)({ + provider, + issuerUrl: authServerUrl, + scopesSupported: ['mcp:tools'] + })); + authApp.post('/introspect', async (req, res) => { + try { + const { token } = req.body; + if (!token) { + res.status(400).json({ error: 'Token is required' }); + return; + } + const tokenInfo = await provider.verifyAccessToken(token); + res.json({ + active: true, + client_id: tokenInfo.clientId, + scope: tokenInfo.scopes.join(' '), + exp: tokenInfo.expiresAt, + aud: tokenInfo.resource + }); + return; + } + catch (error) { + res.status(401).json({ + active: false, + error: 'Unauthorized', + error_description: `Invalid token: ${error}` + }); + } + }); + const auth_port = authServerUrl.port; + // Start the auth server + authApp.listen(auth_port, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`OAuth Authorization Server listening on port ${auth_port}`); + }); + // Note: we could fetch this from the server, but then we end up + // with some top level async which gets annoying. + const oauthMetadata = (0, router_js_1.createOAuthMetadata)({ + provider, + issuerUrl: authServerUrl, + scopesSupported: ['mcp:tools'] + }); + oauthMetadata.introspection_endpoint = new URL('/introspect', authServerUrl).href; + return oauthMetadata; +}; +exports.setupAuthServer = setupAuthServer; +//# sourceMappingURL=demoInMemoryOAuthProvider.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/demoInMemoryOAuthProvider.js.map b/dist/cjs/examples/server/demoInMemoryOAuthProvider.js.map new file mode 100644 index 000000000..e19a20db9 --- /dev/null +++ b/dist/cjs/examples/server/demoInMemoryOAuthProvider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"demoInMemoryOAuthProvider.js","sourceRoot":"","sources":["../../../../src/examples/server/demoInMemoryOAuthProvider.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAyC;AAIzC,sDAAqD;AAErD,2DAAiF;AACjF,8DAAsE;AACtE,2DAAkE;AAElE,MAAa,wBAAwB;IAArC;QACY,YAAO,GAAG,IAAI,GAAG,EAAsC,CAAC;IAUpE,CAAC;IARG,KAAK,CAAC,SAAS,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,cAA0C;QAC3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAC3D,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ;AAXD,4DAWC;AAED;;;;;;;GAOG;AACH,MAAa,wBAAwB;IAWjC,YAAoB,gBAA8C;QAA9C,qBAAgB,GAAhB,gBAAgB,CAA8B;QAVlE,iBAAY,GAAG,IAAI,wBAAwB,EAAE,CAAC;QACtC,UAAK,GAAG,IAAI,GAAG,EAMpB,CAAC;QACI,WAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEwB,CAAC;IAEtE,KAAK,CAAC,SAAS,CAAC,MAAkC,EAAE,MAA2B,EAAE,GAAa;QAC1F,MAAM,IAAI,GAAG,IAAA,wBAAU,GAAE,CAAC;QAE1B,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC;YACrC,IAAI;SACP,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IA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O;QACX,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,cAAc;gBACrB,iBAAiB,EAAE,kBAAkB,KAAK,EAAE;aAC/C,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC;IACrC,wBAAwB;IACxB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC9B,IAAI,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,gDAAgD,SAAS,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,gEAAgE;IAChE,iDAAiD;IACjD,MAAM,aAAa,GAAkB,IAAA,+BAAmB,EAAC;QACrD,QAAQ;QACR,SAAS,EAAE,aAAa;QACxB,eAAe,EAAE,CAAC,WAAW,CAAC;KACjC,CAAC,CAAC;IAEH,aAAa,CAAC,sBAAsB,GAAG,IAAI,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC;IAElF,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC;AAvFW,QAAA,eAAe,mBAuF1B"} \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationFormExample.d.ts b/dist/cjs/examples/server/elicitationFormExample.d.ts new file mode 100644 index 000000000..e4b736e0f --- /dev/null +++ b/dist/cjs/examples/server/elicitationFormExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationFormExample.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationFormExample.d.ts.map b/dist/cjs/examples/server/elicitationFormExample.d.ts.map new file mode 100644 index 000000000..c569df428 --- /dev/null +++ b/dist/cjs/examples/server/elicitationFormExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationFormExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/elicitationFormExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationFormExample.js b/dist/cjs/examples/server/elicitationFormExample.js new file mode 100644 index 000000000..e25ac9205 --- /dev/null +++ b/dist/cjs/examples/server/elicitationFormExample.js @@ -0,0 +1,441 @@ +"use strict"; +// Run with: npx tsx src/examples/server/elicitationFormExample.ts +// +// This example demonstrates how to use form elicitation to collect structured user input +// with JSON Schema validation via a local HTTP server with SSE streaming. +// Form elicitation allows servers to request *non-sensitive* user input through the client +// with schema-based validation. +// Note: See also elicitationUrlExample.ts for an example of using URL elicitation +// to collect *sensitive* user input via a browser. +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const node_crypto_1 = require("node:crypto"); +const cors_1 = __importDefault(require("cors")); +const express_1 = __importDefault(require("express")); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +// Create MCP server - it will automatically use AjvJsonSchemaValidator with sensible defaults +// The validator supports format validation (email, date, etc.) if ajv-formats is installed +const mcpServer = new mcp_js_1.McpServer({ + name: 'form-elicitation-example-server', + version: '1.0.0' +}, { + capabilities: {} +}); +/** + * Example 1: Simple user registration tool + * Collects username, email, and password from the user + */ +mcpServer.registerTool('register_user', { + description: 'Register a new user account by collecting their information', + inputSchema: {} +}, async () => { + try { + // Request user information through form elicitation + const result = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Please provide your registration information:', + requestedSchema: { + type: 'object', + properties: { + username: { + type: 'string', + title: 'Username', + description: 'Your desired username (3-20 characters)', + minLength: 3, + maxLength: 20 + }, + email: { + type: 'string', + title: 'Email', + description: 'Your email address', + format: 'email' + }, + password: { + type: 'string', + title: 'Password', + description: 'Your password (min 8 characters)', + minLength: 8 + }, + newsletter: { + type: 'boolean', + title: 'Newsletter', + description: 'Subscribe to newsletter?', + default: false + } + }, + required: ['username', 'email', 'password'] + } + }); + // Handle the different possible actions + if (result.action === 'accept' && result.content) { + const { username, email, newsletter } = result.content; + return { + content: [ + { + type: 'text', + text: `Registration successful!\n\nUsername: ${username}\nEmail: ${email}\nNewsletter: ${newsletter ? 'Yes' : 'No'}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [ + { + type: 'text', + text: 'Registration cancelled by user.' + } + ] + }; + } + else { + return { + content: [ + { + type: 'text', + text: 'Registration was cancelled.' + } + ] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Registration failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +/** + * Example 2: Multi-step workflow with multiple form elicitation requests + * Demonstrates how to collect information in multiple steps + */ +mcpServer.registerTool('create_event', { + description: 'Create a calendar event by collecting event details', + inputSchema: {} +}, async () => { + try { + // Step 1: Collect basic event information + const basicInfo = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Step 1: Enter basic event information', + requestedSchema: { + type: 'object', + properties: { + title: { + type: 'string', + title: 'Event Title', + description: 'Name of the event', + minLength: 1 + }, + description: { + type: 'string', + title: 'Description', + description: 'Event description (optional)' + } + }, + required: ['title'] + } + }); + if (basicInfo.action !== 'accept' || !basicInfo.content) { + return { + content: [{ type: 'text', text: 'Event creation cancelled.' }] + }; + } + // Step 2: Collect date and time + const dateTime = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Step 2: Enter date and time', + requestedSchema: { + type: 'object', + properties: { + date: { + type: 'string', + title: 'Date', + description: 'Event date', + format: 'date' + }, + startTime: { + type: 'string', + title: 'Start Time', + description: 'Event start time (HH:MM)' + }, + duration: { + type: 'integer', + title: 'Duration', + description: 'Duration in minutes', + minimum: 15, + maximum: 480 + } + }, + required: ['date', 'startTime', 'duration'] + } + }); + if (dateTime.action !== 'accept' || !dateTime.content) { + return { + content: [{ type: 'text', text: 'Event creation cancelled.' }] + }; + } + // Combine all collected information + const event = { + ...basicInfo.content, + ...dateTime.content + }; + return { + content: [ + { + type: 'text', + text: `Event created successfully!\n\n${JSON.stringify(event, null, 2)}` + } + ] + }; + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Event creation failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +/** + * Example 3: Collecting address information + * Demonstrates validation with patterns and optional fields + */ +mcpServer.registerTool('update_shipping_address', { + description: 'Update shipping address with validation', + inputSchema: {} +}, async () => { + try { + const result = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Please provide your shipping address:', + requestedSchema: { + type: 'object', + properties: { + name: { + type: 'string', + title: 'Full Name', + description: 'Recipient name', + minLength: 1 + }, + street: { + type: 'string', + title: 'Street Address', + minLength: 1 + }, + city: { + type: 'string', + title: 'City', + minLength: 1 + }, + state: { + type: 'string', + title: 'State/Province', + minLength: 2, + maxLength: 2 + }, + zipCode: { + type: 'string', + title: 'ZIP/Postal Code', + description: '5-digit ZIP code' + }, + phone: { + type: 'string', + title: 'Phone Number (optional)', + description: 'Contact phone number' + } + }, + required: ['name', 'street', 'city', 'state', 'zipCode'] + } + }); + if (result.action === 'accept' && result.content) { + return { + content: [ + { + type: 'text', + text: `Address updated successfully!\n\n${JSON.stringify(result.content, null, 2)}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [{ type: 'text', text: 'Address update cancelled by user.' }] + }; + } + else { + return { + content: [{ type: 'text', text: 'Address update was cancelled.' }] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Address update failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +async function main() { + const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000; + const app = (0, express_1.default)(); + app.use(express_1.default.json()); + // Allow CORS for all domains, expose the Mcp-Session-Id header + app.use((0, cors_1.default)({ + origin: '*', + exposedHeaders: ['Mcp-Session-Id'] + })); + // Map to store transports by session ID + const transports = {}; + // MCP POST endpoint + const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (sessionId) { + console.log(`Received MCP request for session: ${sessionId}`); + } + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport for this session + transport = transports[sessionId]; + } + else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) { + // New initialization request - create new transport + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + await mcpServer.connect(transport); + await transport.handleRequest(req, res, req.body); + return; + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } + }; + app.post('/mcp', mcpPostHandler); + // Handle GET requests for SSE streams + const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Establishing SSE stream for session ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + }; + app.get('/mcp', mcpGetHandler); + // Handle DELETE requests for session termination + const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } + }; + app.delete('/mcp', mcpDeleteHandler); + // Start listening + app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Form elicitation example server is running on http://localhost:${PORT}/mcp`); + console.log('Available tools:'); + console.log(' - register_user: Collect user registration information'); + console.log(' - create_event: Multi-step event creation'); + console.log(' - update_shipping_address: Collect and validate address'); + console.log('\nConnect your MCP client to this server using the HTTP transport.'); + }); + // Handle server shutdown + process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); + }); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=elicitationFormExample.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationFormExample.js.map b/dist/cjs/examples/server/elicitationFormExample.js.map new file mode 100644 index 000000000..fc5ebcd47 --- /dev/null +++ b/dist/cjs/examples/server/elicitationFormExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationFormExample.js","sourceRoot":"","sources":["../../../../src/examples/server/elicitationFormExample.ts"],"names":[],"mappings":";AAAA,kEAAkE;AAClE,EAAE;AACF,yFAAyF;AACzF,0EAA0E;AAC1E,2FAA2F;AAC3F,gCAAgC;AAChC,kFAAkF;AAClF,mDAAmD;;;;;AAEnD,6CAAyC;AACzC,gDAAwB;AACxB,sDAA+D;AAC/D,gDAAgD;AAChD,sEAA+E;AAC/E,6CAAqD;AAErD,8FAA8F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GAAG,CAAC,2DAA2D,CAAC,CAAC;QACzE,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IAEH,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAEvC,6DAA6D;QAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,IAAI,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;gBAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;gBACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9E,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationUrlExample.d.ts b/dist/cjs/examples/server/elicitationUrlExample.d.ts new file mode 100644 index 000000000..611f6eba2 --- /dev/null +++ b/dist/cjs/examples/server/elicitationUrlExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationUrlExample.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationUrlExample.d.ts.map b/dist/cjs/examples/server/elicitationUrlExample.d.ts.map new file mode 100644 index 000000000..04acd6664 --- /dev/null +++ b/dist/cjs/examples/server/elicitationUrlExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/elicitationUrlExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationUrlExample.js b/dist/cjs/examples/server/elicitationUrlExample.js new file mode 100644 index 000000000..0282070a0 --- /dev/null +++ b/dist/cjs/examples/server/elicitationUrlExample.js @@ -0,0 +1,656 @@ +"use strict"; +// Run with: npx tsx src/examples/server/elicitationUrlExample.ts +// +// This example demonstrates how to use URL elicitation to securely collect +// *sensitive* user input in a remote (HTTP) server. +// URL elicitation allows servers to prompt the end-user to open a URL in their browser +// to collect sensitive information. +// Note: See also elicitationFormExample.ts for an example of using form (not URL) elicitation +// to collect *non-sensitive* user input with a structured schema. +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const zod_1 = require("zod"); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const router_js_1 = require("../../server/auth/router.js"); +const bearerAuth_js_1 = require("../../server/auth/middleware/bearerAuth.js"); +const types_js_1 = require("../../types.js"); +const inMemoryEventStore_js_1 = require("../shared/inMemoryEventStore.js"); +const demoInMemoryOAuthProvider_js_1 = require("./demoInMemoryOAuthProvider.js"); +const auth_utils_js_1 = require("../../shared/auth-utils.js"); +const cors_1 = __importDefault(require("cors")); +// Create an MCP server with implementation details +const getServer = () => { + const mcpServer = new mcp_js_1.McpServer({ + name: 'url-elicitation-http-server', + version: '1.0.0' + }, { + capabilities: { logging: {} } + }); + mcpServer.registerTool('payment-confirm', { + description: 'A tool that confirms a payment directly with a user', + inputSchema: { + cartId: zod_1.z.string().describe('The ID of the cart to confirm') + } + }, async ({ cartId }, extra) => { + /* + In a real world scenario, there would be some logic here to check if the user has the provided cartId. + For the purposes of this example, we'll throw an error (-> elicits the client to open a URL to confirm payment) + */ + const sessionId = extra.sessionId; + if (!sessionId) { + throw new Error('Expected a Session ID'); + } + // Create and track the elicitation + const elicitationId = generateTrackedElicitation(sessionId, elicitationId => mcpServer.server.createElicitationCompletionNotifier(elicitationId)); + throw new types_js_1.UrlElicitationRequiredError([ + { + mode: 'url', + message: 'This tool requires a payment confirmation. Open the link to confirm payment!', + url: `http://localhost:${MCP_PORT}/confirm-payment?session=${sessionId}&elicitation=${elicitationId}&cartId=${encodeURIComponent(cartId)}`, + elicitationId + } + ]); + }); + mcpServer.registerTool('third-party-auth', { + description: 'A demo tool that requires third-party OAuth credentials', + inputSchema: { + param1: zod_1.z.string().describe('First parameter') + } + }, async (_, extra) => { + /* + In a real world scenario, there would be some logic here to check if we already have a valid access token for the user. + Auth info (with a subject or `sub` claim) can be typically be found in `extra.authInfo`. + If we do, we can just return the result of the tool call. + If we don't, we can throw an ElicitationRequiredError to request the user to authenticate. + For the purposes of this example, we'll throw an error (-> elicits the client to open a URL to authenticate). + */ + const sessionId = extra.sessionId; + if (!sessionId) { + throw new Error('Expected a Session ID'); + } + // Create and track the elicitation + const elicitationId = generateTrackedElicitation(sessionId, elicitationId => mcpServer.server.createElicitationCompletionNotifier(elicitationId)); + // Simulate OAuth callback and token exchange after 5 seconds + // In a real app, this would be called from your OAuth callback handler + setTimeout(() => { + console.log(`Simulating OAuth token received for elicitation ${elicitationId}`); + completeURLElicitation(elicitationId); + }, 5000); + throw new types_js_1.UrlElicitationRequiredError([ + { + mode: 'url', + message: 'This tool requires access to your example.com account. Open the link to authenticate!', + url: 'https://www.example.com/oauth/authorize', + elicitationId + } + ]); + }); + return mcpServer; +}; +const elicitationsMap = new Map(); +// Clean up old elicitations after 1 hour to prevent memory leaks +const ELICITATION_TTL_MS = 60 * 60 * 1000; // 1 hour +const CLEANUP_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes +function cleanupOldElicitations() { + const now = new Date(); + for (const [id, metadata] of elicitationsMap.entries()) { + if (now.getTime() - metadata.createdAt.getTime() > ELICITATION_TTL_MS) { + elicitationsMap.delete(id); + console.log(`Cleaned up expired elicitation: ${id}`); + } + } +} +setInterval(cleanupOldElicitations, CLEANUP_INTERVAL_MS); +/** + * Elicitation IDs must be unique strings within the MCP session + * UUIDs are used in this example for simplicity + */ +function generateElicitationId() { + return (0, node_crypto_1.randomUUID)(); +} +/** + * Helper function to create and track a new elicitation. + */ +function generateTrackedElicitation(sessionId, createCompletionNotifier) { + const elicitationId = generateElicitationId(); + // Create a Promise and its resolver for tracking completion + let completeResolver; + const completedPromise = new Promise(resolve => { + completeResolver = resolve; + }); + const completionNotifier = createCompletionNotifier ? createCompletionNotifier(elicitationId) : undefined; + // Store the elicitation in our map + elicitationsMap.set(elicitationId, { + status: 'pending', + completedPromise, + completeResolver: completeResolver, + createdAt: new Date(), + sessionId, + completionNotifier + }); + return elicitationId; +} +/** + * Helper function to complete an elicitation. + */ +function completeURLElicitation(elicitationId) { + const elicitation = elicitationsMap.get(elicitationId); + if (!elicitation) { + console.warn(`Attempted to complete unknown elicitation: ${elicitationId}`); + return; + } + if (elicitation.status === 'complete') { + console.warn(`Elicitation already complete: ${elicitationId}`); + return; + } + // Update metadata + elicitation.status = 'complete'; + // Send completion notification to the client + if (elicitation.completionNotifier) { + console.log(`Sending notifications/elicitation/complete notification for elicitation ${elicitationId}`); + elicitation.completionNotifier().catch(error => { + console.error(`Failed to send completion notification for elicitation ${elicitationId}:`, error); + }); + } + // Resolve the promise to unblock any waiting code + elicitation.completeResolver(); +} +const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000; +const AUTH_PORT = process.env.MCP_AUTH_PORT ? parseInt(process.env.MCP_AUTH_PORT, 10) : 3001; +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Allow CORS all domains, expose the Mcp-Session-Id header +app.use((0, cors_1.default)({ + origin: '*', // Allow all origins + exposedHeaders: ['Mcp-Session-Id'], + credentials: true // Allow cookies to be sent cross-origin +})); +// Set up OAuth (required for this example) +let authMiddleware = null; +// Create auth middleware for MCP endpoints +const mcpServerUrl = new URL(`http://localhost:${MCP_PORT}/mcp`); +const authServerUrl = new URL(`http://localhost:${AUTH_PORT}`); +const oauthMetadata = (0, demoInMemoryOAuthProvider_js_1.setupAuthServer)({ authServerUrl, mcpServerUrl, strictResource: true }); +const tokenVerifier = { + verifyAccessToken: async (token) => { + const endpoint = oauthMetadata.introspection_endpoint; + if (!endpoint) { + throw new Error('No token verification endpoint available in metadata'); + } + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + token: token + }).toString() + }); + if (!response.ok) { + const text = await response.text().catch(() => null); + throw new Error(`Invalid or expired token: ${text}`); + } + const data = await response.json(); + if (!data.aud) { + throw new Error(`Resource Indicator (RFC8707) missing`); + } + if (!(0, auth_utils_js_1.checkResourceAllowed)({ requestedResource: data.aud, configuredResource: mcpServerUrl })) { + throw new Error(`Expected resource indicator ${mcpServerUrl}, got: ${data.aud}`); + } + // Convert the response to AuthInfo format + return { + token, + clientId: data.client_id, + scopes: data.scope ? data.scope.split(' ') : [], + expiresAt: data.exp + }; + } +}; +// Add metadata routes to the main MCP server +app.use((0, router_js_1.mcpAuthMetadataRouter)({ + oauthMetadata, + resourceServerUrl: mcpServerUrl, + scopesSupported: ['mcp:tools'], + resourceName: 'MCP Demo Server' +})); +authMiddleware = (0, bearerAuth_js_1.requireBearerAuth)({ + verifier: tokenVerifier, + requiredScopes: [], + resourceMetadataUrl: (0, router_js_1.getOAuthProtectedResourceMetadataUrl)(mcpServerUrl) +}); +/** + * API Key Form Handling + * + * Many servers today require an API key to operate, but there's no scalable way to do this dynamically for remote servers within MCP protocol. + * URL-mode elicitation enables the server to host a simple form and get the secret data securely from the user without involving the LLM or client. + **/ +async function sendApiKeyElicitation(sessionId, sender, createCompletionNotifier) { + if (!sessionId) { + console.error('No session ID provided'); + throw new Error('Expected a Session ID to track elicitation'); + } + console.log('🔑 URL elicitation demo: Requesting API key from client...'); + const elicitationId = generateTrackedElicitation(sessionId, createCompletionNotifier); + try { + const result = await sender({ + mode: 'url', + message: 'Please provide your API key to authenticate with this server', + // Host the form on the same server. In a real app, you might coordinate passing these state variables differently. + url: `http://localhost:${MCP_PORT}/api-key-form?session=${sessionId}&elicitation=${elicitationId}`, + elicitationId + }); + switch (result.action) { + case 'accept': + console.log('🔑 URL elicitation demo: Client accepted the API key elicitation (now pending form submission)'); + // Wait for the API key to be submitted via the form + // The form submission will complete the elicitation + break; + default: + console.log('🔑 URL elicitation demo: Client declined to provide an API key'); + // In a real app, this might close the connection, but for the demo, we'll continue + break; + } + } + catch (error) { + console.error('Error during API key elicitation:', error); + } +} +// API Key Form endpoint - serves a simple HTML form +app.get('/api-key-form', (req, res) => { + const mcpSessionId = req.query.session; + const elicitationId = req.query.elicitation; + if (!mcpSessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie + // In production, this is often handled by some user auth middleware to ensure the user has a valid session + // This session is different from the MCP session. + // This userSession is the cookie that the MCP Server's Authorization Server sets for the user when they log in. + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // Serve a simple HTML form + res.send(` + + + + Submit Your API Key + + + +

API Key Required

+
✓ Logged in as: ${userSession.name}
+
+ + + + +
+
This is a demo showing how a server can securely elicit sensitive data from a user using a URL.
+ + + `); +}); +// Handle API key form submission +app.post('/api-key-form', express_1.default.urlencoded(), (req, res) => { + const { session: sessionId, apiKey, elicitation: elicitationId } = req.body; + if (!sessionId || !apiKey || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie here too + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // A real app might store this API key to be used later for the user. + console.log(`🔑 Received API key \x1b[32m${apiKey}\x1b[0m for session ${sessionId}`); + // If we have an elicitationId, complete the elicitation + completeURLElicitation(elicitationId); + // Send a success response + res.send(` + + + + Success + + + +
+

Success ✓

+

API key received.

+
+

You can close this window and return to your MCP client.

+ + + `); +}); +// Helper to get the user session from the demo_session cookie +function getUserSessionCookie(cookieHeader) { + if (!cookieHeader) + return null; + const cookies = cookieHeader.split(';'); + for (const cookie of cookies) { + const [name, value] = cookie.trim().split('='); + if (name === 'demo_session' && value) { + try { + return JSON.parse(decodeURIComponent(value)); + } + catch (error) { + console.error('Failed to parse demo_session cookie:', error); + return null; + } + } + } + return null; +} +/** + * Payment Confirmation Form Handling + * + * This demonstrates how a server can use URL-mode elicitation to get user confirmation + * for sensitive operations like payment processing. + **/ +// Payment Confirmation Form endpoint - serves a simple HTML form +app.get('/confirm-payment', (req, res) => { + const mcpSessionId = req.query.session; + const elicitationId = req.query.elicitation; + const cartId = req.query.cartId; + if (!mcpSessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie + // In production, this is often handled by some user auth middleware to ensure the user has a valid session + // This session is different from the MCP session. + // This userSession is the cookie that the MCP Server's Authorization Server sets for the user when they log in. + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // Serve a simple HTML form + res.send(` + + + + Confirm Payment + + + +

Confirm Payment

+
✓ Logged in as: ${userSession.name}
+ ${cartId ? `
Cart ID: ${cartId}
` : ''} +
+ ⚠️ Please review your order before confirming. +
+
+ + + ${cartId ? `` : ''} + + +
+
This is a demo showing how a server can securely get user confirmation for sensitive operations using URL-mode elicitation.
+ + + `); +}); +// Handle Payment Confirmation form submission +app.post('/confirm-payment', express_1.default.urlencoded(), (req, res) => { + const { session: sessionId, elicitation: elicitationId, cartId, action } = req.body; + if (!sessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie here too + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + if (action === 'confirm') { + // A real app would process the payment here + console.log(`💳 Payment confirmed for cart ${cartId || 'unknown'} by user ${userSession.name} (session ${sessionId})`); + // Complete the elicitation + completeURLElicitation(elicitationId); + // Send a success response + res.send(` + + + + Payment Confirmed + + + +
+

Payment Confirmed ✓

+

Your payment has been successfully processed.

+ ${cartId ? `

Cart ID: ${cartId}

` : ''} +
+

You can close this window and return to your MCP client.

+ + + `); + } + else if (action === 'cancel') { + console.log(`💳 Payment cancelled for cart ${cartId || 'unknown'} by user ${userSession.name} (session ${sessionId})`); + // The client will still receive a notifications/elicitation/complete notification, + // which indicates that the out-of-band interaction is complete (but not necessarily successful) + completeURLElicitation(elicitationId); + res.send(` + + + + Payment Cancelled + + + +
+

Payment Cancelled

+

Your payment has been cancelled.

+
+

You can close this window and return to your MCP client.

+ + + `); + } + else { + res.status(400).send('

Error

Invalid action

'); + } +}); +// Map to store transports by session ID +const transports = {}; +const sessionsNeedingElicitation = {}; +// MCP POST endpoint +const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + console.debug(`Received MCP POST for session: ${sessionId || 'unknown'}`); + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) { + const server = getServer(); + // New initialization request + const eventStore = new inMemoryEventStore_js_1.InMemoryEventStore(); + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + sessionsNeedingElicitation[sessionId] = { + elicitationSender: params => server.server.elicitInput(params), + createCompletionNotifier: elicitationId => server.server.createElicitationCompletionNotifier(elicitationId) + }; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + delete sessionsNeedingElicitation[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + // so responses can flow back through the same transport + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + // The existing transport is already connected to the server + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}; +// Set up routes with auth middleware +app.post('/mcp', authMiddleware, mcpPostHandler); +// Handle GET requests for SSE streams (using built-in support from StreamableHTTP) +const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + // Check for Last-Event-ID header for resumability + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`); + } + else { + console.log(`Establishing new SSE stream for session ${sessionId}`); + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + if (sessionsNeedingElicitation[sessionId]) { + const { elicitationSender, createCompletionNotifier } = sessionsNeedingElicitation[sessionId]; + // Send an elicitation request to the client in the background + sendApiKeyElicitation(sessionId, elicitationSender, createCompletionNotifier) + .then(() => { + // Only delete on successful send for this demo + delete sessionsNeedingElicitation[sessionId]; + console.log(`🔑 URL elicitation demo: Finished sending API key elicitation request for session ${sessionId}`); + }) + .catch(error => { + console.error('Error sending API key elicitation:', error); + // Keep in map to potentially retry on next reconnect + }); + } +}; +// Set up GET route with conditional auth middleware +app.get('/mcp', authMiddleware, mcpGetHandler); +// Handle DELETE requests for session termination (according to MCP spec) +const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } +}; +// Set up DELETE route with auth middleware +app.delete('/mcp', authMiddleware, mcpDeleteHandler); +app.listen(MCP_PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + delete sessionsNeedingElicitation[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=elicitationUrlExample.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/elicitationUrlExample.js.map b/dist/cjs/examples/server/elicitationUrlExample.js.map new file mode 100644 index 000000000..0b2eb4611 --- /dev/null +++ b/dist/cjs/examples/server/elicitationUrlExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.js","sourceRoot":"","sources":["../../../../src/examples/server/elicitationUrlExample.ts"],"names":[],"mappings":";AAAA,iEAAiE;AACjE,EAAE;AACF,2EAA2E;AAC3E,oDAAoD;AACpD,uFAAuF;AACvF,oCAAoC;AACpC,8FAA8F;AAC9F,kEAAkE;;;;;AAElE,sDAAqD;AACrD,6CAAyC;AACzC,6BAAw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AAU,CAAC,SAAS,CAAC,CAAC;YAC7B,OAAO,0BAA0B,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts b/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts new file mode 100644 index 000000000..477fa6bae --- /dev/null +++ b/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=jsonResponseStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts.map b/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts.map new file mode 100644 index 000000000..ee8117ee2 --- /dev/null +++ b/dist/cjs/examples/server/jsonResponseStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"jsonResponseStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/jsonResponseStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/jsonResponseStreamableHttp.js b/dist/cjs/examples/server/jsonResponseStreamableHttp.js new file mode 100644 index 000000000..fa4802f15 --- /dev/null +++ b/dist/cjs/examples/server/jsonResponseStreamableHttp.js @@ -0,0 +1,175 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const z = __importStar(require("zod/v4")); +const types_js_1 = require("../../types.js"); +const cors_1 = __importDefault(require("cors")); +// Create an MCP server with implementation details +const getServer = () => { + const server = new mcp_js_1.McpServer({ + name: 'json-response-streamable-http-server', + version: '1.0.0' + }, { + capabilities: { + logging: {} + } + }); + // Register a simple tool that returns a greeting + server.tool('greet', 'A simple greeting tool', { + name: z.string().describe('Name to greet') + }, async ({ name }) => { + return { + content: [ + { + type: 'text', + text: `Hello, ${name}!` + } + ] + }; + }); + // Register a tool that sends multiple greetings with notifications + server.tool('multi-greet', 'A tool that sends different greetings with delays between them', { + name: z.string().describe('Name to greet') + }, async ({ name }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + await server.sendLoggingMessage({ + level: 'debug', + data: `Starting multi-greet for ${name}` + }, extra.sessionId); + await sleep(1000); // Wait 1 second before first greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending first greeting to ${name}` + }, extra.sessionId); + await sleep(1000); // Wait another second before second greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending second greeting to ${name}` + }, extra.sessionId); + return { + content: [ + { + type: 'text', + text: `Good morning, ${name}!` + } + ] + }; + }); + return server; +}; +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use((0, cors_1.default)({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +// Map to store transports by session ID +const transports = {}; +app.post('/mcp', async (req, res) => { + console.log('Received MCP request:', req.body); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) { + // New initialization request - use JSON response mode + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + enableJsonResponse: true, // Enable JSON response mode + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Connect the transport to the MCP server BEFORE handling the request + const server = getServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams according to spec +app.get('/mcp', async (req, res) => { + // Since this is a very simple example, we don't support GET requests for this server + // The spec requires returning 405 Method Not Allowed in this case + res.status(405).set('Allow', 'POST').send('Method Not Allowed'); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + process.exit(0); +}); +//# sourceMappingURL=jsonResponseStreamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/jsonResponseStreamableHttp.js.map b/dist/cjs/examples/server/jsonResponseStreamableHttp.js.map new file mode 100644 index 000000000..cfe7bc4a3 --- /dev/null +++ b/dist/cjs/examples/server/jsonResponseStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"jsonResponseStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/jsonResponseStreamableHttp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,6CAAyC;AACzC,gDAAgD;AAChD,sEAA+E;AAC/E,0CAA4B;AAC5B,6CAAqE;AACrE,gDAAwB;AAExB,mDAAmD;AACnD,MAAM,SAAS,GAAG,GAAG,EAAE;IACnB,MAAM,MAAM,GAAG,IAAI,kBAAS,CACxB;QACI,IAAI,EAAE,sCAAsC;QAC5C,OAAO,EAAE,OAAO;KACnB,EACD;QACI,YAAY,EAAE;YACV,OAAO,EAAE,EAAE;SACd;KACJ,CACJ,CAAC;IAEF,iDAAiD;IACjD,MAAM,CAAC,IAAI,CACP,OAAO,EACP,wBAAwB,EACxB;QACI,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;KAC7C,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,EAA2B,EAAE;QACxC,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,UAAU,IAAI,GAAG;iBAC1B;aACJ;SACJ,CAAC;IACN,CAAC,CACJ,CAAC;IAEF,mEAAmE;IACnE,MAAM,CAAC,IAAI,CACP,aAAa,EACb,gEAAgE,EAChE;QACI,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,C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AC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,gDAAgD,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/mcpServerOutputSchema.d.ts b/dist/cjs/examples/server/mcpServerOutputSchema.d.ts new file mode 100644 index 000000000..a6cb49747 --- /dev/null +++ b/dist/cjs/examples/server/mcpServerOutputSchema.d.ts @@ -0,0 +1,7 @@ +#!/usr/bin/env node +/** + * Example MCP server using the high-level McpServer API with outputSchema + * This demonstrates how to easily create tools with structured output + */ +export {}; +//# sourceMappingURL=mcpServerOutputSchema.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/mcpServerOutputSchema.d.ts.map b/dist/cjs/examples/server/mcpServerOutputSchema.d.ts.map new file mode 100644 index 000000000..bd3abdcc2 --- /dev/null +++ b/dist/cjs/examples/server/mcpServerOutputSchema.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcpServerOutputSchema.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/mcpServerOutputSchema.ts"],"names":[],"mappings":";AACA;;;GAGG"} \ No newline at end of file diff --git a/dist/cjs/examples/server/mcpServerOutputSchema.js b/dist/cjs/examples/server/mcpServerOutputSchema.js new file mode 100644 index 000000000..4ac7e5cda --- /dev/null +++ b/dist/cjs/examples/server/mcpServerOutputSchema.js @@ -0,0 +1,95 @@ +#!/usr/bin/env node +"use strict"; +/** + * Example MCP server using the high-level McpServer API with outputSchema + * This demonstrates how to easily create tools with structured output + */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mcp_js_1 = require("../../server/mcp.js"); +const stdio_js_1 = require("../../server/stdio.js"); +const z = __importStar(require("zod/v4")); +const server = new mcp_js_1.McpServer({ + name: 'mcp-output-schema-high-level-example', + version: '1.0.0' +}); +// Define a tool with structured output - Weather data +server.registerTool('get_weather', { + description: 'Get weather information for a city', + inputSchema: { + city: z.string().describe('City name'), + country: z.string().describe('Country code (e.g., US, UK)') + }, + outputSchema: { + temperature: z.object({ + celsius: z.number(), + fahrenheit: z.number() + }), + conditions: z.enum(['sunny', 'cloudy', 'rainy', 'stormy', 'snowy']), + humidity: z.number().min(0).max(100), + wind: z.object({ + speed_kmh: z.number(), + direction: z.string() + }) + } +}, async ({ city, country }) => { + // Parameters are available but not used in this example + void city; + void country; + // Simulate weather API call + const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10; + const conditions = ['sunny', 'cloudy', 'rainy', 'stormy', 'snowy'][Math.floor(Math.random() * 5)]; + const structuredContent = { + temperature: { + celsius: temp_c, + fahrenheit: Math.round(((temp_c * 9) / 5 + 32) * 10) / 10 + }, + conditions, + humidity: Math.round(Math.random() * 100), + wind: { + speed_kmh: Math.round(Math.random() * 50), + direction: ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'][Math.floor(Math.random() * 8)] + } + }; + return { + content: [ + { + type: 'text', + text: JSON.stringify(structuredContent, null, 2) + } + ], + structuredContent + }; +}); +async function main() { + const transport = new stdio_js_1.StdioServerTransport(); + await server.connect(transport); + console.error('High-level Output Schema Example Server running on stdio'); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=mcpServerOutputSchema.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/mcpServerOutputSchema.js.map b/dist/cjs/examples/server/mcpServerOutputSchema.js.map new file mode 100644 index 000000000..ba0f8b24c --- /dev/null +++ b/dist/cjs/examples/server/mcpServerOutputSchema.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcpServerOutputSchema.js","sourceRoot":"","sources":["../../../../src/examples/server/mcpServerOutputSchema.ts"],"names":[],"mappings":";;AACA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAgD;AAChD,oDAA6D;AAC7D,0CAA4B;AAE5B,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;IACzB,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,sDAAsD;AACtD,MAAM,CAAC,YAAY,CACf,aAAa,EACb;IACI,WAAW,EAAE,oCAAoC;IACjD,WAAW,EAAE;QACT,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC;QACtC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KAC9D;IACD,YAAY,EAAE;QACV,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;YACnB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;SACzB,CAAC;QACF,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,E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AE,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;SACzF;KACJ,CAAC;IAEF,OAAO;QACH,OAAO,EAAE;YACL;gBACI,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;aACnD;SACJ;QACD,iBAAiB;KACpB,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleSseServer.d.ts b/dist/cjs/examples/server/simpleSseServer.d.ts new file mode 100644 index 000000000..4269b7814 --- /dev/null +++ b/dist/cjs/examples/server/simpleSseServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleSseServer.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleSseServer.d.ts.map b/dist/cjs/examples/server/simpleSseServer.d.ts.map new file mode 100644 index 000000000..08a1b4502 --- /dev/null +++ b/dist/cjs/examples/server/simpleSseServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleSseServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleSseServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleSseServer.js b/dist/cjs/examples/server/simpleSseServer.js new file mode 100644 index 000000000..8b1afd86b --- /dev/null +++ b/dist/cjs/examples/server/simpleSseServer.js @@ -0,0 +1,169 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const mcp_js_1 = require("../../server/mcp.js"); +const sse_js_1 = require("../../server/sse.js"); +const z = __importStar(require("zod/v4")); +/** + * This example server demonstrates the deprecated HTTP+SSE transport + * (protocol version 2024-11-05). It mainly used for testing backward compatible clients. + * + * The server exposes two endpoints: + * - /mcp: For establishing the SSE stream (GET) + * - /messages: For receiving client messages (POST) + * + */ +// Create an MCP server instance +const getServer = () => { + const server = new mcp_js_1.McpServer({ + name: 'simple-sse-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + server.tool('start-notification-stream', 'Starts sending periodic notifications', { + interval: z.number().describe('Interval in milliseconds between notifications').default(1000), + count: z.number().describe('Number of notifications to send').default(10) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + // Send the initial notification + await server.sendLoggingMessage({ + level: 'info', + data: `Starting notification stream with ${count} messages every ${interval}ms` + }, extra.sessionId); + // Send periodic notifications + while (counter < count) { + counter++; + await sleep(interval); + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + } + return { + content: [ + { + type: 'text', + text: `Completed sending ${count} notifications every ${interval}ms` + } + ] + }; + }); + return server; +}; +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Store transports by session ID +const transports = {}; +// SSE endpoint for establishing the stream +app.get('/mcp', async (req, res) => { + console.log('Received GET request to /sse (establishing SSE stream)'); + try { + // Create a new SSE transport for the client + // The endpoint for POST messages is '/messages' + const transport = new sse_js_1.SSEServerTransport('/messages', res); + // Store the transport by session ID + const sessionId = transport.sessionId; + transports[sessionId] = transport; + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + console.log(`SSE transport closed for session ${sessionId}`); + delete transports[sessionId]; + }; + // Connect the transport to the MCP server + const server = getServer(); + await server.connect(transport); + console.log(`Established SSE stream with session ID: ${sessionId}`); + } + catch (error) { + console.error('Error establishing SSE stream:', error); + if (!res.headersSent) { + res.status(500).send('Error establishing SSE stream'); + } + } +}); +// Messages endpoint for receiving client JSON-RPC requests +app.post('/messages', async (req, res) => { + console.log('Received POST request to /messages'); + // Extract session ID from URL query parameter + // In the SSE protocol, this is added by the client based on the endpoint event + const sessionId = req.query.sessionId; + if (!sessionId) { + console.error('No session ID provided in request URL'); + res.status(400).send('Missing sessionId parameter'); + return; + } + const transport = transports[sessionId]; + if (!transport) { + console.error(`No active transport found for session ID: ${sessionId}`); + res.status(404).send('Session not found'); + return; + } + try { + // Handle the POST message with the transport + await transport.handlePostMessage(req, res, req.body); + } + catch (error) { + console.error('Error handling request:', error); + if (!res.headersSent) { + res.status(500).send('Error handling request'); + } + } +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Simple SSE Server (deprecated protocol version 2024-11-05) listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleSseServer.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleSseServer.js.map b/dist/cjs/examples/server/simpleSseServer.js.map new file mode 100644 index 000000000..6bb0444a2 --- /dev/null +++ b/dist/cjs/examples/server/simpleSseServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleSseServer.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleSseServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,gDAAgD;AAChD,gDAAyD;AACzD,0CAA4B;AAG5B;;;;;;;;GAQG;AAEH,gCAAgC;AAChC,MAAM,SAAS,GAAG,GAAG,EAAE;IACnB,MAAM,MAAM,GAAG,IAAI,kBAAS,CACxB;QACI,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,OAAO;KACnB,EACD,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CACpC,CAAC;IAEF,MAAM,CAAC,IAAI,CACP,2BAA2B,EAC3B,uCAAuC,EACvC;QACI,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAC7F,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;KAC5E,EACD,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,E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AAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts b/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts new file mode 100644 index 000000000..0aa4ad243 --- /dev/null +++ b/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStatelessStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts.map b/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts.map new file mode 100644 index 000000000..92deb06ec --- /dev/null +++ b/dist/cjs/examples/server/simpleStatelessStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStatelessStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleStatelessStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStatelessStreamableHttp.js b/dist/cjs/examples/server/simpleStatelessStreamableHttp.js new file mode 100644 index 000000000..b82ab00f8 --- /dev/null +++ b/dist/cjs/examples/server/simpleStatelessStreamableHttp.js @@ -0,0 +1,170 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const z = __importStar(require("zod/v4")); +const cors_1 = __importDefault(require("cors")); +const getServer = () => { + // Create an MCP server with implementation details + const server = new mcp_js_1.McpServer({ + name: 'stateless-streamable-http-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + // Register a simple prompt + server.prompt('greeting-template', 'A simple greeting prompt template', { + name: z.string().describe('Name to include in greeting') + }, async ({ name }) => { + return { + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please greet ${name} in a friendly manner.` + } + } + ] + }; + }); + // Register a tool specifically for testing resumability + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(10) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + // Create a simple resource at a fixed URI + server.resource('greeting-resource', 'https://example.com/greetings/default', { mimeType: 'text/plain' }, async () => { + return { + contents: [ + { + uri: 'https://example.com/greetings/default', + text: 'Hello, world!' + } + ] + }; + }); + return server; +}; +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use((0, cors_1.default)({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +app.post('/mcp', async (req, res) => { + const server = getServer(); + try { + const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: undefined + }); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + res.on('close', () => { + console.log('Request closed'); + transport.close(); + server.close(); + }); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +app.get('/mcp', async (req, res) => { + console.log('Received GET MCP request'); + res.writeHead(405).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); +}); +app.delete('/mcp', async (req, res) => { + console.log('Received DELETE MCP request'); + res.writeHead(405).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Stateless Streamable HTTP Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + process.exit(0); +}); +//# sourceMappingURL=simpleStatelessStreamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStatelessStreamableHttp.js.map b/dist/cjs/examples/server/simpleStatelessStreamableHttp.js.map new file mode 100644 index 000000000..abc90f024 --- /dev/null +++ b/dist/cjs/examples/server/simpleStatelessStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStatelessStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleStatelessStreamableHttp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,gDAAgD;AAChD,sEAA+E;AAC/E,0CAA4B;AAE5B,gDAAwB;AAExB,MAAM,SAAS,GAAG,GAAG,EAAE;IACnB,mDAAmD;IACnD,MAAM,MAAM,GAAG,IAAI,kBAAS,CACxB;QACI,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,OAAO;KACnB,EACD,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CACpC,CAAC;IAEF,2BAA2B;IAC3B,MAAM,CAAC,MAAM,CACT,mBAAmB,EACnB,mCAAmC,EACnC;QACI,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KAC3D,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,EAA4B,EAAE;QACzC,OAAO;YACH,QAAQ,EAAE;gBACN;oBACI,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACL,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,gBAAgB,IAAI,wBAAwB;qBACrD;iBACJ;aACJ;SACJ,CAAC;IACN,CAAC,CACJ,CAAC;IAEF,wDAAwD;IACxD,MAAM,CAAC,IAAI,CACP,2BAA2B,EAC3B,gEAAgE,EACh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AC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0DAA0D,IAAI,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStreamableHttp.d.ts b/dist/cjs/examples/server/simpleStreamableHttp.d.ts new file mode 100644 index 000000000..a20be42ca --- /dev/null +++ b/dist/cjs/examples/server/simpleStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStreamableHttp.d.ts.map b/dist/cjs/examples/server/simpleStreamableHttp.d.ts.map new file mode 100644 index 000000000..e3cf04224 --- /dev/null +++ b/dist/cjs/examples/server/simpleStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStreamableHttp.js b/dist/cjs/examples/server/simpleStreamableHttp.js new file mode 100644 index 000000000..d35dc236a --- /dev/null +++ b/dist/cjs/examples/server/simpleStreamableHttp.js @@ -0,0 +1,661 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const z = __importStar(require("zod/v4")); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const router_js_1 = require("../../server/auth/router.js"); +const bearerAuth_js_1 = require("../../server/auth/middleware/bearerAuth.js"); +const types_js_1 = require("../../types.js"); +const inMemoryEventStore_js_1 = require("../shared/inMemoryEventStore.js"); +const in_memory_js_1 = require("../../experimental/tasks/stores/in-memory.js"); +const demoInMemoryOAuthProvider_js_1 = require("./demoInMemoryOAuthProvider.js"); +const auth_utils_js_1 = require("../../shared/auth-utils.js"); +const cors_1 = __importDefault(require("cors")); +// Check for OAuth flag +const useOAuth = process.argv.includes('--oauth'); +const strictOAuth = process.argv.includes('--oauth-strict'); +// Create shared task store for demonstration +const taskStore = new in_memory_js_1.InMemoryTaskStore(); +// Create an MCP server with implementation details +const getServer = () => { + const server = new mcp_js_1.McpServer({ + name: 'simple-streamable-http-server', + version: '1.0.0', + icons: [{ src: './mcp.svg', sizes: ['512x512'], mimeType: 'image/svg+xml' }], + websiteUrl: 'https://github.com/modelcontextprotocol/typescript-sdk' + }, { + capabilities: { logging: {}, tasks: { requests: { tools: { call: {} } } } }, + taskStore, // Enable task support + taskMessageQueue: new in_memory_js_1.InMemoryTaskMessageQueue() + }); + // Register a simple tool that returns a greeting + server.registerTool('greet', { + title: 'Greeting Tool', // Display name for UI + description: 'A simple greeting tool', + inputSchema: { + name: z.string().describe('Name to greet') + } + }, async ({ name }) => { + return { + content: [ + { + type: 'text', + text: `Hello, ${name}!` + } + ] + }; + }); + // Register a tool that sends multiple greetings with notifications (with annotations) + server.tool('multi-greet', 'A tool that sends different greetings with delays between them', { + name: z.string().describe('Name to greet') + }, { + title: 'Multiple Greeting Tool', + readOnlyHint: true, + openWorldHint: false + }, async ({ name }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + await server.sendLoggingMessage({ + level: 'debug', + data: `Starting multi-greet for ${name}` + }, extra.sessionId); + await sleep(1000); // Wait 1 second before first greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending first greeting to ${name}` + }, extra.sessionId); + await sleep(1000); // Wait another second before second greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending second greeting to ${name}` + }, extra.sessionId); + return { + content: [ + { + type: 'text', + text: `Good morning, ${name}!` + } + ] + }; + }); + // Register a tool that demonstrates form elicitation (user input collection with a schema) + // This creates a closure that captures the server instance + server.tool('collect-user-info', 'A tool that collects user information through form elicitation', { + infoType: z.enum(['contact', 'preferences', 'feedback']).describe('Type of information to collect') + }, async ({ infoType }, extra) => { + let message; + let requestedSchema; + switch (infoType) { + case 'contact': + message = 'Please provide your contact information'; + requestedSchema = { + type: 'object', + properties: { + name: { + type: 'string', + title: 'Full Name', + description: 'Your full name' + }, + email: { + type: 'string', + title: 'Email Address', + description: 'Your email address', + format: 'email' + }, + phone: { + type: 'string', + title: 'Phone Number', + description: 'Your phone number (optional)' + } + }, + required: ['name', 'email'] + }; + break; + case 'preferences': + message = 'Please set your preferences'; + requestedSchema = { + type: 'object', + properties: { + theme: { + type: 'string', + title: 'Theme', + description: 'Choose your preferred theme', + enum: ['light', 'dark', 'auto'], + enumNames: ['Light', 'Dark', 'Auto'] + }, + notifications: { + type: 'boolean', + title: 'Enable Notifications', + description: 'Would you like to receive notifications?', + default: true + }, + frequency: { + type: 'string', + title: 'Notification Frequency', + description: 'How often would you like notifications?', + enum: ['daily', 'weekly', 'monthly'], + enumNames: ['Daily', 'Weekly', 'Monthly'] + } + }, + required: ['theme'] + }; + break; + case 'feedback': + message = 'Please provide your feedback'; + requestedSchema = { + type: 'object', + properties: { + rating: { + type: 'integer', + title: 'Rating', + description: 'Rate your experience (1-5)', + minimum: 1, + maximum: 5 + }, + comments: { + type: 'string', + title: 'Comments', + description: 'Additional comments (optional)', + maxLength: 500 + }, + recommend: { + type: 'boolean', + title: 'Would you recommend this?', + description: 'Would you recommend this to others?' + } + }, + required: ['rating', 'recommend'] + }; + break; + default: + throw new Error(`Unknown info type: ${infoType}`); + } + try { + // Use sendRequest through the extra parameter to elicit input + const result = await extra.sendRequest({ + method: 'elicitation/create', + params: { + mode: 'form', + message, + requestedSchema + } + }, types_js_1.ElicitResultSchema); + if (result.action === 'accept') { + return { + content: [ + { + type: 'text', + text: `Thank you! Collected ${infoType} information: ${JSON.stringify(result.content, null, 2)}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [ + { + type: 'text', + text: `No information was collected. User declined ${infoType} information request.` + } + ] + }; + } + else { + return { + content: [ + { + type: 'text', + text: `Information collection was cancelled by the user.` + } + ] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Error collecting ${infoType} information: ${error}` + } + ] + }; + } + }); + // Register a simple prompt with title + server.registerPrompt('greeting-template', { + title: 'Greeting Template', // Display name for UI + description: 'A simple greeting prompt template', + argsSchema: { + name: z.string().describe('Name to include in greeting') + } + }, async ({ name }) => { + return { + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please greet ${name} in a friendly manner.` + } + } + ] + }; + }); + // Register a tool specifically for testing resumability + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(50) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + // Create a simple resource at a fixed URI + server.registerResource('greeting-resource', 'https://example.com/greetings/default', { + title: 'Default Greeting', // Display name for UI + description: 'A simple greeting resource', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'https://example.com/greetings/default', + text: 'Hello, world!' + } + ] + }; + }); + // Create additional resources for ResourceLink demonstration + server.registerResource('example-file-1', 'file:///example/file1.txt', { + title: 'Example File 1', + description: 'First example file for ResourceLink demonstration', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'file:///example/file1.txt', + text: 'This is the content of file 1' + } + ] + }; + }); + server.registerResource('example-file-2', 'file:///example/file2.txt', { + title: 'Example File 2', + description: 'Second example file for ResourceLink demonstration', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'file:///example/file2.txt', + text: 'This is the content of file 2' + } + ] + }; + }); + // Register a tool that returns ResourceLinks + server.registerTool('list-files', { + title: 'List Files with ResourceLinks', + description: 'Returns a list of files as ResourceLinks without embedding their content', + inputSchema: { + includeDescriptions: z.boolean().optional().describe('Whether to include descriptions in the resource links') + } + }, async ({ includeDescriptions = true }) => { + const resourceLinks = [ + { + type: 'resource_link', + uri: 'https://example.com/greetings/default', + name: 'Default Greeting', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'A simple greeting resource' }) + }, + { + type: 'resource_link', + uri: 'file:///example/file1.txt', + name: 'Example File 1', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'First example file for ResourceLink demonstration' }) + }, + { + type: 'resource_link', + uri: 'file:///example/file2.txt', + name: 'Example File 2', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'Second example file for ResourceLink demonstration' }) + } + ]; + return { + content: [ + { + type: 'text', + text: 'Here are the available files as resource links:' + }, + ...resourceLinks, + { + type: 'text', + text: '\nYou can read any of these resources using their URI.' + } + ] + }; + }); + // Register a long-running tool that demonstrates task execution + // Using the experimental tasks API - WARNING: may change without notice + server.experimental.tasks.registerToolTask('delay', { + title: 'Delay', + description: 'A simple tool that delays for a specified duration, useful for testing task execution', + inputSchema: { + duration: z.number().describe('Duration in milliseconds').default(5000) + } + }, { + async createTask({ duration }, { taskStore, taskRequestedTtl }) { + // Create the task + const task = await taskStore.createTask({ + ttl: taskRequestedTtl + }); + // Simulate out-of-band work + (async () => { + await new Promise(resolve => setTimeout(resolve, duration)); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [ + { + type: 'text', + text: `Completed ${duration}ms delay` + } + ] + }); + })(); + // Return CreateTaskResult with the created task + return { + task + }; + }, + async getTask(_args, { taskId, taskStore }) { + return await taskStore.getTask(taskId); + }, + async getTaskResult(_args, { taskId, taskStore }) { + const result = await taskStore.getTaskResult(taskId); + return result; + } + }); + return server; +}; +const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000; +const AUTH_PORT = process.env.MCP_AUTH_PORT ? parseInt(process.env.MCP_AUTH_PORT, 10) : 3001; +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Allow CORS all domains, expose the Mcp-Session-Id header +app.use((0, cors_1.default)({ + origin: '*', // Allow all origins + exposedHeaders: ['Mcp-Session-Id'] +})); +// Set up OAuth if enabled +let authMiddleware = null; +if (useOAuth) { + // Create auth middleware for MCP endpoints + const mcpServerUrl = new URL(`http://localhost:${MCP_PORT}/mcp`); + const authServerUrl = new URL(`http://localhost:${AUTH_PORT}`); + const oauthMetadata = (0, demoInMemoryOAuthProvider_js_1.setupAuthServer)({ authServerUrl, mcpServerUrl, strictResource: strictOAuth }); + const tokenVerifier = { + verifyAccessToken: async (token) => { + const endpoint = oauthMetadata.introspection_endpoint; + if (!endpoint) { + throw new Error('No token verification endpoint available in metadata'); + } + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + token: token + }).toString() + }); + if (!response.ok) { + const text = await response.text().catch(() => null); + throw new Error(`Invalid or expired token: ${text}`); + } + const data = await response.json(); + if (strictOAuth) { + if (!data.aud) { + throw new Error(`Resource Indicator (RFC8707) missing`); + } + if (!(0, auth_utils_js_1.checkResourceAllowed)({ requestedResource: data.aud, configuredResource: mcpServerUrl })) { + throw new Error(`Expected resource indicator ${mcpServerUrl}, got: ${data.aud}`); + } + } + // Convert the response to AuthInfo format + return { + token, + clientId: data.client_id, + scopes: data.scope ? data.scope.split(' ') : [], + expiresAt: data.exp + }; + } + }; + // Add metadata routes to the main MCP server + app.use((0, router_js_1.mcpAuthMetadataRouter)({ + oauthMetadata, + resourceServerUrl: mcpServerUrl, + scopesSupported: ['mcp:tools'], + resourceName: 'MCP Demo Server' + })); + authMiddleware = (0, bearerAuth_js_1.requireBearerAuth)({ + verifier: tokenVerifier, + requiredScopes: [], + resourceMetadataUrl: (0, router_js_1.getOAuthProtectedResourceMetadataUrl)(mcpServerUrl) + }); +} +// Map to store transports by session ID +const transports = {}; +// MCP POST endpoint with optional auth +const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (sessionId) { + console.log(`Received MCP request for session: ${sessionId}`); + } + else { + console.log('Request body:', req.body); + } + if (useOAuth && req.auth) { + console.log('Authenticated user:', req.auth); + } + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) { + // New initialization request + const eventStore = new inMemoryEventStore_js_1.InMemoryEventStore(); + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + // so responses can flow back through the same transport + const server = getServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + // The existing transport is already connected to the server + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}; +// Set up routes with conditional auth middleware +if (useOAuth && authMiddleware) { + app.post('/mcp', authMiddleware, mcpPostHandler); +} +else { + app.post('/mcp', mcpPostHandler); +} +// Handle GET requests for SSE streams (using built-in support from StreamableHTTP) +const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + if (useOAuth && req.auth) { + console.log('Authenticated SSE connection from user:', req.auth); + } + // Check for Last-Event-ID header for resumability + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`); + } + else { + console.log(`Establishing new SSE stream for session ${sessionId}`); + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}; +// Set up GET route with conditional auth middleware +if (useOAuth && authMiddleware) { + app.get('/mcp', authMiddleware, mcpGetHandler); +} +else { + app.get('/mcp', mcpGetHandler); +} +// Handle DELETE requests for session termination (according to MCP spec) +const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } +}; +// Set up DELETE route with conditional auth middleware +if (useOAuth && authMiddleware) { + app.delete('/mcp', authMiddleware, mcpDeleteHandler); +} +else { + app.delete('/mcp', mcpDeleteHandler); +} +app.listen(MCP_PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleStreamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleStreamableHttp.js.map b/dist/cjs/examples/server/simpleStreamableHttp.js.map new file mode 100644 index 000000000..e3c553a25 --- /dev/null +++ b/dist/cjs/examples/server/simpleStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleStreamableHttp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,6CAAyC;AACzC,0CAA4B;AAC5B,gDAAgD;AAChD,sEAA+E;AAC/E,2DAA0G;AAC1G,8EAA+E;AAC/E,6CAQwB;AACxB,2EAAqE;AACrE,+EAA2G;AAC3G,iFAAiE;AAEjE,8DAAkE;AAElE,gDAAwB;AAExB,uBAAuB;AACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CA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QACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,gDAAgD,QAAQ,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleTaskInteractive.d.ts b/dist/cjs/examples/server/simpleTaskInteractive.d.ts new file mode 100644 index 000000000..661c9f010 --- /dev/null +++ b/dist/cjs/examples/server/simpleTaskInteractive.d.ts @@ -0,0 +1,12 @@ +/** + * Simple interactive task server demonstrating elicitation and sampling. + * + * This server demonstrates the task message queue pattern from the MCP Tasks spec: + * - confirm_delete: Uses elicitation to ask the user for confirmation + * - write_haiku: Uses sampling to request an LLM to generate content + * + * Both tools use the "call-now, fetch-later" pattern where the initial call + * creates a task, and the result is fetched via tasks/result endpoint. + */ +export {}; +//# sourceMappingURL=simpleTaskInteractive.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleTaskInteractive.d.ts.map b/dist/cjs/examples/server/simpleTaskInteractive.d.ts.map new file mode 100644 index 000000000..3e48b9e76 --- /dev/null +++ b/dist/cjs/examples/server/simpleTaskInteractive.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractive.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleTaskInteractive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"} \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleTaskInteractive.js b/dist/cjs/examples/server/simpleTaskInteractive.js new file mode 100644 index 000000000..3b72e73d2 --- /dev/null +++ b/dist/cjs/examples/server/simpleTaskInteractive.js @@ -0,0 +1,608 @@ +"use strict"; +/** + * Simple interactive task server demonstrating elicitation and sampling. + * + * This server demonstrates the task message queue pattern from the MCP Tasks spec: + * - confirm_delete: Uses elicitation to ask the user for confirmation + * - write_haiku: Uses sampling to request an LLM to generate content + * + * Both tools use the "call-now, fetch-later" pattern where the initial call + * creates a task, and the result is fetched via tasks/result endpoint. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const index_js_1 = require("../../server/index.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +const interfaces_js_1 = require("../../experimental/tasks/interfaces.js"); +const in_memory_js_1 = require("../../experimental/tasks/stores/in-memory.js"); +// ============================================================================ +// Resolver - Promise-like for passing results between async operations +// ============================================================================ +class Resolver { + constructor() { + this._done = false; + this._promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + }); + } + setResult(value) { + if (this._done) + return; + this._done = true; + this._resolve(value); + } + setException(error) { + if (this._done) + return; + this._done = true; + this._reject(error); + } + wait() { + return this._promise; + } + done() { + return this._done; + } +} +class TaskMessageQueueWithResolvers { + constructor() { + this.queues = new Map(); + this.waitResolvers = new Map(); + } + getQueue(taskId) { + let queue = this.queues.get(taskId); + if (!queue) { + queue = []; + this.queues.set(taskId, queue); + } + return queue; + } + async enqueue(taskId, message, _sessionId, maxSize) { + const queue = this.getQueue(taskId); + if (maxSize !== undefined && queue.length >= maxSize) { + throw new Error(`Task message queue overflow: queue size (${queue.length}) exceeds maximum (${maxSize})`); + } + queue.push(message); + // Notify any waiters + this.notifyWaiters(taskId); + } + async enqueueWithResolver(taskId, message, resolver, originalRequestId) { + const queue = this.getQueue(taskId); + const queuedMessage = { + type: 'request', + message, + timestamp: Date.now(), + resolver, + originalRequestId + }; + queue.push(queuedMessage); + this.notifyWaiters(taskId); + } + async dequeue(taskId, _sessionId) { + const queue = this.getQueue(taskId); + return queue.shift(); + } + async dequeueAll(taskId, _sessionId) { + var _a; + const queue = (_a = this.queues.get(taskId)) !== null && _a !== void 0 ? _a : []; + this.queues.delete(taskId); + return queue; + } + async waitForMessage(taskId) { + // Check if there are already messages + const queue = this.getQueue(taskId); + if (queue.length > 0) + return; + // Wait for a message to be added + return new Promise(resolve => { + let waiters = this.waitResolvers.get(taskId); + if (!waiters) { + waiters = []; + this.waitResolvers.set(taskId, waiters); + } + waiters.push(resolve); + }); + } + notifyWaiters(taskId) { + const waiters = this.waitResolvers.get(taskId); + if (waiters) { + this.waitResolvers.delete(taskId); + for (const resolve of waiters) { + resolve(); + } + } + } + cleanup() { + this.queues.clear(); + this.waitResolvers.clear(); + } +} +// ============================================================================ +// Extended task store with wait functionality +// ============================================================================ +class TaskStoreWithNotifications extends in_memory_js_1.InMemoryTaskStore { + constructor() { + super(...arguments); + this.updateResolvers = new Map(); + } + async updateTaskStatus(taskId, status, statusMessage, sessionId) { + await super.updateTaskStatus(taskId, status, statusMessage, sessionId); + this.notifyUpdate(taskId); + } + async storeTaskResult(taskId, status, result, sessionId) { + await super.storeTaskResult(taskId, status, result, sessionId); + this.notifyUpdate(taskId); + } + async waitForUpdate(taskId) { + return new Promise(resolve => { + let waiters = this.updateResolvers.get(taskId); + if (!waiters) { + waiters = []; + this.updateResolvers.set(taskId, waiters); + } + waiters.push(resolve); + }); + } + notifyUpdate(taskId) { + const waiters = this.updateResolvers.get(taskId); + if (waiters) { + this.updateResolvers.delete(taskId); + for (const resolve of waiters) { + resolve(); + } + } + } +} +// ============================================================================ +// Task Result Handler - delivers queued messages and routes responses +// ============================================================================ +class TaskResultHandler { + constructor(store, queue) { + this.store = store; + this.queue = queue; + this.pendingRequests = new Map(); + } + async handle(taskId, server, _sessionId) { + while (true) { + // Get fresh task state + const task = await this.store.getTask(taskId); + if (!task) { + throw new Error(`Task not found: ${taskId}`); + } + // Dequeue and send all pending messages + await this.deliverQueuedMessages(taskId, server, _sessionId); + // If task is terminal, return result + if ((0, interfaces_js_1.isTerminal)(task.status)) { + const result = await this.store.getTaskResult(taskId); + // Add related-task metadata per spec + return { + ...result, + _meta: { + ...(result._meta || {}), + [types_js_1.RELATED_TASK_META_KEY]: { taskId } + } + }; + } + // Wait for task update or new message + await this.waitForUpdate(taskId); + } + } + async deliverQueuedMessages(taskId, server, _sessionId) { + while (true) { + const message = await this.queue.dequeue(taskId); + if (!message) + break; + console.log(`[Server] Delivering queued ${message.type} message for task ${taskId}`); + if (message.type === 'request') { + const reqMessage = message; + // Send the request via the server + // Store the resolver so we can route the response back + if (reqMessage.resolver && reqMessage.originalRequestId) { + this.pendingRequests.set(reqMessage.originalRequestId, reqMessage.resolver); + } + // Send the message - for elicitation/sampling, we use the server's methods + // But since we're in tasks/result context, we need to send via transport + // This is simplified - in production you'd use proper message routing + try { + const request = reqMessage.message; + let response; + if (request.method === 'elicitation/create') { + // Send elicitation request to client + const params = request.params; + response = await server.elicitInput(params); + } + else if (request.method === 'sampling/createMessage') { + // Send sampling request to client + const params = request.params; + response = await server.createMessage(params); + } + else { + throw new Error(`Unknown request method: ${request.method}`); + } + // Route response back to resolver + if (reqMessage.resolver) { + reqMessage.resolver.setResult(response); + } + } + catch (error) { + if (reqMessage.resolver) { + reqMessage.resolver.setException(error instanceof Error ? error : new Error(String(error))); + } + } + } + // For notifications, we'd send them too but this example focuses on requests + } + } + async waitForUpdate(taskId) { + // Race between store update and queue message + await Promise.race([this.store.waitForUpdate(taskId), this.queue.waitForMessage(taskId)]); + } + routeResponse(requestId, response) { + const resolver = this.pendingRequests.get(requestId); + if (resolver && !resolver.done()) { + this.pendingRequests.delete(requestId); + resolver.setResult(response); + return true; + } + return false; + } + routeError(requestId, error) { + const resolver = this.pendingRequests.get(requestId); + if (resolver && !resolver.done()) { + this.pendingRequests.delete(requestId); + resolver.setException(error); + return true; + } + return false; + } +} +// ============================================================================ +// Task Session - wraps server to enqueue requests during task execution +// ============================================================================ +class TaskSession { + constructor(server, taskId, store, queue) { + this.server = server; + this.taskId = taskId; + this.store = store; + this.queue = queue; + this.requestCounter = 0; + } + nextRequestId() { + return `task-${this.taskId}-${++this.requestCounter}`; + } + async elicit(message, requestedSchema) { + // Update task status to input_required + await this.store.updateTaskStatus(this.taskId, 'input_required'); + const requestId = this.nextRequestId(); + // Build the elicitation request with related-task metadata + const params = { + message, + requestedSchema, + mode: 'form', + _meta: { + [types_js_1.RELATED_TASK_META_KEY]: { taskId: this.taskId } + } + }; + const jsonrpcRequest = { + jsonrpc: '2.0', + id: requestId, + method: 'elicitation/create', + params + }; + // Create resolver to wait for response + const resolver = new Resolver(); + // Enqueue the request + await this.queue.enqueueWithResolver(this.taskId, jsonrpcRequest, resolver, requestId); + try { + // Wait for response + const response = await resolver.wait(); + // Update status back to working + await this.store.updateTaskStatus(this.taskId, 'working'); + return response; + } + catch (error) { + await this.store.updateTaskStatus(this.taskId, 'working'); + throw error; + } + } + async createMessage(messages, maxTokens) { + // Update task status to input_required + await this.store.updateTaskStatus(this.taskId, 'input_required'); + const requestId = this.nextRequestId(); + // Build the sampling request with related-task metadata + const params = { + messages, + maxTokens, + _meta: { + [types_js_1.RELATED_TASK_META_KEY]: { taskId: this.taskId } + } + }; + const jsonrpcRequest = { + jsonrpc: '2.0', + id: requestId, + method: 'sampling/createMessage', + params + }; + // Create resolver to wait for response + const resolver = new Resolver(); + // Enqueue the request + await this.queue.enqueueWithResolver(this.taskId, jsonrpcRequest, resolver, requestId); + try { + // Wait for response + const response = await resolver.wait(); + // Update status back to working + await this.store.updateTaskStatus(this.taskId, 'working'); + return response; + } + catch (error) { + await this.store.updateTaskStatus(this.taskId, 'working'); + throw error; + } + } +} +// ============================================================================ +// Server Setup +// ============================================================================ +const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 8000; +// Create shared stores +const taskStore = new TaskStoreWithNotifications(); +const messageQueue = new TaskMessageQueueWithResolvers(); +const taskResultHandler = new TaskResultHandler(taskStore, messageQueue); +// Track active task executions +const activeTaskExecutions = new Map(); +// Create the server +const createServer = () => { + const server = new index_js_1.Server({ name: 'simple-task-interactive', version: '1.0.0' }, { + capabilities: { + tools: {}, + tasks: { + requests: { + tools: { call: {} } + } + } + } + }); + // Register tools + server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => { + return { + tools: [ + { + name: 'confirm_delete', + description: 'Asks for confirmation before deleting (demonstrates elicitation)', + inputSchema: { + type: 'object', + properties: { + filename: { type: 'string' } + } + }, + execution: { taskSupport: 'required' } + }, + { + name: 'write_haiku', + description: 'Asks LLM to write a haiku (demonstrates sampling)', + inputSchema: { + type: 'object', + properties: { + topic: { type: 'string' } + } + }, + execution: { taskSupport: 'required' } + } + ] + }; + }); + // Handle tool calls + server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request, extra) => { + var _a, _b, _c; + const { name, arguments: args } = request.params; + const taskParams = (((_a = request.params._meta) === null || _a === void 0 ? void 0 : _a.task) || request.params.task); + // Validate task mode - these tools require tasks + if (!taskParams) { + throw new Error(`Tool ${name} requires task mode`); + } + // Create task + const taskOptions = { + ttl: taskParams.ttl, + pollInterval: (_b = taskParams.pollInterval) !== null && _b !== void 0 ? _b : 1000 + }; + const task = await taskStore.createTask(taskOptions, extra.requestId, request, extra.sessionId); + console.log(`\n[Server] ${name} called, task created: ${task.taskId}`); + // Start background task execution + const taskExecution = (async () => { + var _a, _b; + try { + const taskSession = new TaskSession(server, task.taskId, taskStore, messageQueue); + if (name === 'confirm_delete') { + const filename = (_a = args === null || args === void 0 ? void 0 : args.filename) !== null && _a !== void 0 ? _a : 'unknown.txt'; + console.log(`[Server] confirm_delete: asking about '${filename}'`); + console.log('[Server] Sending elicitation request to client...'); + const result = await taskSession.elicit(`Are you sure you want to delete '${filename}'?`, { + type: 'object', + properties: { + confirm: { type: 'boolean' } + }, + required: ['confirm'] + }); + console.log(`[Server] Received elicitation response: action=${result.action}, content=${JSON.stringify(result.content)}`); + let text; + if (result.action === 'accept' && result.content) { + const confirmed = result.content.confirm; + text = confirmed ? `Deleted '${filename}'` : 'Deletion cancelled'; + } + else { + text = 'Deletion cancelled'; + } + console.log(`[Server] Completing task with result: ${text}`); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [{ type: 'text', text }] + }); + } + else if (name === 'write_haiku') { + const topic = (_b = args === null || args === void 0 ? void 0 : args.topic) !== null && _b !== void 0 ? _b : 'nature'; + console.log(`[Server] write_haiku: topic '${topic}'`); + console.log('[Server] Sending sampling request to client...'); + const result = await taskSession.createMessage([ + { + role: 'user', + content: { type: 'text', text: `Write a haiku about ${topic}` } + } + ], 50); + let haiku = 'No response'; + if (result.content && 'text' in result.content) { + haiku = result.content.text; + } + console.log(`[Server] Received sampling response: ${haiku.substring(0, 50)}...`); + console.log('[Server] Completing task with haiku'); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [{ type: 'text', text: `Haiku:\n${haiku}` }] + }); + } + } + catch (error) { + console.error(`[Server] Task ${task.taskId} failed:`, error); + await taskStore.storeTaskResult(task.taskId, 'failed', { + content: [{ type: 'text', text: `Error: ${error}` }], + isError: true + }); + } + finally { + activeTaskExecutions.delete(task.taskId); + } + })(); + activeTaskExecutions.set(task.taskId, { + promise: taskExecution, + server, + sessionId: (_c = extra.sessionId) !== null && _c !== void 0 ? _c : '' + }); + return { task }; + }); + // Handle tasks/get + server.setRequestHandler(types_js_1.GetTaskRequestSchema, async (request) => { + const { taskId } = request.params; + const task = await taskStore.getTask(taskId); + if (!task) { + throw new Error(`Task ${taskId} not found`); + } + return task; + }); + // Handle tasks/result + server.setRequestHandler(types_js_1.GetTaskPayloadRequestSchema, async (request, extra) => { + var _a; + const { taskId } = request.params; + console.log(`[Server] tasks/result called for task ${taskId}`); + return taskResultHandler.handle(taskId, server, (_a = extra.sessionId) !== null && _a !== void 0 ? _a : ''); + }); + return server; +}; +// ============================================================================ +// Express App Setup +// ============================================================================ +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Map to store transports by session ID +const transports = {}; +// Helper to check if request is initialize +const isInitializeRequest = (body) => { + return typeof body === 'object' && body !== null && 'method' in body && body.method === 'initialize'; +}; +// MCP POST endpoint +app.post('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + try { + let transport; + if (sessionId && transports[sessionId]) { + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + onsessioninitialized: sid => { + console.log(`Session initialized: ${sid}`); + transports[sid] = transport; + } + }); + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}`); + delete transports[sid]; + } + }; + const server = createServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; + } + else { + res.status(400).json({ + jsonrpc: '2.0', + error: { code: -32000, message: 'Bad Request: No valid session ID' }, + id: null + }); + return; + } + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { code: -32603, message: 'Internal server error' }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams +app.get('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Handle DELETE requests for session termination +app.delete('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Session termination request: ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Start server +app.listen(PORT, () => { + console.log(`Starting server on http://localhost:${PORT}/mcp`); + console.log('\nAvailable tools:'); + console.log(' - confirm_delete: Demonstrates elicitation (asks user y/n)'); + console.log(' - write_haiku: Demonstrates sampling (requests LLM completion)'); +}); +// Handle shutdown +process.on('SIGINT', async () => { + console.log('\nShutting down server...'); + for (const sessionId of Object.keys(transports)) { + try { + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing session ${sessionId}:`, error); + } + } + taskStore.cleanup(); + messageQueue.cleanup(); + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleTaskInteractive.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/simpleTaskInteractive.js.map b/dist/cjs/examples/server/simpleTaskInteractive.js.map new file mode 100644 index 000000000..7fbf5faad --- /dev/null +++ b/dist/cjs/examples/server/simpleTaskInteractive.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractive.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleTaskInteractive.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;AAEH,sDAAqD;AACrD,6CAAyC;AACzC,oDAA+C;AAC/C,sEAA+E;AAC/E,6CAqBwB;AACxB,0EAAuI;AACvI,+EAAiF;AAEjF,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAE/E,MAAM,QAAQ;IAMV;QAFQ,UAAK,GAAG,KAAK,CAAC;QAGlB,IAAI,CA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AC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC;YACD,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,yBAAyB,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAChE,CAAC;IACL,CAAC;IACD,SAAS,CAAC,OAAO,EAAE,CAAC;IACpB,YAAY,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts new file mode 100644 index 000000000..c536d0c80 --- /dev/null +++ b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=sseAndStreamableHttpCompatibleServer.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map new file mode 100644 index 000000000..fb982c84a --- /dev/null +++ b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sseAndStreamableHttpCompatibleServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/sseAndStreamableHttpCompatibleServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js new file mode 100644 index 000000000..def1932ed --- /dev/null +++ b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js @@ -0,0 +1,263 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const sse_js_1 = require("../../server/sse.js"); +const z = __importStar(require("zod/v4")); +const types_js_1 = require("../../types.js"); +const inMemoryEventStore_js_1 = require("../shared/inMemoryEventStore.js"); +const cors_1 = __importDefault(require("cors")); +/** + * This example server demonstrates backwards compatibility with both: + * 1. The deprecated HTTP+SSE transport (protocol version 2024-11-05) + * 2. The Streamable HTTP transport (protocol version 2025-03-26) + * + * It maintains a single MCP server instance but exposes two transport options: + * - /mcp: The new Streamable HTTP endpoint (supports GET/POST/DELETE) + * - /sse: The deprecated SSE endpoint for older clients (GET to establish stream) + * - /messages: The deprecated POST endpoint for older clients (POST to send messages) + */ +const getServer = () => { + const server = new mcp_js_1.McpServer({ + name: 'backwards-compatible-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + // Register a simple tool that sends notifications over time + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(50) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + return server; +}; +// Create Express application +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use((0, cors_1.default)({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +// Store transports by session ID +const transports = {}; +//============================================================================= +// STREAMABLE HTTP TRANSPORT (PROTOCOL VERSION 2025-03-26) +//============================================================================= +// Handle all MCP Streamable HTTP requests (GET, POST, DELETE) on a single endpoint +app.all('/mcp', async (req, res) => { + console.log(`Received ${req.method} request to /mcp`); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Check if the transport is of the correct type + const existingTransport = transports[sessionId]; + if (existingTransport instanceof streamableHttp_js_1.StreamableHTTPServerTransport) { + // Reuse existing transport + transport = existingTransport; + } + else { + // Transport exists but is not a StreamableHTTPServerTransport (could be SSEServerTransport) + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Session exists but uses a different transport protocol' + }, + id: null + }); + return; + } + } + else if (!sessionId && req.method === 'POST' && (0, types_js_1.isInitializeRequest)(req.body)) { + const eventStore = new inMemoryEventStore_js_1.InMemoryEventStore(); + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + console.log(`StreamableHTTP session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server + const server = getServer(); + await server.connect(transport); + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with the transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +//============================================================================= +// DEPRECATED HTTP+SSE TRANSPORT (PROTOCOL VERSION 2024-11-05) +//============================================================================= +app.get('/sse', async (req, res) => { + console.log('Received GET request to /sse (deprecated SSE transport)'); + const transport = new sse_js_1.SSEServerTransport('/messages', res); + transports[transport.sessionId] = transport; + res.on('close', () => { + delete transports[transport.sessionId]; + }); + const server = getServer(); + await server.connect(transport); +}); +app.post('/messages', async (req, res) => { + const sessionId = req.query.sessionId; + let transport; + const existingTransport = transports[sessionId]; + if (existingTransport instanceof sse_js_1.SSEServerTransport) { + // Reuse existing transport + transport = existingTransport; + } + else { + // Transport exists but is not a SSEServerTransport (could be StreamableHTTPServerTransport) + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Session exists but uses a different transport protocol' + }, + id: null + }); + return; + } + if (transport) { + await transport.handlePostMessage(req, res, req.body); + } + else { + res.status(400).send('No transport found for sessionId'); + } +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Backwards compatible MCP server listening on port ${PORT}`); + console.log(` +============================================== +SUPPORTED TRANSPORT OPTIONS: + +1. Streamable Http(Protocol version: 2025-03-26) + Endpoint: /mcp + Methods: GET, POST, DELETE + Usage: + - Initialize with POST to /mcp + - Establish SSE stream with GET to /mcp + - Send requests with POST to /mcp + - Terminate session with DELETE to /mcp + +2. Http + SSE (Protocol version: 2024-11-05) + Endpoints: /sse (GET) and /messages (POST) + Usage: + - Establish SSE stream with GET to /sse + - Send requests with POST to /messages?sessionId= +============================================== +`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=sseAndStreamableHttpCompatibleServer.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js.map b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js.map new file mode 100644 index 000000000..148cf28b1 --- /dev/null +++ b/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sseAndStreamableHttpCompatibleServer.js","sourceRoot":"","sources":["../../../../src/examples/server/sseAndStreamableHttpCompatibleServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAqD;AACrD,6CAAyC;AACzC,gDAAgD;AAChD,sEAA+E;AAC/E,gDAAyD;AACzD,0CAA4B;AAC5B,6CAAqE;AACrE,2EAAqE;AACrE,gDAAwB;AAExB;;;;;;;;;GASG;AAEH,M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AC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/ssePollingExample.d.ts b/dist/cjs/examples/server/ssePollingExample.d.ts new file mode 100644 index 000000000..63e45548e --- /dev/null +++ b/dist/cjs/examples/server/ssePollingExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=ssePollingExample.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/ssePollingExample.d.ts.map b/dist/cjs/examples/server/ssePollingExample.d.ts.map new file mode 100644 index 000000000..93827316a --- /dev/null +++ b/dist/cjs/examples/server/ssePollingExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/ssePollingExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/ssePollingExample.js b/dist/cjs/examples/server/ssePollingExample.js new file mode 100644 index 000000000..3bbd93585 --- /dev/null +++ b/dist/cjs/examples/server/ssePollingExample.js @@ -0,0 +1,116 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * SSE Polling Example Server (SEP-1699) + * + * This example demonstrates server-initiated SSE stream disconnection + * and client reconnection with Last-Event-ID for resumability. + * + * Key features: + * - Configures `retryInterval` to tell clients how long to wait before reconnecting + * - Uses `eventStore` to persist events for replay after reconnection + * - Calls `closeSSEStream()` to gracefully disconnect clients mid-operation + * + * Run with: npx tsx src/examples/server/ssePollingExample.ts + * Test with: curl or the MCP Inspector + */ +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const inMemoryEventStore_js_1 = require("../shared/inMemoryEventStore.js"); +const cors_1 = __importDefault(require("cors")); +// Create the MCP server +const server = new mcp_js_1.McpServer({ + name: 'sse-polling-example', + version: '1.0.0' +}, { + capabilities: { logging: {} } +}); +// Track active transports by session ID for closeSSEStream access +const transports = new Map(); +// Register a long-running tool that demonstrates server-initiated disconnect +server.tool('long-task', 'A long-running task that sends progress updates. Server will disconnect mid-task to demonstrate polling.', {}, async (_args, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + console.log(`[${extra.sessionId}] Starting long-task...`); + // Send first progress notification + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 25% - Starting work...' + }, extra.sessionId); + await sleep(1000); + // Send second progress notification + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 50% - Halfway there...' + }, extra.sessionId); + await sleep(1000); + // Server decides to disconnect the client to free resources + // Client will reconnect via GET with Last-Event-ID after retryInterval + const transport = transports.get(extra.sessionId); + if (transport) { + console.log(`[${extra.sessionId}] Closing SSE stream to trigger client polling...`); + transport.closeSSEStream(extra.requestId); + } + // Continue processing while client is disconnected + // Events are stored in eventStore and will be replayed on reconnect + await sleep(500); + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 75% - Almost done (sent while client disconnected)...' + }, extra.sessionId); + await sleep(500); + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 100% - Complete!' + }, extra.sessionId); + console.log(`[${extra.sessionId}] Task complete`); + return { + content: [ + { + type: 'text', + text: 'Long task completed successfully!' + } + ] + }; +}); +// Set up Express app +const app = (0, express_1.default)(); +app.use((0, cors_1.default)()); +// Create event store for resumability +const eventStore = new inMemoryEventStore_js_1.InMemoryEventStore(); +// Handle all MCP requests - use express.json() only for this route +app.all('/mcp', express_1.default.json(), async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + // Reuse existing transport or create new one + let transport = sessionId ? transports.get(sessionId) : undefined; + if (!transport) { + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + eventStore, + retryInterval: 2000, // Client should reconnect after 2 seconds + onsessioninitialized: id => { + console.log(`[${id}] Session initialized`); + transports.set(id, transport); + } + }); + // Connect the MCP server to the transport + await server.connect(transport); + } + await transport.handleRequest(req, res, req.body); +}); +// Start the server +const PORT = 3001; +app.listen(PORT, () => { + console.log(`SSE Polling Example Server running on http://localhost:${PORT}/mcp`); + console.log(''); + console.log('This server demonstrates SEP-1699 SSE polling:'); + console.log('- retryInterval: 2000ms (client waits 2s before reconnecting)'); + console.log('- eventStore: InMemoryEventStore (events are persisted for replay)'); + console.log(''); + console.log('Try calling the "long-task" tool to see server-initiated disconnect in action.'); +}); +//# sourceMappingURL=ssePollingExample.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/ssePollingExample.js.map b/dist/cjs/examples/server/ssePollingExample.js.map new file mode 100644 index 000000000..bceb2350b --- /dev/null +++ b/dist/cjs/examples/server/ssePollingExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingExample.js","sourceRoot":"","sources":["../../../../src/examples/server/ssePollingExample.ts"],"names":[],"mappings":";;;;;AAAA;;;;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IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,iDAA6B,CAAC;YAC1C,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAA,wBAAU,GAAE;YACtC,UAAU;YACV,aAAa,EAAE,IAAI,EAAE,0CAA0C;YAC/D,oBAAoB,EAAE,EAAE,CAAC,EAAE;gBACvB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;gBAC3C,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,SAAU,CAAC,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;QAEH,0CAA0C;QAC1C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IAClB,OAAO,CAAC,GAAG,CAAC,0DAA0D,IAAI,MAAM,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,gFAAgF,CAAC,CAAC;AAClG,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts new file mode 100644 index 000000000..4df17831b --- /dev/null +++ b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=standaloneSseWithGetStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map new file mode 100644 index 000000000..df60dc51b --- /dev/null +++ b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"standaloneSseWithGetStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/standaloneSseWithGetStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js new file mode 100644 index 000000000..ae1193d31 --- /dev/null +++ b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js @@ -0,0 +1,116 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = __importDefault(require("express")); +const node_crypto_1 = require("node:crypto"); +const mcp_js_1 = require("../../server/mcp.js"); +const streamableHttp_js_1 = require("../../server/streamableHttp.js"); +const types_js_1 = require("../../types.js"); +// Create an MCP server with implementation details +const server = new mcp_js_1.McpServer({ + name: 'resource-list-changed-notification-server', + version: '1.0.0' +}); +// Store transports by session ID to send notifications +const transports = {}; +const addResource = (name, content) => { + const uri = `https://mcp-example.com/dynamic/${encodeURIComponent(name)}`; + server.resource(name, uri, { mimeType: 'text/plain', description: `Dynamic resource: ${name}` }, async () => { + return { + contents: [{ uri, text: content }] + }; + }); +}; +addResource('example-resource', 'Initial content for example-resource'); +const resourceChangeInterval = setInterval(() => { + const name = (0, node_crypto_1.randomUUID)(); + addResource(name, `Content for ${name}`); +}, 5000); // Change resources every 5 seconds for testing +const app = (0, express_1.default)(); +app.use(express_1.default.json()); +app.post('/mcp', async (req, res) => { + console.log('Received MCP request:', req.body); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) { + // New initialization request + transport = new streamableHttp_js_1.StreamableHTTPServerTransport({ + sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(), + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Connect the transport to the MCP server + await server.connect(transport); + // Handle the request - the onsessioninitialized callback will store the transport + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams (now using built-in support from StreamableHTTP) +app.get('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Establishing SSE stream for session ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + clearInterval(resourceChangeInterval); + await server.close(); + process.exit(0); +}); +//# sourceMappingURL=standaloneSseWithGetStreamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js.map b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js.map new file mode 100644 index 000000000..c48532b79 --- /dev/null +++ b/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"standaloneSseWithGetStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/standaloneSseWithGetStreamableHttp.ts"],"names":[],"mappings":";;;;;AAAA,sDAAqD;AACrD,6CAAyC;AACzC,gDAAgD;AAChD,sEAA+E;AAC/E,6CAAyE;AAEzE,mDAAmD;AACnD,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;IACzB,IAAI,EAAE,2CAA2C;IACjD,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,uDAAuD;AACvD,MAAM,UAAU,GAA2D,EAAE,CAAC;AAE9E,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,EAAE;IAClD,MAAM,GAAG,GAAG,mCAAmC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1E,MAAM,CAAC,QAAQ,CACX,IAAI,EACJ,GAAG,EACH,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,IAAI,EAAE,EAAE,EACpE,KAAK,IAAiC,EAAE;QACpC,OAAO;YACH,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;SACrC,CAAC;IACN,CAAC,CACJ,CAAC;AACN,CAAC,CAAC;AAEF,WAAW,CAAC,kBAAkB,EAAE,sCAAsC,CAAC,CAAC;AAExE,MAAM,sBAAsB,GAAG,WAAW,CAAC,GAAG,EAAE;IAC5C,MAAM,IAAI,GAAG,IAAA,wBAAU,GAAE,CAAC;IAC1B,WAAW,CAAC,IAAI,EAAE,eAAe,IAAI,EAAE,CAAC,CAAC;AAC7C,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,+CAA+C;AAEzD,MAAM,GAAG,GAAG,IAAA,iBAA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BAAmB;AACnB,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;IACrB,IAAI,KAAK,EAAE,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACtC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/server/toolWithSampleServer.d.ts b/dist/cjs/examples/server/toolWithSampleServer.d.ts new file mode 100644 index 000000000..acc24b6a5 --- /dev/null +++ b/dist/cjs/examples/server/toolWithSampleServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=toolWithSampleServer.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/server/toolWithSampleServer.d.ts.map b/dist/cjs/examples/server/toolWithSampleServer.d.ts.map new file mode 100644 index 000000000..bd0cebcf1 --- /dev/null +++ b/dist/cjs/examples/server/toolWithSampleServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"toolWithSampleServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/toolWithSampleServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/examples/server/toolWithSampleServer.js b/dist/cjs/examples/server/toolWithSampleServer.js new file mode 100644 index 000000000..4a35eb798 --- /dev/null +++ b/dist/cjs/examples/server/toolWithSampleServer.js @@ -0,0 +1,71 @@ +"use strict"; +// Run with: npx tsx src/examples/server/toolWithSampleServer.ts +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mcp_js_1 = require("../../server/mcp.js"); +const stdio_js_1 = require("../../server/stdio.js"); +const z = __importStar(require("zod/v4")); +const mcpServer = new mcp_js_1.McpServer({ + name: 'tools-with-sample-server', + version: '1.0.0' +}); +// Tool that uses LLM sampling to summarize any text +mcpServer.registerTool('summarize', { + description: 'Summarize any text using an LLM', + inputSchema: { + text: z.string().describe('Text to summarize') + } +}, async ({ text }) => { + // Call the LLM through MCP sampling + const response = await mcpServer.server.createMessage({ + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please summarize the following text concisely:\n\n${text}` + } + } + ], + maxTokens: 500 + }); + const contents = Array.isArray(response.content) ? response.content : [response.content]; + return { + content: contents.map(content => ({ + type: 'text', + text: content.type === 'text' ? content.text : 'Unable to generate summary' + })) + }; +}); +async function main() { + const transport = new stdio_js_1.StdioServerTransport(); + await mcpServer.connect(transport); + console.log('MCP server is running...'); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=toolWithSampleServer.js.map \ No newline at end of file diff --git a/dist/cjs/examples/server/toolWithSampleServer.js.map b/dist/cjs/examples/server/toolWithSampleServer.js.map new file mode 100644 index 000000000..5f9d21992 --- /dev/null +++ b/dist/cjs/examples/server/toolWithSampleServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"toolWithSampleServer.js","sourceRoot":"","sources":["../../../../src/examples/server/toolWithSampleServer.ts"],"names":[],"mappings":";AAAA,gEAAgE;;;;;;;;;;;;;;;;;;;;;;;;;AAEhE,gDAAgD;AAChD,oDAA6D;AAC7D,0CAA4B;AAE5B,MAAM,SAAS,GAAG,IAAI,kBAAS,CAAC;IAC5B,IAAI,EAAE,0BAA0B;IAChC,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,oDAAoD;AACpD,SAAS,CAAC,YAAY,CAClB,WAAW,EACX;IACI,WAAW,EAAE,iCAAiC;IAC9C,WAAW,EAAE;QACT,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;KACjD;CACJ,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;IACf,oCAAoC;IACpC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC;QAClD,QAAQ,EAAE;YACN;gBACI,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,qDAAqD,IAAI,EAAE;iBACpE;aACJ;SACJ;QACD,SAAS,EAAE,GAAG;KACjB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzF,OAAO;QACH,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,4BAA4B;SAC9E,CAAC,CAAC;KACN,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAC5C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/examples/shared/inMemoryEventStore.d.ts b/dist/cjs/examples/shared/inMemoryEventStore.d.ts new file mode 100644 index 000000000..26ff38cf9 --- /dev/null +++ b/dist/cjs/examples/shared/inMemoryEventStore.d.ts @@ -0,0 +1,31 @@ +import { JSONRPCMessage } from '../../types.js'; +import { EventStore } from '../../server/streamableHttp.js'; +/** + * Simple in-memory implementation of the EventStore interface for resumability + * This is primarily intended for examples and testing, not for production use + * where a persistent storage solution would be more appropriate. + */ +export declare class InMemoryEventStore implements EventStore { + private events; + /** + * Generates a unique event ID for a given stream ID + */ + private generateEventId; + /** + * Extracts the stream ID from an event ID + */ + private getStreamIdFromEventId; + /** + * Stores an event with a generated event ID + * Implements EventStore.storeEvent + */ + storeEvent(streamId: string, message: JSONRPCMessage): Promise; + /** + * Replays events that occurred after a specific event ID + * Implements EventStore.replayEventsAfter + */ + replayEventsAfter(lastEventId: string, { send }: { + send: (eventId: string, message: JSONRPCMessage) => Promise; + }): Promise; +} +//# sourceMappingURL=inMemoryEventStore.d.ts.map \ No newline at end of file diff --git a/dist/cjs/examples/shared/inMemoryEventStore.d.ts.map b/dist/cjs/examples/shared/inMemoryEventStore.d.ts.map new file mode 100644 index 000000000..a67ee6cd1 --- /dev/null +++ b/dist/cjs/examples/shared/inMemoryEventStore.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemoryEventStore.d.ts","sourceRoot":"","sources":["../../../../src/examples/shared/inMemoryEventStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACjD,OAAO,CAAC,MAAM,CAAyE;IAEvF;;OAEG;IACH,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAK9B;;;OAGG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAM5E;;;OAGG;IACG,iBAAiB,CACnB,WAAW,EAAE,MAAM,EACnB,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,GAChF,OAAO,CAAC,MAAM,CAAC;CAkCrB"} \ No newline at end of file diff --git a/dist/cjs/examples/shared/inMemoryEventStore.js b/dist/cjs/examples/shared/inMemoryEventStore.js new file mode 100644 index 000000000..d33ffdb5c --- /dev/null +++ b/dist/cjs/examples/shared/inMemoryEventStore.js @@ -0,0 +1,69 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemoryEventStore = void 0; +/** + * Simple in-memory implementation of the EventStore interface for resumability + * This is primarily intended for examples and testing, not for production use + * where a persistent storage solution would be more appropriate. + */ +class InMemoryEventStore { + constructor() { + this.events = new Map(); + } + /** + * Generates a unique event ID for a given stream ID + */ + generateEventId(streamId) { + return `${streamId}_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`; + } + /** + * Extracts the stream ID from an event ID + */ + getStreamIdFromEventId(eventId) { + const parts = eventId.split('_'); + return parts.length > 0 ? parts[0] : ''; + } + /** + * Stores an event with a generated event ID + * Implements EventStore.storeEvent + */ + async storeEvent(streamId, message) { + const eventId = this.generateEventId(streamId); + this.events.set(eventId, { streamId, message }); + return eventId; + } + /** + * Replays events that occurred after a specific event ID + * Implements EventStore.replayEventsAfter + */ + async replayEventsAfter(lastEventId, { send }) { + if (!lastEventId || !this.events.has(lastEventId)) { + return ''; + } + // Extract the stream ID from the event ID + const streamId = this.getStreamIdFromEventId(lastEventId); + if (!streamId) { + return ''; + } + let foundLastEvent = false; + // Sort events by eventId for chronological ordering + const sortedEvents = [...this.events.entries()].sort((a, b) => a[0].localeCompare(b[0])); + for (const [eventId, { streamId: eventStreamId, message }] of sortedEvents) { + // Only include events from the same stream + if (eventStreamId !== streamId) { + continue; + } + // Start sending events after we find the lastEventId + if (eventId === lastEventId) { + foundLastEvent = true; + continue; + } + if (foundLastEvent) { + await send(eventId, message); + } + } + return streamId; + } +} +exports.InMemoryEventStore = InMemoryEventStore; +//# sourceMappingURL=inMemoryEventStore.js.map \ No newline at end of file diff --git a/dist/cjs/examples/shared/inMemoryEventStore.js.map b/dist/cjs/examples/shared/inMemoryEventStore.js.map new file mode 100644 index 000000000..d69645063 --- /dev/null +++ b/dist/cjs/examples/shared/inMemoryEventStore.js.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemoryEventStore.js","sourceRoot":"","sources":["../../../../src/examples/shared/inMemoryEventStore.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACH,MAAa,kBAAkB;IAA/B;QACY,WAAM,GAA+D,IAAI,GAAG,EAAE,CAAC;IAoE3F,CAAC;IAlEG;;OAEG;IACK,eAAe,CAAC,QAAgB;QACpC,OAAO,GAAG,QAAQ,IAAI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AC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEzF,KAAK,MAAM,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC;YACzE,2CAA2C;YAC3C,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;gBAC7B,SAAS;YACb,CAAC;YAED,qDAAqD;YACrD,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;gBAC1B,cAAc,GAAG,IAAI,CAAC;gBACtB,SAAS;YACb,CAAC;YAED,IAAI,cAAc,EAAE,CAAC;gBACjB,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACjC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AArED,gDAqEC"} \ No newline at end of file diff --git a/dist/cjs/experimental/index.d.ts b/dist/cjs/experimental/index.d.ts new file mode 100644 index 000000000..2a8633553 --- /dev/null +++ b/dist/cjs/experimental/index.d.ts @@ -0,0 +1,13 @@ +/** + * Experimental MCP SDK features. + * WARNING: These APIs are experimental and may change without notice. + * + * Import experimental features from this module: + * ```typescript + * import { TaskStore, InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental'; + * ``` + * + * @experimental + */ +export * from './tasks/index.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/index.d.ts.map b/dist/cjs/experimental/index.d.ts.map new file mode 100644 index 000000000..410892aa4 --- /dev/null +++ b/dist/cjs/experimental/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kBAAkB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/experimental/index.js b/dist/cjs/experimental/index.js new file mode 100644 index 000000000..7634e674c --- /dev/null +++ b/dist/cjs/experimental/index.js @@ -0,0 +1,29 @@ +"use strict"; +/** + * Experimental MCP SDK features. + * WARNING: These APIs are experimental and may change without notice. + * + * Import experimental features from this module: + * ```typescript + * import { TaskStore, InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental'; + * ``` + * + * @experimental + */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./tasks/index.js"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/index.js.map b/dist/cjs/experimental/index.js.map new file mode 100644 index 000000000..110189e9f --- /dev/null +++ b/dist/cjs/experimental/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;AAEH,mDAAiC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/client.d.ts b/dist/cjs/experimental/tasks/client.d.ts new file mode 100644 index 000000000..9c7a92834 --- /dev/null +++ b/dist/cjs/experimental/tasks/client.d.ts @@ -0,0 +1,121 @@ +/** + * Experimental client task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { Client } from '../../client/index.js'; +import type { RequestOptions } from '../../shared/protocol.js'; +import type { ResponseMessage } from '../../shared/responseMessage.js'; +import type { AnyObjectSchema, SchemaOutput } from '../../server/zod-compat.js'; +import type { CallToolRequest, ClientRequest, Notification, Request, Result } from '../../types.js'; +import { CallToolResultSchema, type CompatibilityCallToolResultSchema } from '../../types.js'; +import type { GetTaskResult, ListTasksResult, CancelTaskResult } from './types.js'; +/** + * Experimental task features for MCP clients. + * + * Access via `client.experimental.tasks`: + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'tool', arguments: {} }); + * const task = await client.experimental.tasks.getTask(taskId); + * ``` + * + * @experimental + */ +export declare class ExperimentalClientTasks { + private readonly _client; + constructor(_client: Client); + /** + * Calls a tool and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to tool execution, allowing you to + * observe intermediate task status updates for long-running tool calls. + * Automatically validates structured output if the tool has an outputSchema. + * + * @example + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} }); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Tool execution started:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Tool status:', message.task.status); + * break; + * case 'result': + * console.log('Tool result:', message.result); + * break; + * case 'error': + * console.error('Tool error:', message.error); + * break; + * } + * } + * ``` + * + * @param params - Tool call parameters (name and arguments) + * @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema) + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + callToolStream(params: CallToolRequest['params'], resultSchema?: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + getTask(taskId: string, options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + getTaskResult(taskId: string, resultSchema?: T, options?: RequestOptions): Promise>; + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + listTasks(cursor?: string, options?: RequestOptions): Promise; + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + cancelTask(taskId: string, options?: RequestOptions): Promise; + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request: ClientRequest | RequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; +} +//# sourceMappingURL=client.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/client.d.ts.map b/dist/cjs/experimental/tasks/client.d.ts.map new file mode 100644 index 000000000..e54158d65 --- /dev/null +++ b/dist/cjs/experimental/tasks/client.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,KAAK,iCAAiC,EAAuB,MAAM,gBAAgB,CAAC;AAEnH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAgBnF;;;;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OAAO,CAAC,EAAE,cAAc,GACzB,cAAc,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;CAWlE"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/client.js b/dist/cjs/experimental/tasks/client.js new file mode 100644 index 000000000..e9adca24e --- /dev/null +++ b/dist/cjs/experimental/tasks/client.js @@ -0,0 +1,189 @@ +"use strict"; +/** + * Experimental client task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ExperimentalClientTasks = void 0; +const types_js_1 = require("../../types.js"); +/** + * Experimental task features for MCP clients. + * + * Access via `client.experimental.tasks`: + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'tool', arguments: {} }); + * const task = await client.experimental.tasks.getTask(taskId); + * ``` + * + * @experimental + */ +class ExperimentalClientTasks { + constructor(_client) { + this._client = _client; + } + /** + * Calls a tool and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to tool execution, allowing you to + * observe intermediate task status updates for long-running tool calls. + * Automatically validates structured output if the tool has an outputSchema. + * + * @example + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} }); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Tool execution started:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Tool status:', message.task.status); + * break; + * case 'result': + * console.log('Tool result:', message.result); + * break; + * case 'error': + * console.error('Tool error:', message.error); + * break; + * } + * } + * ``` + * + * @param params - Tool call parameters (name and arguments) + * @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema) + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + async *callToolStream(params, resultSchema = types_js_1.CallToolResultSchema, options) { + var _a; + // Access Client's internal methods + const clientInternal = this._client; + // Add task creation parameters if server supports it and not explicitly provided + const optionsWithTask = { + ...options, + // We check if the tool is known to be a task during auto-configuration, but assume + // the caller knows what they're doing if they pass this explicitly + task: (_a = options === null || options === void 0 ? void 0 : options.task) !== null && _a !== void 0 ? _a : (clientInternal.isToolTask(params.name) ? {} : undefined) + }; + const stream = clientInternal.requestStream({ method: 'tools/call', params }, resultSchema, optionsWithTask); + // Get the validator for this tool (if it has an output schema) + const validator = clientInternal.getToolOutputValidator(params.name); + // Iterate through the stream and validate the final result if needed + for await (const message of stream) { + // If this is a result message and the tool has an output schema, validate it + if (message.type === 'result' && validator) { + const result = message.result; + // If tool has outputSchema, it MUST return structuredContent (unless it's an error) + if (!result.structuredContent && !result.isError) { + yield { + type: 'error', + error: new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`) + }; + return; + } + // Only validate structured content if present (not when there's an error) + if (result.structuredContent) { + try { + // Validate the structured content against the schema + const validationResult = validator(result.structuredContent); + if (!validationResult.valid) { + yield { + type: 'error', + error: new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`) + }; + return; + } + } + catch (error) { + if (error instanceof types_js_1.McpError) { + yield { type: 'error', error }; + return; + } + yield { + type: 'error', + error: new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`) + }; + return; + } + } + } + // Yield the message (either validated result or any other message type) + yield message; + } + } + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + async getTask(taskId, options) { + return this._client.getTask({ taskId }, options); + } + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + async getTaskResult(taskId, resultSchema, options) { + // Delegate to the client's underlying Protocol method + return this._client.getTaskResult({ taskId }, resultSchema, options); + } + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + async listTasks(cursor, options) { + // Delegate to the client's underlying Protocol method + return this._client.listTasks(cursor ? { cursor } : undefined, options); + } + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + async cancelTask(taskId, options) { + // Delegate to the client's underlying Protocol method + return this._client.cancelTask({ taskId }, options); + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request, resultSchema, options) { + return this._client.requestStream(request, resultSchema, options); + } +} +exports.ExperimentalClientTasks = ExperimentalClientTasks; +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/client.js.map b/dist/cjs/experimental/tasks/client.js.map new file mode 100644 index 000000000..612a61914 --- /dev/null +++ b/dist/cjs/experimental/tasks/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAOH,6CAAmH;AAkBnH;;;;;;;;;;GAUG;AACH,MAAa,uBAAuB;IAKhC,YAA6B,OAAiD;QAAjD,YAAO,GAAP,OAAO,CAA0C;IAAG,CAAC;IAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,KAAK,CAAC,CAAC,cAAc,CACjB,MAAiC,EACjC,eAAkB,+BAAyB,EAC3C,OAAwB;;QAExB,mCAAmC;QACnC,MAAM,cAAc,GAAG,IAAI,CAAC,OAA8C,CAAC;QAE3E,iFAAiF;QACjF,MAAM,eAAe,GAAG;YACpB,GAAG,OAA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;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,OAAwB;QACrD,sDAAsD;QACtD,OACI,IAAI,CAAC,OAGR,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,aAAa,CACT,OAAiC,EACjC,YAAe,EACf,OAAwB;QAUxB,OAAQ,IAAI,CAAC,OAA8C,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9G,CAAC;CACJ;AA9ND,0DA8NC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/helpers.d.ts b/dist/cjs/experimental/tasks/helpers.d.ts new file mode 100644 index 000000000..f5e505f81 --- /dev/null +++ b/dist/cjs/experimental/tasks/helpers.d.ts @@ -0,0 +1,47 @@ +/** + * Experimental task capability assertion helpers. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +/** + * Type representing the task requests capability structure. + * This is derived from ClientTasksCapability.requests and ServerTasksCapability.requests. + */ +interface TaskRequestsCapability { + tools?: { + call?: object; + }; + sampling?: { + createMessage?: object; + }; + elicitation?: { + create?: object; + }; +} +/** + * Asserts that task creation is supported for tools/call. + * Used by Client.assertTaskCapability and Server.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export declare function assertToolsCallTaskCapability(requests: TaskRequestsCapability | undefined, method: string, entityName: 'Server' | 'Client'): void; +/** + * Asserts that task creation is supported for sampling/createMessage or elicitation/create. + * Used by Server.assertTaskCapability and Client.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export declare function assertClientRequestTaskCapability(requests: TaskRequestsCapability | undefined, method: string, entityName: 'Server' | 'Client'): void; +export {}; +//# sourceMappingURL=helpers.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/helpers.d.ts.map b/dist/cjs/experimental/tasks/helpers.d.ts.map new file mode 100644 index 000000000..99dc90343 --- /dev/null +++ b/dist/cjs/experimental/tasks/helpers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,UAAU,sBAAsB;IAC5B,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,WAAW,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CACzC,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAChC,IAAI,CAgBN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC7C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAChC,IAAI,CAsBN"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/helpers.js b/dist/cjs/experimental/tasks/helpers.js new file mode 100644 index 000000000..bd51a7084 --- /dev/null +++ b/dist/cjs/experimental/tasks/helpers.js @@ -0,0 +1,70 @@ +"use strict"; +/** + * Experimental task capability assertion helpers. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.assertToolsCallTaskCapability = assertToolsCallTaskCapability; +exports.assertClientRequestTaskCapability = assertClientRequestTaskCapability; +/** + * Asserts that task creation is supported for tools/call. + * Used by Client.assertTaskCapability and Server.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +function assertToolsCallTaskCapability(requests, method, entityName) { + var _a; + if (!requests) { + throw new Error(`${entityName} does not support task creation (required for ${method})`); + } + switch (method) { + case 'tools/call': + if (!((_a = requests.tools) === null || _a === void 0 ? void 0 : _a.call)) { + throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`); + } + break; + default: + // Method doesn't support tasks, which is fine - no error + break; + } +} +/** + * Asserts that task creation is supported for sampling/createMessage or elicitation/create. + * Used by Server.assertTaskCapability and Client.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +function assertClientRequestTaskCapability(requests, method, entityName) { + var _a, _b; + if (!requests) { + throw new Error(`${entityName} does not support task creation (required for ${method})`); + } + switch (method) { + case 'sampling/createMessage': + if (!((_a = requests.sampling) === null || _a === void 0 ? void 0 : _a.createMessage)) { + throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`); + } + break; + case 'elicitation/create': + if (!((_b = requests.elicitation) === null || _b === void 0 ? void 0 : _b.create)) { + throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`); + } + break; + default: + // Method doesn't support tasks, which is fine - no error + break; + } +} +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/helpers.js.map b/dist/cjs/experimental/tasks/helpers.js.map new file mode 100644 index 000000000..c460c4d06 --- /dev/null +++ b/dist/cjs/experimental/tasks/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/helpers.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuBH,sEAoBC;AAaD,8EA0BC;AAtED;;;;;;;;;;GAUG;AACH,SAAgB,6BAA6B,CACzC,QAA4C,EAC5C,MAAc,EACd,UAA+B;;IAE/B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,iDAAiD,MAAM,GAAG,CAAC,CAAC;IAC7F,CAAC;IAED,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,YAAY;YACb,IAAI,CAAC,CAAA,MAAA,QAAQ,CAAC,KAAK,0CAAE,IAAI,CAAA,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,gEAAgE,MAAM,GAAG,CAAC,CAAC;YAC5G,CAAC;YACD,MAAM;QAEV;YACI,yDAAyD;YACzD,MAAM;IACd,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,iCAAiC,CAC7C,QAA4C,EAC5C,MAAc,EACd,UAA+B;;IAE/B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,iDAAiD,MAAM,GAAG,CAAC,CAAC;IAC7F,CAAC;IAED,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,wBAAwB;YACzB,IAAI,CAAC,CAAA,MAAA,QAAQ,CAAC,QAAQ,0CAAE,aAAa,CAAA,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,4EAA4E,MAAM,GAAG,CAAC,CAAC;YACxH,CAAC;YACD,MAAM;QAEV,KAAK,oBAAoB;YACrB,IAAI,CAAC,CAAA,MAAA,QAAQ,CAAC,WAAW,0CAAE,MAAM,CAAA,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,wEAAwE,MAAM,GAAG,CAAC,CAAC;YACpH,CAAC;YACD,MAAM;QAEV;YACI,yDAAyD;YACzD,MAAM;IACd,CAAC;AACL,CAAC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/index.d.ts b/dist/cjs/experimental/tasks/index.d.ts new file mode 100644 index 000000000..33ab79169 --- /dev/null +++ b/dist/cjs/experimental/tasks/index.d.ts @@ -0,0 +1,16 @@ +/** + * Experimental task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +export * from './types.js'; +export * from './interfaces.js'; +export * from './helpers.js'; +export * from './client.js'; +export * from './server.js'; +export * from './mcp-server.js'; +export * from './stores/in-memory.js'; +export type { ResponseMessage, TaskStatusMessage, TaskCreatedMessage, ResultMessage, ErrorMessage, BaseResponseMessage } from '../../shared/responseMessage.js'; +export { takeResult, toArrayAsync } from '../../shared/responseMessage.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/index.d.ts.map b/dist/cjs/experimental/tasks/index.d.ts.map new file mode 100644 index 000000000..cf117ed5f --- /dev/null +++ b/dist/cjs/experimental/tasks/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,cAAc,CAAC;AAG7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,uBAAuB,CAAC;AAGtC,YAAY,EACR,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/index.js b/dist/cjs/experimental/tasks/index.js new file mode 100644 index 000000000..25296f6d6 --- /dev/null +++ b/dist/cjs/experimental/tasks/index.js @@ -0,0 +1,39 @@ +"use strict"; +/** + * Experimental task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toArrayAsync = exports.takeResult = void 0; +// Re-export spec types for convenience +__exportStar(require("./types.js"), exports); +// SDK implementation interfaces +__exportStar(require("./interfaces.js"), exports); +// Assertion helpers +__exportStar(require("./helpers.js"), exports); +// Wrapper classes +__exportStar(require("./client.js"), exports); +__exportStar(require("./server.js"), exports); +__exportStar(require("./mcp-server.js"), exports); +// Store implementations +__exportStar(require("./stores/in-memory.js"), exports); +var responseMessage_js_1 = require("../../shared/responseMessage.js"); +Object.defineProperty(exports, "takeResult", { enumerable: true, get: function () { return responseMessage_js_1.takeResult; } }); +Object.defineProperty(exports, "toArrayAsync", { enumerable: true, get: function () { return responseMessage_js_1.toArrayAsync; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/index.js.map b/dist/cjs/experimental/tasks/index.js.map new file mode 100644 index 000000000..3d570658c --- /dev/null +++ b/dist/cjs/experimental/tasks/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;AAEH,uCAAuC;AACvC,6CAA2B;AAE3B,gCAAgC;AAChC,kDAAgC;AAEhC,oBAAoB;AACpB,+CAA6B;AAE7B,kBAAkB;AAClB,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAEhC,wBAAwB;AACxB,wDAAsC;AAWtC,sEAA2E;AAAlE,gHAAA,UAAU,OAAA;AAAE,kHAAA,YAAY,OAAA"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/interfaces.d.ts b/dist/cjs/experimental/tasks/interfaces.d.ts new file mode 100644 index 000000000..da0f6f9b8 --- /dev/null +++ b/dist/cjs/experimental/tasks/interfaces.d.ts @@ -0,0 +1,232 @@ +/** + * Experimental task interfaces for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + */ +import { Task, Request, RequestId, Result, JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, JSONRPCError, ServerRequest, ServerNotification, CallToolResult, GetTaskResult, ToolExecution } from '../../types.js'; +import { CreateTaskResult } from './types.js'; +import type { RequestHandlerExtra, RequestTaskStore } from '../../shared/protocol.js'; +import type { ZodRawShapeCompat, AnySchema, ShapeOutput } from '../../server/zod-compat.js'; +/** + * Extended handler extra with task store for task creation. + * @experimental + */ +export interface CreateTaskRequestHandlerExtra extends RequestHandlerExtra { + taskStore: RequestTaskStore; +} +/** + * Extended handler extra with task ID and store for task operations. + * @experimental + */ +export interface TaskRequestHandlerExtra extends RequestHandlerExtra { + taskId: string; + taskStore: RequestTaskStore; +} +/** + * Base callback type for tool handlers. + * @experimental + */ +export type BaseToolCallback, Args extends undefined | ZodRawShapeCompat | AnySchema = undefined> = Args extends ZodRawShapeCompat ? (args: ShapeOutput, extra: ExtraT) => SendResultT | Promise : Args extends AnySchema ? (args: unknown, extra: ExtraT) => SendResultT | Promise : (extra: ExtraT) => SendResultT | Promise; +/** + * Handler for creating a task. + * @experimental + */ +export type CreateTaskRequestHandler = BaseToolCallback; +/** + * Handler for task operations (get, getResult). + * @experimental + */ +export type TaskRequestHandler = BaseToolCallback; +/** + * Interface for task-based tool handlers. + * @experimental + */ +export interface ToolTaskHandler { + createTask: CreateTaskRequestHandler; + getTask: TaskRequestHandler; + getTaskResult: TaskRequestHandler; +} +/** + * Task-specific execution configuration. + * taskSupport cannot be 'forbidden' for task-based tools. + * @experimental + */ +export type TaskToolExecution = Omit & { + taskSupport: TaskSupport extends 'forbidden' | undefined ? never : TaskSupport; +}; +/** + * Represents a message queued for side-channel delivery via tasks/result. + * + * This is a serializable data structure that can be stored in external systems. + * All fields are JSON-serializable. + */ +export type QueuedMessage = QueuedRequest | QueuedNotification | QueuedResponse | QueuedError; +export interface BaseQueuedMessage { + /** Type of message */ + type: string; + /** When the message was queued (milliseconds since epoch) */ + timestamp: number; +} +export interface QueuedRequest extends BaseQueuedMessage { + type: 'request'; + /** The actual JSONRPC request */ + message: JSONRPCRequest; +} +export interface QueuedNotification extends BaseQueuedMessage { + type: 'notification'; + /** The actual JSONRPC notification */ + message: JSONRPCNotification; +} +export interface QueuedResponse extends BaseQueuedMessage { + type: 'response'; + /** The actual JSONRPC response */ + message: JSONRPCResponse; +} +export interface QueuedError extends BaseQueuedMessage { + type: 'error'; + /** The actual JSONRPC error */ + message: JSONRPCError; +} +/** + * Interface for managing per-task FIFO message queues. + * + * Similar to TaskStore, this allows pluggable queue implementations + * (in-memory, Redis, other distributed queues, etc.). + * + * Each method accepts taskId and optional sessionId parameters to enable + * a single queue instance to manage messages for multiple tasks, with + * isolation based on task ID and session ID. + * + * All methods are async to support external storage implementations. + * All data in QueuedMessage must be JSON-serializable. + * + * @experimental + */ +export interface TaskMessageQueue { + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + enqueue(taskId: string, message: QueuedMessage, sessionId?: string, maxSize?: number): Promise; + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + dequeue(taskId: string, sessionId?: string): Promise; + /** + * Removes and returns all messages from the queue for a specific task. + * Used when tasks are cancelled or failed to clean up pending messages. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + dequeueAll(taskId: string, sessionId?: string): Promise; +} +/** + * Task creation options. + * @experimental + */ +export interface CreateTaskOptions { + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl?: number | null; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval?: number; + /** + * Additional context to pass to the task store. + */ + context?: Record; +} +/** + * Interface for storing and retrieving task state and results. + * + * Similar to Transport, this allows pluggable task storage implementations + * (in-memory, database, distributed cache, etc.). + * + * @experimental + */ +export interface TaskStore { + /** + * Creates a new task with the given creation parameters and original request. + * The implementation must generate a unique taskId and createdAt timestamp. + * + * TTL Management: + * - The implementation receives the TTL suggested by the requestor via taskParams.ttl + * - The implementation MAY override the requested TTL (e.g., to enforce limits) + * - The actual TTL used MUST be returned in the Task object + * - Null TTL indicates unlimited task lifetime (no automatic cleanup) + * - Cleanup SHOULD occur automatically after TTL expires, regardless of task status + * + * @param taskParams - The task creation parameters from the request (ttl, pollInterval) + * @param requestId - The JSON-RPC request ID + * @param request - The original request that triggered task creation + * @param sessionId - Optional session ID for binding the task to a specific session + * @returns The created task object + */ + createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, sessionId?: string): Promise; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns The task object, or null if it does not exist + */ + getTask(taskId: string, sessionId?: string): Promise; + /** + * Stores the result of a task and sets its final status. + * + * @param taskId - The task identifier + * @param status - The final status: 'completed' for success, 'failed' for errors + * @param result - The result to store + * @param sessionId - Optional session ID for binding the operation to a specific session + */ + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, sessionId?: string): Promise; + /** + * Retrieves the stored result of a task. + * + * @param taskId - The task identifier + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns The stored result + */ + getTaskResult(taskId: string, sessionId?: string): Promise; + /** + * Updates a task's status (e.g., to 'cancelled', 'failed', 'completed'). + * + * @param taskId - The task identifier + * @param status - The new status + * @param statusMessage - Optional diagnostic message for failed tasks or other status information + * @param sessionId - Optional session ID for binding the operation to a specific session + */ + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string, sessionId?: string): Promise; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @param cursor - Optional cursor for pagination + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns An object containing the tasks array and an optional nextCursor + */ + listTasks(cursor?: string, sessionId?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; +} +/** + * Checks if a task status represents a terminal state. + * Terminal states are those where the task has finished and will not change. + * + * @param status - The task status to check + * @returns True if the status is terminal (completed, failed, or cancelled) + * @experimental + */ +export declare function isTerminal(status: Task['status']): boolean; +//# sourceMappingURL=interfaces.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/interfaces.d.ts.map b/dist/cjs/experimental/tasks/interfaces.d.ts.map new file mode 100644 index 000000000..9bf002e3d --- /dev/null +++ b/dist/cjs/experimental/tasks/interfaces.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,IAAI,EACJ,OAAO,EACP,SAAS,EACT,MAAM,EACN,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,aAAa,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAM5F;;;GAGG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ACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnE;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpH;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnG;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,OAAO,CAE1D"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/interfaces.js b/dist/cjs/experimental/tasks/interfaces.js new file mode 100644 index 000000000..8f533bbae --- /dev/null +++ b/dist/cjs/experimental/tasks/interfaces.js @@ -0,0 +1,19 @@ +"use strict"; +/** + * Experimental task interfaces for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isTerminal = isTerminal; +/** + * Checks if a task status represents a terminal state. + * Terminal states are those where the task has finished and will not change. + * + * @param status - The task status to check + * @returns True if the status is terminal (completed, failed, or cancelled) + * @experimental + */ +function isTerminal(status) { + return status === 'completed' || status === 'failed' || status === 'cancelled'; +} +//# sourceMappingURL=interfaces.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/interfaces.js.map b/dist/cjs/experimental/tasks/interfaces.js.map new file mode 100644 index 000000000..c3cd4edd2 --- /dev/null +++ b/dist/cjs/experimental/tasks/interfaces.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA2RH,gCAEC;AAVD;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,MAAsB;IAC7C,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnF,CAAC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/mcp-server.d.ts b/dist/cjs/experimental/tasks/mcp-server.d.ts new file mode 100644 index 000000000..b3244f9d6 --- /dev/null +++ b/dist/cjs/experimental/tasks/mcp-server.d.ts @@ -0,0 +1,77 @@ +/** + * Experimental McpServer task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { McpServer, RegisteredTool } from '../../server/mcp.js'; +import type { ZodRawShapeCompat, AnySchema } from '../../server/zod-compat.js'; +import type { ToolAnnotations } from '../../types.js'; +import type { ToolTaskHandler, TaskToolExecution } from './interfaces.js'; +/** + * Experimental task features for McpServer. + * + * Access via `server.experimental.tasks`: + * ```typescript + * server.experimental.tasks.registerToolTask('long-running', config, handler); + * ``` + * + * @experimental + */ +export declare class ExperimentalMcpServerTasks { + private readonly _mcpServer; + constructor(_mcpServer: McpServer); + /** + * Registers a task-based tool with a config object and handler. + * + * Task-based tools support long-running operations that can be polled for status + * and results. The handler must implement `createTask`, `getTask`, and `getTaskResult` + * methods. + * + * @example + * ```typescript + * server.experimental.tasks.registerToolTask('long-computation', { + * description: 'Performs a long computation', + * inputSchema: { input: z.string() }, + * execution: { taskSupport: 'required' } + * }, { + * createTask: async (args, extra) => { + * const task = await extra.taskStore.createTask({ ttl: 300000 }); + * startBackgroundWork(task.taskId, args); + * return { task }; + * }, + * getTask: async (args, extra) => { + * return extra.taskStore.getTask(extra.taskId); + * }, + * getTaskResult: async (args, extra) => { + * return extra.taskStore.getTaskResult(extra.taskId); + * } + * }); + * ``` + * + * @param name - The tool name + * @param config - Tool configuration (description, schemas, etc.) + * @param handler - Task handler with createTask, getTask, getTaskResult methods + * @returns RegisteredTool for managing the tool's lifecycle + * + * @experimental + */ + registerToolTask(name: string, config: { + title?: string; + description?: string; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + execution?: TaskToolExecution; + _meta?: Record; + }, handler: ToolTaskHandler): RegisteredTool; + registerToolTask(name: string, config: { + title?: string; + description?: string; + inputSchema: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + execution?: TaskToolExecution; + _meta?: Record; + }, handler: ToolTaskHandler): RegisteredTool; +} +//# sourceMappingURL=mcp-server.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/mcp-server.d.ts.map b/dist/cjs/experimental/tasks/mcp-server.d.ts.map new file mode 100644 index 000000000..84ee9e08d --- /dev/null +++ b/dist/cjs/experimental/tasks/mcp-server.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAkB,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAoB1E;;;;;;;;;GASG;AACH,qBAAa,0BAA0B;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,SAAS;IAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,gBAAgB,CAAC,UAAU,SAAS,SAAS,GAAG,iBAAiB,GAAG,SAAS,EACzE,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,UAAU,CAAC;QAC1B,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B,SAAS,CAAC,EAAE,iBAAiB,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,EACD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GACpC,cAAc;IAEjB,gBAAgB,CAAC,SAAS,SAAS,iBAAiB,GAAG,SAAS,EAAE,UAAU,SAAS,SAAS,GAAG,iBAAiB,GAAG,SAAS,EAC1H,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,SAAS,CAAC;QACvB,YAAY,CAAC,EAAE,UAAU,CAAC;QAC1B,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B,SAAS,CAAC,EAAE,iBAAiB,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,EACD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GACpC,cAAc;CAsCpB"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/mcp-server.js b/dist/cjs/experimental/tasks/mcp-server.js new file mode 100644 index 000000000..a2718e1e0 --- /dev/null +++ b/dist/cjs/experimental/tasks/mcp-server.js @@ -0,0 +1,36 @@ +"use strict"; +/** + * Experimental McpServer task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ExperimentalMcpServerTasks = void 0; +/** + * Experimental task features for McpServer. + * + * Access via `server.experimental.tasks`: + * ```typescript + * server.experimental.tasks.registerToolTask('long-running', config, handler); + * ``` + * + * @experimental + */ +class ExperimentalMcpServerTasks { + constructor(_mcpServer) { + this._mcpServer = _mcpServer; + } + registerToolTask(name, config, handler) { + // Validate that taskSupport is not 'forbidden' for task-based tools + const execution = { taskSupport: 'required', ...config.execution }; + if (execution.taskSupport === 'forbidden') { + throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`); + } + // Access McpServer's internal _createRegisteredTool method + const mcpServerInternal = this._mcpServer; + return mcpServerInternal._createRegisteredTool(name, config.title, config.description, config.inputSchema, config.outputSchema, config.annotations, execution, config._meta, handler); + } +} +exports.ExperimentalMcpServerTasks = ExperimentalMcpServerTasks; +//# sourceMappingURL=mcp-server.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/mcp-server.js.map b/dist/cjs/experimental/tasks/mcp-server.js.map new file mode 100644 index 000000000..ff3e8c49a --- /dev/null +++ b/dist/cjs/experimental/tasks/mcp-server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/mcp-server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyBH;;;;;;;;;GASG;AACH,MAAa,0BAA0B;IACnC,YAA6B,UAAqB;QAArB,eAAU,GAAV,UAAU,CAAW;IAAG,CAAC;IAgEtD,gBAAgB,CAIZ,IAAY,EACZ,MAQC,EACD,OAAmC;QAEnC,oEAAoE;QACpE,MAAM,SAAS,GAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAClF,IAAI,SAAS,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,6DAA6D,CAAC,CAAC;QAC3H,CAAC;QAED,2DAA2D;QAC3D,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAA0C,CAAC;QAC1E,OAAO,iBAAiB,CAAC,qBAAqB,CAC1C,IAAI,EACJ,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,WAAW,EAClB,SAAS,EACT,MAAM,CAAC,KAAK,EACZ,OAAwD,CAC3D,CAAC;IACN,CAAC;CACJ;AArGD,gEAqGC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/server.d.ts b/dist/cjs/experimental/tasks/server.d.ts new file mode 100644 index 000000000..185e0bab5 --- /dev/null +++ b/dist/cjs/experimental/tasks/server.d.ts @@ -0,0 +1,83 @@ +/** + * Experimental server task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { Server } from '../../server/index.js'; +import type { RequestOptions } from '../../shared/protocol.js'; +import type { ResponseMessage } from '../../shared/responseMessage.js'; +import type { AnySchema, SchemaOutput } from '../../server/zod-compat.js'; +import type { ServerRequest, Notification, Request, Result, GetTaskResult, ListTasksResult, CancelTaskResult } from '../../types.js'; +/** + * Experimental task features for low-level MCP servers. + * + * Access via `server.experimental.tasks`: + * ```typescript + * const stream = server.experimental.tasks.requestStream(request, schema, options); + * ``` + * + * For high-level server usage with task-based tools, use `McpServer.experimental.tasks` instead. + * + * @experimental + */ +export declare class ExperimentalServerTasks { + private readonly _server; + constructor(_server: Server); + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request: ServerRequest | RequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + getTask(taskId: string, options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + getTaskResult(taskId: string, resultSchema?: T, options?: RequestOptions): Promise>; + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + listTasks(cursor?: string, options?: RequestOptions): Promise; + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + cancelTask(taskId: string, options?: RequestOptions): Promise; +} +//# sourceMappingURL=server.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/server.d.ts.map b/dist/cjs/experimental/tasks/server.d.ts.map new file mode 100644 index 000000000..a1681854f --- /dev/null +++ b/dist/cjs/experimental/tasks/server.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAErI;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAuB,CAChC,QAAQ,SAAS,OAAO,GAAG,OAAO,EAClC,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,OAAO,SAAS,MAAM,GAAG,MAAM;IAEnB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC;IAE9E;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,CAAC,SAAS,SAAS,EAC7B,OAAO,EAAE,aAAa,GAAG,QAAQ,EACjC,YAAY,EAAE,CAAC,EACf,OAAO,CAAC,EAAE,cAAc,GACzB,cAAc,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;IAY/D;;;;;;;;OAQG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAK/E;;;;;;;;;OASG;IACG,aAAa,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAY9H;;;;;;;;OAQG;IACG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAQpF;;;;;;;OAOG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAOxF"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/server.js b/dist/cjs/experimental/tasks/server.js new file mode 100644 index 000000000..200d4b96a --- /dev/null +++ b/dist/cjs/experimental/tasks/server.js @@ -0,0 +1,93 @@ +"use strict"; +/** + * Experimental server task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ExperimentalServerTasks = void 0; +/** + * Experimental task features for low-level MCP servers. + * + * Access via `server.experimental.tasks`: + * ```typescript + * const stream = server.experimental.tasks.requestStream(request, schema, options); + * ``` + * + * For high-level server usage with task-based tools, use `McpServer.experimental.tasks` instead. + * + * @experimental + */ +class ExperimentalServerTasks { + constructor(_server) { + this._server = _server; + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request, resultSchema, options) { + return this._server.requestStream(request, resultSchema, options); + } + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + async getTask(taskId, options) { + return this._server.getTask({ taskId }, options); + } + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + async getTaskResult(taskId, resultSchema, options) { + return this._server.getTaskResult({ taskId }, resultSchema, options); + } + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + async listTasks(cursor, options) { + return this._server.listTasks(cursor ? { cursor } : undefined, options); + } + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + async cancelTask(taskId, options) { + return this._server.cancelTask({ taskId }, options); + } +} +exports.ExperimentalServerTasks = ExperimentalServerTasks; +//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/server.js.map b/dist/cjs/experimental/tasks/server.js.map new file mode 100644 index 000000000..905631d24 --- /dev/null +++ b/dist/cjs/experimental/tasks/server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAQH;;;;;;;;;;;GAWG;AACH,MAAa,uBAAuB;IAKhC,YAA6B,OAAiD;QAAjD,YAAO,GAAP,OAAO,CAA0C;IAAG,CAAC;IAElF;;;;;;;;;;;;;OAaG;IACH,aAAa,CACT,OAAiC,EACjC,YAAe,EACf,OAAwB;QAUxB,OAAQ,IAAI,CAAC,OAA8C,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9G,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,OAAwB;QAElD,OAAQ,IAAI,CAAC,OAAwC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACvF,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,aAAa,CAAsB,MAAc,EAAE,YAAgB,EAAE,OAAwB;QAC/F,OACI,IAAI,CAAC,OAOR,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,CAAC,MAAe,EAAE,OAAwB;QACrD,OACI,IAAI,CAAC,OAGR,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,OAAwB;QACrD,OACI,IAAI,CAAC,OAGR,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ;AAzGD,0DAyGC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/stores/in-memory.d.ts b/dist/cjs/experimental/tasks/stores/in-memory.d.ts new file mode 100644 index 000000000..b2228b578 --- /dev/null +++ b/dist/cjs/experimental/tasks/stores/in-memory.d.ts @@ -0,0 +1,94 @@ +/** + * In-memory implementations of TaskStore and TaskMessageQueue. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import { Task, Request, RequestId, Result } from '../../../types.js'; +import { TaskStore, TaskMessageQueue, QueuedMessage, CreateTaskOptions } from '../interfaces.js'; +/** + * A simple in-memory implementation of TaskStore for demonstration purposes. + * + * This implementation stores all tasks in memory and provides automatic cleanup + * based on the ttl duration specified in the task creation parameters. + * + * Note: This is not suitable for production use as all data is lost on restart. + * For production, consider implementing TaskStore with a database or distributed cache. + * + * @experimental + */ +export declare class InMemoryTaskStore implements TaskStore { + private tasks; + private cleanupTimers; + /** + * Generates a unique task ID. + * Uses 16 bytes of random data encoded as hex (32 characters). + */ + private generateTaskId; + createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, _sessionId?: string): Promise; + getTask(taskId: string, _sessionId?: string): Promise; + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, _sessionId?: string): Promise; + getTaskResult(taskId: string, _sessionId?: string): Promise; + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string, _sessionId?: string): Promise; + listTasks(cursor?: string, _sessionId?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; + /** + * Cleanup all timers (useful for testing or graceful shutdown) + */ + cleanup(): void; + /** + * Get all tasks (useful for debugging) + */ + getAllTasks(): Task[]; +} +/** + * A simple in-memory implementation of TaskMessageQueue for demonstration purposes. + * + * This implementation stores messages in memory, organized by task ID and optional session ID. + * Messages are stored in FIFO queues per task. + * + * Note: This is not suitable for production use in distributed systems. + * For production, consider implementing TaskMessageQueue with Redis or other distributed queues. + * + * @experimental + */ +export declare class InMemoryTaskMessageQueue implements TaskMessageQueue { + private queues; + /** + * Generates a queue key from taskId. + * SessionId is intentionally ignored because taskIds are globally unique + * and tasks need to be accessible across HTTP requests/sessions. + */ + private getQueueKey; + /** + * Gets or creates a queue for the given task and session. + */ + private getQueue; + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + enqueue(taskId: string, message: QueuedMessage, sessionId?: string, maxSize?: number): Promise; + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + dequeue(taskId: string, sessionId?: string): Promise; + /** + * Removes and returns all messages from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + dequeueAll(taskId: string, sessionId?: string): Promise; +} +//# sourceMappingURL=in-memory.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/stores/in-memory.d.ts.map b/dist/cjs/experimental/tasks/stores/in-memory.d.ts.map new file mode 100644 index 000000000..5b8bd7020 --- /dev/null +++ b/dist/cjs/experimental/tasks/stores/in-memory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/tasks/stores/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAc,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAU7G;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IAC/C,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,aAAa,CAAoD;IAEzE;;;OAGG;IACH,OAAO,CAAC,cAAc;IAIhB,UAAU,CAAC,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0CrH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAKlE,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM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F"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/stores/in-memory.js b/dist/cjs/experimental/tasks/stores/in-memory.js new file mode 100644 index 000000000..50b00becc --- /dev/null +++ b/dist/cjs/experimental/tasks/stores/in-memory.js @@ -0,0 +1,253 @@ +"use strict"; +/** + * In-memory implementations of TaskStore and TaskMessageQueue. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemoryTaskMessageQueue = exports.InMemoryTaskStore = void 0; +const interfaces_js_1 = require("../interfaces.js"); +const node_crypto_1 = require("node:crypto"); +/** + * A simple in-memory implementation of TaskStore for demonstration purposes. + * + * This implementation stores all tasks in memory and provides automatic cleanup + * based on the ttl duration specified in the task creation parameters. + * + * Note: This is not suitable for production use as all data is lost on restart. + * For production, consider implementing TaskStore with a database or distributed cache. + * + * @experimental + */ +class InMemoryTaskStore { + constructor() { + this.tasks = new Map(); + this.cleanupTimers = new Map(); + } + /** + * Generates a unique task ID. + * Uses 16 bytes of random data encoded as hex (32 characters). + */ + generateTaskId() { + return (0, node_crypto_1.randomBytes)(16).toString('hex'); + } + async createTask(taskParams, requestId, request, _sessionId) { + var _a, _b; + // Generate a unique task ID + const taskId = this.generateTaskId(); + // Ensure uniqueness + if (this.tasks.has(taskId)) { + throw new Error(`Task with ID ${taskId} already exists`); + } + const actualTtl = (_a = taskParams.ttl) !== null && _a !== void 0 ? _a : null; + // Create task with generated ID and timestamps + const createdAt = new Date().toISOString(); + const task = { + taskId, + status: 'working', + ttl: actualTtl, + createdAt, + lastUpdatedAt: createdAt, + pollInterval: (_b = taskParams.pollInterval) !== null && _b !== void 0 ? _b : 1000 + }; + this.tasks.set(taskId, { + task, + request, + requestId + }); + // Schedule cleanup if ttl is specified + // Cleanup occurs regardless of task status + if (actualTtl) { + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, actualTtl); + this.cleanupTimers.set(taskId, timer); + } + return task; + } + async getTask(taskId, _sessionId) { + const stored = this.tasks.get(taskId); + return stored ? { ...stored.task } : null; + } + async storeTaskResult(taskId, status, result, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + // Don't allow storing results for tasks already in terminal state + if ((0, interfaces_js_1.isTerminal)(stored.task.status)) { + throw new Error(`Cannot store result for task ${taskId} in terminal status '${stored.task.status}'. Task results can only be stored once.`); + } + stored.result = result; + stored.task.status = status; + stored.task.lastUpdatedAt = new Date().toISOString(); + // Reset cleanup timer to start from now (if ttl is set) + if (stored.task.ttl) { + const existingTimer = this.cleanupTimers.get(taskId); + if (existingTimer) { + clearTimeout(existingTimer); + } + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, stored.task.ttl); + this.cleanupTimers.set(taskId, timer); + } + } + async getTaskResult(taskId, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + if (!stored.result) { + throw new Error(`Task ${taskId} has no result stored`); + } + return stored.result; + } + async updateTaskStatus(taskId, status, statusMessage, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + // Don't allow transitions from terminal states + if ((0, interfaces_js_1.isTerminal)(stored.task.status)) { + throw new Error(`Cannot update task ${taskId} from terminal status '${stored.task.status}' to '${status}'. Terminal states (completed, failed, cancelled) cannot transition to other states.`); + } + stored.task.status = status; + if (statusMessage) { + stored.task.statusMessage = statusMessage; + } + stored.task.lastUpdatedAt = new Date().toISOString(); + // If task is in a terminal state and has ttl, start cleanup timer + if ((0, interfaces_js_1.isTerminal)(status) && stored.task.ttl) { + const existingTimer = this.cleanupTimers.get(taskId); + if (existingTimer) { + clearTimeout(existingTimer); + } + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, stored.task.ttl); + this.cleanupTimers.set(taskId, timer); + } + } + async listTasks(cursor, _sessionId) { + const PAGE_SIZE = 10; + const allTaskIds = Array.from(this.tasks.keys()); + let startIndex = 0; + if (cursor) { + const cursorIndex = allTaskIds.indexOf(cursor); + if (cursorIndex >= 0) { + startIndex = cursorIndex + 1; + } + else { + // Invalid cursor - throw error + throw new Error(`Invalid cursor: ${cursor}`); + } + } + const pageTaskIds = allTaskIds.slice(startIndex, startIndex + PAGE_SIZE); + const tasks = pageTaskIds.map(taskId => { + const stored = this.tasks.get(taskId); + return { ...stored.task }; + }); + const nextCursor = startIndex + PAGE_SIZE < allTaskIds.length ? pageTaskIds[pageTaskIds.length - 1] : undefined; + return { tasks, nextCursor }; + } + /** + * Cleanup all timers (useful for testing or graceful shutdown) + */ + cleanup() { + for (const timer of this.cleanupTimers.values()) { + clearTimeout(timer); + } + this.cleanupTimers.clear(); + this.tasks.clear(); + } + /** + * Get all tasks (useful for debugging) + */ + getAllTasks() { + return Array.from(this.tasks.values()).map(stored => ({ ...stored.task })); + } +} +exports.InMemoryTaskStore = InMemoryTaskStore; +/** + * A simple in-memory implementation of TaskMessageQueue for demonstration purposes. + * + * This implementation stores messages in memory, organized by task ID and optional session ID. + * Messages are stored in FIFO queues per task. + * + * Note: This is not suitable for production use in distributed systems. + * For production, consider implementing TaskMessageQueue with Redis or other distributed queues. + * + * @experimental + */ +class InMemoryTaskMessageQueue { + constructor() { + this.queues = new Map(); + } + /** + * Generates a queue key from taskId. + * SessionId is intentionally ignored because taskIds are globally unique + * and tasks need to be accessible across HTTP requests/sessions. + */ + getQueueKey(taskId, _sessionId) { + return taskId; + } + /** + * Gets or creates a queue for the given task and session. + */ + getQueue(taskId, sessionId) { + const key = this.getQueueKey(taskId, sessionId); + let queue = this.queues.get(key); + if (!queue) { + queue = []; + this.queues.set(key, queue); + } + return queue; + } + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + async enqueue(taskId, message, sessionId, maxSize) { + const queue = this.getQueue(taskId, sessionId); + // Atomically check size and enqueue + if (maxSize !== undefined && queue.length >= maxSize) { + throw new Error(`Task message queue overflow: queue size (${queue.length}) exceeds maximum (${maxSize})`); + } + queue.push(message); + } + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + async dequeue(taskId, sessionId) { + const queue = this.getQueue(taskId, sessionId); + return queue.shift(); + } + /** + * Removes and returns all messages from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + async dequeueAll(taskId, sessionId) { + var _a; + const key = this.getQueueKey(taskId, sessionId); + const queue = (_a = this.queues.get(key)) !== null && _a !== void 0 ? _a : []; + this.queues.delete(key); + return queue; + } +} +exports.InMemoryTaskMessageQueue = InMemoryTaskMessageQueue; +//# sourceMappingURL=in-memory.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/stores/in-memory.js.map b/dist/cjs/experimental/tasks/stores/in-memory.js.map new file mode 100644 index 000000000..0ea553552 --- /dev/null +++ b/dist/cjs/experimental/tasks/stores/in-memory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"in-memory.js","sourceRoot":"","sources":["../../../../../src/experimental/tasks/stores/in-memory.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,oDAA6G;AAC7G,6CAA0C;AAS1C;;;;;;;;;;GAUG;AACH,MAAa,iBAAiB;IAA9B;QACY,UAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;QACtC,kBAAa,GAAG,IAAI,GAAG,EAAyC,CAAC;IAsL7E,CAAC;IApLG;;;OAGG;IACK,cAAc;QAClB,OAAO,IAAA,yBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC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AAK,CAAC;IACjB,CAAC;CACJ;AApED,4DAoEC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/types.d.ts b/dist/cjs/experimental/tasks/types.d.ts new file mode 100644 index 000000000..6022e19b2 --- /dev/null +++ b/dist/cjs/experimental/tasks/types.d.ts @@ -0,0 +1,10 @@ +/** + * Re-exports of task-related types from the MCP protocol spec. + * WARNING: These APIs are experimental and may change without notice. + * + * These types are defined in types.ts (matching the protocol spec) and + * re-exported here for convenience when working with experimental task features. + */ +export { TaskCreationParamsSchema, RelatedTaskMetadataSchema, TaskSchema, CreateTaskResultSchema, TaskStatusNotificationParamsSchema, TaskStatusNotificationSchema, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, ClientTasksCapabilitySchema, ServerTasksCapabilitySchema } from '../../types.js'; +export type { Task, TaskCreationParams, RelatedTaskMetadata, CreateTaskResult, TaskStatusNotificationParams, TaskStatusNotification, GetTaskRequest, GetTaskResult, GetTaskPayloadRequest, ListTasksRequest, ListTasksResult, CancelTaskRequest, CancelTaskResult } from '../../types.js'; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/types.d.ts.map b/dist/cjs/experimental/tasks/types.d.ts.map new file mode 100644 index 000000000..f7b9ead05 --- /dev/null +++ b/dist/cjs/experimental/tasks/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACtB,kCAAkC,EAClC,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC9B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACR,IAAI,EACJ,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACnB,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/types.js b/dist/cjs/experimental/tasks/types.js new file mode 100644 index 000000000..b051c848b --- /dev/null +++ b/dist/cjs/experimental/tasks/types.js @@ -0,0 +1,28 @@ +"use strict"; +/** + * Re-exports of task-related types from the MCP protocol spec. + * WARNING: These APIs are experimental and may change without notice. + * + * These types are defined in types.ts (matching the protocol spec) and + * re-exported here for convenience when working with experimental task features. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ServerTasksCapabilitySchema = exports.ClientTasksCapabilitySchema = exports.CancelTaskResultSchema = exports.CancelTaskRequestSchema = exports.ListTasksResultSchema = exports.ListTasksRequestSchema = exports.GetTaskPayloadRequestSchema = exports.GetTaskResultSchema = exports.GetTaskRequestSchema = exports.TaskStatusNotificationSchema = exports.TaskStatusNotificationParamsSchema = exports.CreateTaskResultSchema = exports.TaskSchema = exports.RelatedTaskMetadataSchema = exports.TaskCreationParamsSchema = void 0; +// Task schemas (Zod) +var types_js_1 = require("../../types.js"); +Object.defineProperty(exports, "TaskCreationParamsSchema", { enumerable: true, get: function () { return types_js_1.TaskCreationParamsSchema; } }); +Object.defineProperty(exports, "RelatedTaskMetadataSchema", { enumerable: true, get: function () { return types_js_1.RelatedTaskMetadataSchema; } }); +Object.defineProperty(exports, "TaskSchema", { enumerable: true, get: function () { return types_js_1.TaskSchema; } }); +Object.defineProperty(exports, "CreateTaskResultSchema", { enumerable: true, get: function () { return types_js_1.CreateTaskResultSchema; } }); +Object.defineProperty(exports, "TaskStatusNotificationParamsSchema", { enumerable: true, get: function () { return types_js_1.TaskStatusNotificationParamsSchema; } }); +Object.defineProperty(exports, "TaskStatusNotificationSchema", { enumerable: true, get: function () { return types_js_1.TaskStatusNotificationSchema; } }); +Object.defineProperty(exports, "GetTaskRequestSchema", { enumerable: true, get: function () { return types_js_1.GetTaskRequestSchema; } }); +Object.defineProperty(exports, "GetTaskResultSchema", { enumerable: true, get: function () { return types_js_1.GetTaskResultSchema; } }); +Object.defineProperty(exports, "GetTaskPayloadRequestSchema", { enumerable: true, get: function () { return types_js_1.GetTaskPayloadRequestSchema; } }); +Object.defineProperty(exports, "ListTasksRequestSchema", { enumerable: true, get: function () { return types_js_1.ListTasksRequestSchema; } }); +Object.defineProperty(exports, "ListTasksResultSchema", { enumerable: true, get: function () { return types_js_1.ListTasksResultSchema; } }); +Object.defineProperty(exports, "CancelTaskRequestSchema", { enumerable: true, get: function () { return types_js_1.CancelTaskRequestSchema; } }); +Object.defineProperty(exports, "CancelTaskResultSchema", { enumerable: true, get: function () { return types_js_1.CancelTaskResultSchema; } }); +Object.defineProperty(exports, "ClientTasksCapabilitySchema", { enumerable: true, get: function () { return types_js_1.ClientTasksCapabilitySchema; } }); +Object.defineProperty(exports, "ServerTasksCapabilitySchema", { enumerable: true, get: function () { return types_js_1.ServerTasksCapabilitySchema; } }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/cjs/experimental/tasks/types.js.map b/dist/cjs/experimental/tasks/types.js.map new file mode 100644 index 000000000..adfc3ab50 --- /dev/null +++ b/dist/cjs/experimental/tasks/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,qBAAqB;AACrB,2CAgBwB;AAfpB,oHAAA,wBAAwB,OAAA;AACxB,qHAAA,yBAAyB,OAAA;AACzB,sGAAA,UAAU,OAAA;AACV,kHAAA,sBAAsB,OAAA;AACtB,8HAAA,kCAAkC,OAAA;AAClC,wHAAA,4BAA4B,OAAA;AAC5B,gHAAA,oBAAoB,OAAA;AACpB,+GAAA,mBAAmB,OAAA;AACnB,uHAAA,2BAA2B,OAAA;AAC3B,kHAAA,sBAAsB,OAAA;AACtB,iHAAA,qBAAqB,OAAA;AACrB,mHAAA,uBAAuB,OAAA;AACvB,kHAAA,sBAAsB,OAAA;AACtB,uHAAA,2BAA2B,OAAA;AAC3B,uHAAA,2BAA2B,OAAA"} \ No newline at end of file diff --git a/dist/cjs/inMemory.d.ts b/dist/cjs/inMemory.d.ts new file mode 100644 index 000000000..32a931a86 --- /dev/null +++ b/dist/cjs/inMemory.d.ts @@ -0,0 +1,31 @@ +import { Transport } from './shared/transport.js'; +import { JSONRPCMessage, RequestId } from './types.js'; +import { AuthInfo } from './server/auth/types.js'; +/** + * In-memory transport for creating clients and servers that talk to each other within the same process. + */ +export declare class InMemoryTransport implements Transport { + private _otherTransport?; + private _messageQueue; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: { + authInfo?: AuthInfo; + }) => void; + sessionId?: string; + /** + * Creates a pair of linked in-memory transports that can communicate with each other. One should be passed to a Client and one to a Server. + */ + static createLinkedPair(): [InMemoryTransport, InMemoryTransport]; + start(): Promise; + close(): Promise; + /** + * Sends a message with optional auth info. + * This is useful for testing authentication scenarios. + */ + send(message: JSONRPCMessage, options?: { + relatedRequestId?: RequestId; + authInfo?: AuthInfo; + }): Promise; +} +//# sourceMappingURL=inMemory.d.ts.map \ No newline at end of file diff --git a/dist/cjs/inMemory.d.ts.map b/dist/cjs/inMemory.d.ts.map new file mode 100644 index 000000000..46bc74be1 --- /dev/null +++ b/dist/cjs/inMemory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemory.d.ts","sourceRoot":"","sources":["../../src/inMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAOlD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IAC/C,OAAO,CAAC,eAAe,CAAC,CAAoB;IAC5C,OAAO,CAAC,aAAa,CAAuB;IAE5C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,gBAAgB,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAQ3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;;OAGG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAWtH"} \ No newline at end of file diff --git a/dist/cjs/inMemory.js b/dist/cjs/inMemory.js new file mode 100644 index 000000000..3070d8391 --- /dev/null +++ b/dist/cjs/inMemory.js @@ -0,0 +1,53 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemoryTransport = void 0; +/** + * In-memory transport for creating clients and servers that talk to each other within the same process. + */ +class InMemoryTransport { + constructor() { + this._messageQueue = []; + } + /** + * Creates a pair of linked in-memory transports that can communicate with each other. One should be passed to a Client and one to a Server. + */ + static createLinkedPair() { + const clientTransport = new InMemoryTransport(); + const serverTransport = new InMemoryTransport(); + clientTransport._otherTransport = serverTransport; + serverTransport._otherTransport = clientTransport; + return [clientTransport, serverTransport]; + } + async start() { + var _a; + // Process any messages that were queued before start was called + while (this._messageQueue.length > 0) { + const queuedMessage = this._messageQueue.shift(); + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, queuedMessage.message, queuedMessage.extra); + } + } + async close() { + var _a; + const other = this._otherTransport; + this._otherTransport = undefined; + await (other === null || other === void 0 ? void 0 : other.close()); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + /** + * Sends a message with optional auth info. + * This is useful for testing authentication scenarios. + */ + async send(message, options) { + if (!this._otherTransport) { + throw new Error('Not connected'); + } + if (this._otherTransport.onmessage) { + this._otherTransport.onmessage(message, { authInfo: options === null || options === void 0 ? void 0 : options.authInfo }); + } + else { + this._otherTransport._messageQueue.push({ message, extra: { authInfo: options === null || options === void 0 ? void 0 : options.authInfo } }); + } + } +} +exports.InMemoryTransport = InMemoryTransport; +//# sourceMappingURL=inMemory.js.map \ No newline at end of file diff --git a/dist/cjs/inMemory.js.map b/dist/cjs/inMemory.js.map new file mode 100644 index 000000000..869a51f61 --- /dev/null +++ b/dist/cjs/inMemory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemory.js","sourceRoot":"","sources":["../../src/inMemory.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QAEY,kBAAa,GAAoB,EAAE,CAAC;IAgDhD,CAAC;IAzCG;;OAEG;IACH,MAAM,CAAC,gBAAgB;QACnB,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAChD,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAChD,eAAe,CAAC,eAAe,GAAG,eAAe,CAAC;QAClD,eAAe,CAAC,eAAe,GAAG,eAAe,CAAC;QAClD,OAAO,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,gEAAgE;QAChE,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAG,CAAC;YAClD,MAAA,IAAI,CAAC,SAAS,qDAAG,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,MAAM,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,EAAE,CAAA,CAAC;QACrB,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB,EAAE,OAA+D;QAC/F,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACjG,CAAC;IACL,CAAC;CACJ;AAlDD,8CAkDC"} \ No newline at end of file diff --git a/dist/cjs/package.json b/dist/cjs/package.json new file mode 100644 index 000000000..b731bd61b --- /dev/null +++ b/dist/cjs/package.json @@ -0,0 +1 @@ +{"type": "commonjs"} diff --git a/dist/cjs/server/auth/clients.d.ts b/dist/cjs/server/auth/clients.d.ts new file mode 100644 index 000000000..be6899a19 --- /dev/null +++ b/dist/cjs/server/auth/clients.d.ts @@ -0,0 +1,19 @@ +import { OAuthClientInformationFull } from '../../shared/auth.js'; +/** + * Stores information about registered OAuth clients for this server. + */ +export interface OAuthRegisteredClientsStore { + /** + * Returns information about a registered client, based on its ID. + */ + getClient(clientId: string): OAuthClientInformationFull | undefined | Promise; + /** + * Registers a new client with the server. The client ID and secret will be automatically generated by the library. A modified version of the client information can be returned to reflect specific values enforced by the server. + * + * NOTE: Implementations should NOT delete expired client secrets in-place. Auth middleware provided by this library will automatically check the `client_secret_expires_at` field and reject requests with expired secrets. Any custom logic for authenticating clients should check the `client_secret_expires_at` field as well. + * + * If unimplemented, dynamic client registration is unsupported. + */ + registerClient?(client: Omit): OAuthClientInformationFull | Promise; +} +//# sourceMappingURL=clients.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/clients.d.ts.map b/dist/cjs/server/auth/clients.d.ts.map new file mode 100644 index 000000000..ab3851db3 --- /dev/null +++ b/dist/cjs/server/auth/clients.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IACxC;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,GAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAAC;IAEtH;;;;;;OAMG;IACH,cAAc,CAAC,CACX,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,WAAW,GAAG,qBAAqB,CAAC,GAC9E,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;CACvE"} \ No newline at end of file diff --git a/dist/cjs/server/auth/clients.js b/dist/cjs/server/auth/clients.js new file mode 100644 index 000000000..866b88b74 --- /dev/null +++ b/dist/cjs/server/auth/clients.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=clients.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/clients.js.map b/dist/cjs/server/auth/clients.js.map new file mode 100644 index 000000000..021010442 --- /dev/null +++ b/dist/cjs/server/auth/clients.js.map @@ -0,0 +1 @@ +{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/server/auth/clients.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/server/auth/errors.d.ts b/dist/cjs/server/auth/errors.d.ts new file mode 100644 index 000000000..7fddf954c --- /dev/null +++ b/dist/cjs/server/auth/errors.d.ts @@ -0,0 +1,148 @@ +import { OAuthErrorResponse } from '../../shared/auth.js'; +/** + * Base class for all OAuth errors + */ +export declare class OAuthError extends Error { + readonly errorUri?: string | undefined; + static errorCode: string; + constructor(message: string, errorUri?: string | undefined); + /** + * Converts the error to a standard OAuth error response object + */ + toResponseObject(): OAuthErrorResponse; + get errorCode(): string; +} +/** + * Invalid request error - The request is missing a required parameter, + * includes an invalid parameter value, includes a parameter more than once, + * or is otherwise malformed. + */ +export declare class InvalidRequestError extends OAuthError { + static errorCode: string; +} +/** + * Invalid client error - Client authentication failed (e.g., unknown client, no client + * authentication included, or unsupported authentication method). + */ +export declare class InvalidClientError extends OAuthError { + static errorCode: string; +} +/** + * Invalid grant error - The provided authorization grant or refresh token is + * invalid, expired, revoked, does not match the redirection URI used in the + * authorization request, or was issued to another client. + */ +export declare class InvalidGrantError extends OAuthError { + static errorCode: string; +} +/** + * Unauthorized client error - The authenticated client is not authorized to use + * this authorization grant type. + */ +export declare class UnauthorizedClientError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported grant type error - The authorization grant type is not supported + * by the authorization server. + */ +export declare class UnsupportedGrantTypeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid scope error - The requested scope is invalid, unknown, malformed, or + * exceeds the scope granted by the resource owner. + */ +export declare class InvalidScopeError extends OAuthError { + static errorCode: string; +} +/** + * Access denied error - The resource owner or authorization server denied the request. + */ +export declare class AccessDeniedError extends OAuthError { + static errorCode: string; +} +/** + * Server error - The authorization server encountered an unexpected condition + * that prevented it from fulfilling the request. + */ +export declare class ServerError extends OAuthError { + static errorCode: string; +} +/** + * Temporarily unavailable error - The authorization server is currently unable to + * handle the request due to a temporary overloading or maintenance of the server. + */ +export declare class TemporarilyUnavailableError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported response type error - The authorization server does not support + * obtaining an authorization code using this method. + */ +export declare class UnsupportedResponseTypeError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported token type error - The authorization server does not support + * the requested token type. + */ +export declare class UnsupportedTokenTypeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid token error - The access token provided is expired, revoked, malformed, + * or invalid for other reasons. + */ +export declare class InvalidTokenError extends OAuthError { + static errorCode: string; +} +/** + * Method not allowed error - The HTTP method used is not allowed for this endpoint. + * (Custom, non-standard error) + */ +export declare class MethodNotAllowedError extends OAuthError { + static errorCode: string; +} +/** + * Too many requests error - Rate limit exceeded. + * (Custom, non-standard error based on RFC 6585) + */ +export declare class TooManyRequestsError extends OAuthError { + static errorCode: string; +} +/** + * Invalid client metadata error - The client metadata is invalid. + * (Custom error for dynamic client registration - RFC 7591) + */ +export declare class InvalidClientMetadataError extends OAuthError { + static errorCode: string; +} +/** + * Insufficient scope error - The request requires higher privileges than provided by the access token. + */ +export declare class InsufficientScopeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid target error - The requested resource is invalid, missing, unknown, or malformed. + * (Custom error for resource indicators - RFC 8707) + */ +export declare class InvalidTargetError extends OAuthError { + static errorCode: string; +} +/** + * A utility class for defining one-off error codes + */ +export declare class CustomOAuthError extends OAuthError { + private readonly customErrorCode; + constructor(customErrorCode: string, message: string, errorUri?: string); + get errorCode(): string; +} +/** + * A full list of all OAuthErrors, enabling parsing from error responses + */ +export declare const OAUTH_ERRORS: { + readonly [x: string]: typeof InvalidRequestError; +}; +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/errors.d.ts.map b/dist/cjs/server/auth/errors.d.ts.map new file mode 100644 index 000000000..5c0e99202 --- /dev/null +++ b/dist/cjs/server/auth/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;aAKb,QAAQ,CAAC,EAAE,MAAM;IAJrC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACC,QAAQ,CAAC,EAAE,MAAM,YAAA;IAMrC;;OAEG;IACH,gBAAgB,IAAI,kBAAkB;IAatC,IAAI,SAAS,IAAI,MAAM,CAEtB;CACJ;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;IAC/C,MAAM,CAAC,SAAS,SAAqB;CACxC;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAC9C,MAAM,CAAC,SAAS,SAAoB;CACvC;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC7C,MAAM,CAAC,SAAS,SAAmB;CACtC;AAED;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IACnD,MAAM,CAAC,SAAS,SAAyB;CAC5C;AAED;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,UAAU;IACrD,MAAM,CAAC,SAAS,SAA4B;CAC/C;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC7C,MAAM,CAAC,SAAS,SAAmB;CACtC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC7C,MAAM,CAAC,SAAS,SAAmB;CACtC;AAED;;;GAGG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACvC,MAAM,CAAC,SAAS,SAAkB;CACrC;AAED;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,UAAU;IACvD,MAAM,CAAC,SAAS,SAA6B;CAChD;AAED;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,UAAU;IACxD,MAAM,CAAC,SAAS,SAA+B;CAClD;AAED;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,UAAU;IACrD,MAAM,CAAC,SAAS,SAA4B;CAC/C;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC7C,MAAM,CAAC,SAAS,SAAmB;CACtC;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,UAAU;IACjD,MAAM,CAAC,SAAS,SAAwB;CAC3C;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IAChD,MAAM,CAAC,SAAS,SAAuB;CAC1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;IACtD,MAAM,CAAC,SAAS,SAA6B;CAChD;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,MAAM,CAAC,SAAS,SAAwB;CAC3C;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAC9C,MAAM,CAAC,SAAS,SAAoB;CACvC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAExC,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,MAAM,EACxC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM;IAKrB,IAAI,SAAS,IAAI,MAAM,CAEtB;CACJ;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;CAkBf,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/errors.js b/dist/cjs/server/auth/errors.js new file mode 100644 index 000000000..e67478c3c --- /dev/null +++ b/dist/cjs/server/auth/errors.js @@ -0,0 +1,202 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OAUTH_ERRORS = exports.CustomOAuthError = exports.InvalidTargetError = exports.InsufficientScopeError = exports.InvalidClientMetadataError = exports.TooManyRequestsError = exports.MethodNotAllowedError = exports.InvalidTokenError = exports.UnsupportedTokenTypeError = exports.UnsupportedResponseTypeError = exports.TemporarilyUnavailableError = exports.ServerError = exports.AccessDeniedError = exports.InvalidScopeError = exports.UnsupportedGrantTypeError = exports.UnauthorizedClientError = exports.InvalidGrantError = exports.InvalidClientError = exports.InvalidRequestError = exports.OAuthError = void 0; +/** + * Base class for all OAuth errors + */ +class OAuthError extends Error { + constructor(message, errorUri) { + super(message); + this.errorUri = errorUri; + this.name = this.constructor.name; + } + /** + * Converts the error to a standard OAuth error response object + */ + toResponseObject() { + const response = { + error: this.errorCode, + error_description: this.message + }; + if (this.errorUri) { + response.error_uri = this.errorUri; + } + return response; + } + get errorCode() { + return this.constructor.errorCode; + } +} +exports.OAuthError = OAuthError; +/** + * Invalid request error - The request is missing a required parameter, + * includes an invalid parameter value, includes a parameter more than once, + * or is otherwise malformed. + */ +class InvalidRequestError extends OAuthError { +} +exports.InvalidRequestError = InvalidRequestError; +InvalidRequestError.errorCode = 'invalid_request'; +/** + * Invalid client error - Client authentication failed (e.g., unknown client, no client + * authentication included, or unsupported authentication method). + */ +class InvalidClientError extends OAuthError { +} +exports.InvalidClientError = InvalidClientError; +InvalidClientError.errorCode = 'invalid_client'; +/** + * Invalid grant error - The provided authorization grant or refresh token is + * invalid, expired, revoked, does not match the redirection URI used in the + * authorization request, or was issued to another client. + */ +class InvalidGrantError extends OAuthError { +} +exports.InvalidGrantError = InvalidGrantError; +InvalidGrantError.errorCode = 'invalid_grant'; +/** + * Unauthorized client error - The authenticated client is not authorized to use + * this authorization grant type. + */ +class UnauthorizedClientError extends OAuthError { +} +exports.UnauthorizedClientError = UnauthorizedClientError; +UnauthorizedClientError.errorCode = 'unauthorized_client'; +/** + * Unsupported grant type error - The authorization grant type is not supported + * by the authorization server. + */ +class UnsupportedGrantTypeError extends OAuthError { +} +exports.UnsupportedGrantTypeError = UnsupportedGrantTypeError; +UnsupportedGrantTypeError.errorCode = 'unsupported_grant_type'; +/** + * Invalid scope error - The requested scope is invalid, unknown, malformed, or + * exceeds the scope granted by the resource owner. + */ +class InvalidScopeError extends OAuthError { +} +exports.InvalidScopeError = InvalidScopeError; +InvalidScopeError.errorCode = 'invalid_scope'; +/** + * Access denied error - The resource owner or authorization server denied the request. + */ +class AccessDeniedError extends OAuthError { +} +exports.AccessDeniedError = AccessDeniedError; +AccessDeniedError.errorCode = 'access_denied'; +/** + * Server error - The authorization server encountered an unexpected condition + * that prevented it from fulfilling the request. + */ +class ServerError extends OAuthError { +} +exports.ServerError = ServerError; +ServerError.errorCode = 'server_error'; +/** + * Temporarily unavailable error - The authorization server is currently unable to + * handle the request due to a temporary overloading or maintenance of the server. + */ +class TemporarilyUnavailableError extends OAuthError { +} +exports.TemporarilyUnavailableError = TemporarilyUnavailableError; +TemporarilyUnavailableError.errorCode = 'temporarily_unavailable'; +/** + * Unsupported response type error - The authorization server does not support + * obtaining an authorization code using this method. + */ +class UnsupportedResponseTypeError extends OAuthError { +} +exports.UnsupportedResponseTypeError = UnsupportedResponseTypeError; +UnsupportedResponseTypeError.errorCode = 'unsupported_response_type'; +/** + * Unsupported token type error - The authorization server does not support + * the requested token type. + */ +class UnsupportedTokenTypeError extends OAuthError { +} +exports.UnsupportedTokenTypeError = UnsupportedTokenTypeError; +UnsupportedTokenTypeError.errorCode = 'unsupported_token_type'; +/** + * Invalid token error - The access token provided is expired, revoked, malformed, + * or invalid for other reasons. + */ +class InvalidTokenError extends OAuthError { +} +exports.InvalidTokenError = InvalidTokenError; +InvalidTokenError.errorCode = 'invalid_token'; +/** + * Method not allowed error - The HTTP method used is not allowed for this endpoint. + * (Custom, non-standard error) + */ +class MethodNotAllowedError extends OAuthError { +} +exports.MethodNotAllowedError = MethodNotAllowedError; +MethodNotAllowedError.errorCode = 'method_not_allowed'; +/** + * Too many requests error - Rate limit exceeded. + * (Custom, non-standard error based on RFC 6585) + */ +class TooManyRequestsError extends OAuthError { +} +exports.TooManyRequestsError = TooManyRequestsError; +TooManyRequestsError.errorCode = 'too_many_requests'; +/** + * Invalid client metadata error - The client metadata is invalid. + * (Custom error for dynamic client registration - RFC 7591) + */ +class InvalidClientMetadataError extends OAuthError { +} +exports.InvalidClientMetadataError = InvalidClientMetadataError; +InvalidClientMetadataError.errorCode = 'invalid_client_metadata'; +/** + * Insufficient scope error - The request requires higher privileges than provided by the access token. + */ +class InsufficientScopeError extends OAuthError { +} +exports.InsufficientScopeError = InsufficientScopeError; +InsufficientScopeError.errorCode = 'insufficient_scope'; +/** + * Invalid target error - The requested resource is invalid, missing, unknown, or malformed. + * (Custom error for resource indicators - RFC 8707) + */ +class InvalidTargetError extends OAuthError { +} +exports.InvalidTargetError = InvalidTargetError; +InvalidTargetError.errorCode = 'invalid_target'; +/** + * A utility class for defining one-off error codes + */ +class CustomOAuthError extends OAuthError { + constructor(customErrorCode, message, errorUri) { + super(message, errorUri); + this.customErrorCode = customErrorCode; + } + get errorCode() { + return this.customErrorCode; + } +} +exports.CustomOAuthError = CustomOAuthError; +/** + * A full list of all OAuthErrors, enabling parsing from error responses + */ +exports.OAUTH_ERRORS = { + [InvalidRequestError.errorCode]: InvalidRequestError, + [InvalidClientError.errorCode]: InvalidClientError, + [InvalidGrantError.errorCode]: InvalidGrantError, + [UnauthorizedClientError.errorCode]: UnauthorizedClientError, + [UnsupportedGrantTypeError.errorCode]: UnsupportedGrantTypeError, + [InvalidScopeError.errorCode]: InvalidScopeError, + [AccessDeniedError.errorCode]: AccessDeniedError, + [ServerError.errorCode]: ServerError, + [TemporarilyUnavailableError.errorCode]: TemporarilyUnavailableError, + [UnsupportedResponseTypeError.errorCode]: UnsupportedResponseTypeError, + [UnsupportedTokenTypeError.errorCode]: UnsupportedTokenTypeError, + [InvalidTokenError.errorCode]: InvalidTokenError, + [MethodNotAllowedError.errorCode]: MethodNotAllowedError, + [TooManyRequestsError.errorCode]: TooManyRequestsError, + [InvalidClientMetadataError.errorCode]: InvalidClientMetadataError, + [InsufficientScopeError.errorCode]: InsufficientScopeError, + [InvalidTargetError.errorCode]: InvalidTargetError +}; +//# sourceMappingURL=errors.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/errors.js.map b/dist/cjs/server/auth/errors.js.map new file mode 100644 index 000000000..f802594f8 --- /dev/null +++ b/dist/cjs/server/auth/errors.js.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/server/auth/errors.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK;IAGjC,YACI,OAAe,EACC,QAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAS;QAGjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,MAAM,QAAQ,GAAuB;YACjC,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,iBAAiB,EAAE,IAAI,CAAC,OAAO;SAClC,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QACvC,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,IAAI,SAAS;QACT,OAAQ,IAAI,CAAC,WAAiC,CAAC,SAAS,CAAC;IAC7D,CAAC;CACJ;AA9BD,gCA8BC;AAED;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,UAAU;;AAAnD,kDAEC;AADU,6BAAS,GAAG,iBAAiB,CAAC;AAGzC;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,UAAU;;AAAlD,gDAEC;AADU,4BAAS,GAAG,gBAAgB,CAAC;AAGxC;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,UAAU;;AAAjD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;IAClE,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,sBAAsB;IAC1D,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,kBAAkB;CAC5C,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/authorize.d.ts b/dist/cjs/server/auth/handlers/authorize.d.ts new file mode 100644 index 000000000..38e9829bd --- /dev/null +++ b/dist/cjs/server/auth/handlers/authorize.d.ts @@ -0,0 +1,13 @@ +import { RequestHandler } from 'express'; +import { OAuthServerProvider } from '../provider.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type AuthorizationHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the authorization endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function authorizationHandler({ provider, rateLimit: rateLimitConfig }: AuthorizationHandlerOptions): RequestHandler; +//# sourceMappingURL=authorize.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/authorize.d.ts.map b/dist/cjs/server/auth/handlers/authorize.d.ts.map new file mode 100644 index 000000000..b06798834 --- /dev/null +++ b/dist/cjs/server/auth/handlers/authorize.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,2BAA2B,GAAG;IACtC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAqBF,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,2BAA2B,GAAG,cAAc,CAgH1H"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/authorize.js b/dist/cjs/server/auth/handlers/authorize.js new file mode 100644 index 000000000..902208219 --- /dev/null +++ b/dist/cjs/server/auth/handlers/authorize.js @@ -0,0 +1,167 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.authorizationHandler = authorizationHandler; +const z = __importStar(require("zod/v4")); +const express_1 = __importDefault(require("express")); +const express_rate_limit_1 = require("express-rate-limit"); +const allowedMethods_js_1 = require("../middleware/allowedMethods.js"); +const errors_js_1 = require("../errors.js"); +// Parameters that must be validated in order to issue redirects. +const ClientAuthorizationParamsSchema = z.object({ + client_id: z.string(), + redirect_uri: z + .string() + .optional() + .refine(value => value === undefined || URL.canParse(value), { message: 'redirect_uri must be a valid URL' }) +}); +// Parameters that must be validated for a successful authorization request. Failure can be reported to the redirect URI. +const RequestAuthorizationParamsSchema = z.object({ + response_type: z.literal('code'), + code_challenge: z.string(), + code_challenge_method: z.literal('S256'), + scope: z.string().optional(), + state: z.string().optional(), + resource: z.string().url().optional() +}); +function authorizationHandler({ provider, rateLimit: rateLimitConfig }) { + // Create a router to apply middleware + const router = express_1.default.Router(); + router.use((0, allowedMethods_js_1.allowedMethods)(['GET', 'POST'])); + router.use(express_1.default.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use((0, express_rate_limit_1.rateLimit)({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // 100 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for authorization requests').toResponseObject(), + ...rateLimitConfig + })); + } + router.all('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + // In the authorization flow, errors are split into two categories: + // 1. Pre-redirect errors (direct response with 400) + // 2. Post-redirect errors (redirect with error parameters) + // Phase 1: Validate client_id and redirect_uri. Any errors here must be direct responses. + let client_id, redirect_uri, client; + try { + const result = ClientAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query); + if (!result.success) { + throw new errors_js_1.InvalidRequestError(result.error.message); + } + client_id = result.data.client_id; + redirect_uri = result.data.redirect_uri; + client = await provider.clientsStore.getClient(client_id); + if (!client) { + throw new errors_js_1.InvalidClientError('Invalid client_id'); + } + if (redirect_uri !== undefined) { + if (!client.redirect_uris.includes(redirect_uri)) { + throw new errors_js_1.InvalidRequestError('Unregistered redirect_uri'); + } + } + else if (client.redirect_uris.length === 1) { + redirect_uri = client.redirect_uris[0]; + } + else { + throw new errors_js_1.InvalidRequestError('redirect_uri must be specified when client has multiple registered URIs'); + } + } + catch (error) { + // Pre-redirect errors - return direct response + // + // These don't need to be JSON encoded, as they'll be displayed in a user + // agent, but OTOH they all represent exceptional situations (arguably, + // "programmer error"), so presenting a nice HTML page doesn't help the + // user anyway. + if (error instanceof errors_js_1.OAuthError) { + const status = error instanceof errors_js_1.ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + return; + } + // Phase 2: Validate other parameters. Any errors here should go into redirect responses. + let state; + try { + // Parse and validate authorization parameters + const parseResult = RequestAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query); + if (!parseResult.success) { + throw new errors_js_1.InvalidRequestError(parseResult.error.message); + } + const { scope, code_challenge, resource } = parseResult.data; + state = parseResult.data.state; + // Validate scopes + let requestedScopes = []; + if (scope !== undefined) { + requestedScopes = scope.split(' '); + } + // All validation passed, proceed with authorization + await provider.authorize(client, { + state, + scopes: requestedScopes, + redirectUri: redirect_uri, + codeChallenge: code_challenge, + resource: resource ? new URL(resource) : undefined + }, res); + } + catch (error) { + // Post-redirect errors - redirect with error parameters + if (error instanceof errors_js_1.OAuthError) { + res.redirect(302, createErrorRedirect(redirect_uri, error, state)); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.redirect(302, createErrorRedirect(redirect_uri, serverError, state)); + } + } + }); + return router; +} +/** + * Helper function to create redirect URL with error parameters + */ +function createErrorRedirect(redirectUri, error, state) { + const errorUrl = new URL(redirectUri); + errorUrl.searchParams.set('error', error.errorCode); + errorUrl.searchParams.set('error_description', error.message); + if (error.errorUri) { + errorUrl.searchParams.set('error_uri', error.errorUri); + } + if (state) { + errorUrl.searchParams.set('state', state); + } + return errorUrl.href; +} +//# sourceMappingURL=authorize.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/authorize.js.map b/dist/cjs/server/auth/handlers/authorize.js.map new file mode 100644 index 000000000..28e876271 --- /dev/null +++ b/dist/cjs/server/auth/handlers/authorize.js.map @@ -0,0 +1 @@ +{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,oDAgHC;AAnJD,0CAA4B;AAC5B,sDAA8B;AAE9B,2DAA4E;AAC5E,uEA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,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACtC,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,EAAE,CAAC;QACR,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/metadata.d.ts b/dist/cjs/server/auth/handlers/metadata.d.ts new file mode 100644 index 000000000..4d0328617 --- /dev/null +++ b/dist/cjs/server/auth/handlers/metadata.d.ts @@ -0,0 +1,4 @@ +import { RequestHandler } from 'express'; +import { OAuthMetadata, OAuthProtectedResourceMetadata } from '../../../shared/auth.js'; +export declare function metadataHandler(metadata: OAuthMetadata | OAuthProtectedResourceMetadata): RequestHandler; +//# sourceMappingURL=metadata.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/metadata.d.ts.map b/dist/cjs/server/auth/handlers/metadata.d.ts.map new file mode 100644 index 000000000..55e3a50dc --- /dev/null +++ b/dist/cjs/server/auth/handlers/metadata.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAIxF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,aAAa,GAAG,8BAA8B,GAAG,cAAc,CAaxG"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/metadata.js b/dist/cjs/server/auth/handlers/metadata.js new file mode 100644 index 000000000..4e00bc588 --- /dev/null +++ b/dist/cjs/server/auth/handlers/metadata.js @@ -0,0 +1,21 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.metadataHandler = metadataHandler; +const express_1 = __importDefault(require("express")); +const cors_1 = __importDefault(require("cors")); +const allowedMethods_js_1 = require("../middleware/allowedMethods.js"); +function metadataHandler(metadata) { + // Nested router so we can configure middleware and restrict HTTP method + const router = express_1.default.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use((0, cors_1.default)()); + router.use((0, allowedMethods_js_1.allowedMethods)(['GET', 'OPTIONS'])); + router.get('/', (req, res) => { + res.status(200).json(metadata); + }); + return router; +} +//# sourceMappingURL=metadata.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/metadata.js.map b/dist/cjs/server/auth/handlers/metadata.js.map new file mode 100644 index 000000000..9679c9fa5 --- /dev/null +++ b/dist/cjs/server/auth/handlers/metadata.js.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":";;;;;AAKA,0CAaC;AAlBD,sDAAkD;AAElD,gDAAwB;AACxB,uEAAiE;AAEjE,SAAgB,eAAe,CAAC,QAAwD;IACpF,wEAAwE;IACxE,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;IAClF,MAAM,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,IAAA,kCAAc,EAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/register.d.ts b/dist/cjs/server/auth/handlers/register.d.ts new file mode 100644 index 000000000..e9add2845 --- /dev/null +++ b/dist/cjs/server/auth/handlers/register.d.ts @@ -0,0 +1,29 @@ +import { RequestHandler } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type ClientRegistrationHandlerOptions = { + /** + * A store used to save information about dynamically registered OAuth clients. + */ + clientsStore: OAuthRegisteredClientsStore; + /** + * The number of seconds after which to expire issued client secrets, or 0 to prevent expiration of client secrets (not recommended). + * + * If not set, defaults to 30 days. + */ + clientSecretExpirySeconds?: number; + /** + * Rate limiting configuration for the client registration endpoint. + * Set to false to disable rate limiting for this endpoint. + * Registration endpoints are particularly sensitive to abuse and should be rate limited. + */ + rateLimit?: Partial | false; + /** + * Whether to generate a client ID before calling the client registration endpoint. + * + * If not set, defaults to true. + */ + clientIdGeneration?: boolean; +}; +export declare function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds, rateLimit: rateLimitConfig, clientIdGeneration }: ClientRegistrationHandlerOptions): RequestHandler; +//# sourceMappingURL=register.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/register.d.ts.map b/dist/cjs/server/auth/handlers/register.d.ts.map new file mode 100644 index 000000000..a38ebdb89 --- /dev/null +++ b/dist/cjs/server/auth/handlers/register.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,gCAAgC,GAAG;IAC3C;;OAEG;IACH,YAAY,EAAE,2BAA2B,CAAC;IAE1C;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IAE9C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAIF,wBAAgB,yBAAyB,CAAC,EACtC,YAAY,EACZ,yBAAgE,EAChE,SAAS,EAAE,eAAe,EAC1B,kBAAyB,EAC5B,EAAE,gCAAgC,GAAG,cAAc,CA0EnD"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/register.js b/dist/cjs/server/auth/handlers/register.js new file mode 100644 index 000000000..e40c5c904 --- /dev/null +++ b/dist/cjs/server/auth/handlers/register.js @@ -0,0 +1,77 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.clientRegistrationHandler = clientRegistrationHandler; +const express_1 = __importDefault(require("express")); +const auth_js_1 = require("../../../shared/auth.js"); +const node_crypto_1 = __importDefault(require("node:crypto")); +const cors_1 = __importDefault(require("cors")); +const express_rate_limit_1 = require("express-rate-limit"); +const allowedMethods_js_1 = require("../middleware/allowedMethods.js"); +const errors_js_1 = require("../errors.js"); +const DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS = 30 * 24 * 60 * 60; // 30 days +function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds = DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS, rateLimit: rateLimitConfig, clientIdGeneration = true }) { + if (!clientsStore.registerClient) { + throw new Error('Client registration store does not support registering clients'); + } + // Nested router so we can configure middleware and restrict HTTP method + const router = express_1.default.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use((0, cors_1.default)()); + router.use((0, allowedMethods_js_1.allowedMethods)(['POST'])); + router.use(express_1.default.json()); + // Apply rate limiting unless explicitly disabled - stricter limits for registration + if (rateLimitConfig !== false) { + router.use((0, express_rate_limit_1.rateLimit)({ + windowMs: 60 * 60 * 1000, // 1 hour + max: 20, // 20 requests per hour - stricter as registration is sensitive + standardHeaders: true, + legacyHeaders: false, + message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for client registration requests').toResponseObject(), + ...rateLimitConfig + })); + } + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = auth_js_1.OAuthClientMetadataSchema.safeParse(req.body); + if (!parseResult.success) { + throw new errors_js_1.InvalidClientMetadataError(parseResult.error.message); + } + const clientMetadata = parseResult.data; + const isPublicClient = clientMetadata.token_endpoint_auth_method === 'none'; + // Generate client credentials + const clientSecret = isPublicClient ? undefined : node_crypto_1.default.randomBytes(32).toString('hex'); + const clientIdIssuedAt = Math.floor(Date.now() / 1000); + // Calculate client secret expiry time + const clientsDoExpire = clientSecretExpirySeconds > 0; + const secretExpiryTime = clientsDoExpire ? clientIdIssuedAt + clientSecretExpirySeconds : 0; + const clientSecretExpiresAt = isPublicClient ? undefined : secretExpiryTime; + let clientInfo = { + ...clientMetadata, + client_secret: clientSecret, + client_secret_expires_at: clientSecretExpiresAt + }; + if (clientIdGeneration) { + clientInfo.client_id = node_crypto_1.default.randomUUID(); + clientInfo.client_id_issued_at = clientIdIssuedAt; + } + clientInfo = await clientsStore.registerClient(clientInfo); + res.status(201).json(clientInfo); + } + catch (error) { + if (error instanceof errors_js_1.OAuthError) { + const status = error instanceof errors_js_1.ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=register.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/register.js.map b/dist/cjs/server/auth/handlers/register.js.map new file mode 100644 index 000000000..e116a474f --- /dev/null +++ b/dist/cjs/server/auth/handlers/register.js.map @@ -0,0 +1 @@ +{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":";;;;;AAuCA,8DA+EC;AAtHD,sDAAkD;AAClD,qDAAgG;AAChG,8DAAiC;AACjC,gDAAwB;AAExB,2DAA4E;AAC5E,uEAAiE;AACjE,4CAAyG;AA8BzG,MAAM,oCAAoC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AAE1E,SAAgB,yBAAyB,CAAC,EACtC,YAAY,EACZ,yBAAyB,GAAG,oCAAoC,EAChE,SAAS,EAAE,eAAe,EAC1B,kBAAkB,GAAG,IAAI,EACM;IAC/B,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACtF,CAAC;IAED,wEAAwE;IACxE,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;IAClF,MAAM,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,IAAA,kCAAc,EAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAE3B,oFAAoF;IACpF,IAAI,eAAe,KAAK,KAAK,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CACN,IAAA,8BAAS,EAAC;YACN,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,SAAS;YACnC,GAAG,EAAE,EAAE,EAAE,+DAA+D;YACxE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AAa,EAAE,YAAY;gBAC3B,wBAAwB,EAAE,qBAAqB;aAClD,CAAC;YAEF,IAAI,kBAAkB,EAAE,CAAC;gBACrB,UAAU,CAAC,SAAS,GAAG,qBAAM,CAAC,UAAU,EAAE,CAAC;gBAC3C,UAAU,CAAC,mBAAmB,GAAG,gBAAgB,CAAC;YACtD,CAAC;YAED,UAAU,GAAG,MAAM,YAAY,CAAC,cAAe,CAAC,UAAU,CAAC,CAAC;YAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,sBAAU,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,KAAK,YAAY,uBAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;gBACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,uBAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/revoke.d.ts b/dist/cjs/server/auth/handlers/revoke.d.ts new file mode 100644 index 000000000..2be32bb3c --- /dev/null +++ b/dist/cjs/server/auth/handlers/revoke.d.ts @@ -0,0 +1,13 @@ +import { OAuthServerProvider } from '../provider.js'; +import { RequestHandler } from 'express'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type RevocationHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the token revocation endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function revocationHandler({ provider, rateLimit: rateLimitConfig }: RevocationHandlerOptions): RequestHandler; +//# sourceMappingURL=revoke.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/revoke.d.ts.map b/dist/cjs/server/auth/handlers/revoke.d.ts.map new file mode 100644 index 000000000..fb13cf19f --- /dev/null +++ b/dist/cjs/server/auth/handlers/revoke.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/revoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,wBAAwB,GAAG;IACnC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,wBAAwB,GAAG,cAAc,CA4DpH"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/revoke.js b/dist/cjs/server/auth/handlers/revoke.js new file mode 100644 index 000000000..4fb1da738 --- /dev/null +++ b/dist/cjs/server/auth/handlers/revoke.js @@ -0,0 +1,65 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.revocationHandler = revocationHandler; +const express_1 = __importDefault(require("express")); +const cors_1 = __importDefault(require("cors")); +const clientAuth_js_1 = require("../middleware/clientAuth.js"); +const auth_js_1 = require("../../../shared/auth.js"); +const express_rate_limit_1 = require("express-rate-limit"); +const allowedMethods_js_1 = require("../middleware/allowedMethods.js"); +const errors_js_1 = require("../errors.js"); +function revocationHandler({ provider, rateLimit: rateLimitConfig }) { + if (!provider.revokeToken) { + throw new Error('Auth provider does not support revoking tokens'); + } + // Nested router so we can configure middleware and restrict HTTP method + const router = express_1.default.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use((0, cors_1.default)()); + router.use((0, allowedMethods_js_1.allowedMethods)(['POST'])); + router.use(express_1.default.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use((0, express_rate_limit_1.rateLimit)({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 50, // 50 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for token revocation requests').toResponseObject(), + ...rateLimitConfig + })); + } + // Authenticate and extract client details + router.use((0, clientAuth_js_1.authenticateClient)({ clientsStore: provider.clientsStore })); + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = auth_js_1.OAuthTokenRevocationRequestSchema.safeParse(req.body); + if (!parseResult.success) { + throw new errors_js_1.InvalidRequestError(parseResult.error.message); + } + const client = req.client; + if (!client) { + // This should never happen + throw new errors_js_1.ServerError('Internal Server Error'); + } + await provider.revokeToken(client, parseResult.data); + res.status(200).json({}); + } + catch (error) { + if (error instanceof errors_js_1.OAuthError) { + const status = error instanceof errors_js_1.ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=revoke.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/revoke.js.map b/dist/cjs/server/auth/handlers/revoke.js.map new file mode 100644 index 000000000..ca01fee7f --- /dev/null +++ b/dist/cjs/server/auth/handlers/revoke.js.map @@ -0,0 +1 @@ +{"version":3,"file":"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;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/token.d.ts b/dist/cjs/server/auth/handlers/token.d.ts new file mode 100644 index 000000000..24d1c8783 --- /dev/null +++ b/dist/cjs/server/auth/handlers/token.d.ts @@ -0,0 +1,13 @@ +import { RequestHandler } from 'express'; +import { OAuthServerProvider } from '../provider.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type TokenHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the token endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function tokenHandler({ provider, rateLimit: rateLimitConfig }: TokenHandlerOptions): RequestHandler; +//# sourceMappingURL=token.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/token.d.ts.map b/dist/cjs/server/auth/handlers/token.d.ts.map new file mode 100644 index 000000000..68189b0b2 --- /dev/null +++ b/dist/cjs/server/auth/handlers/token.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/token.ts"],"names":[],"mappings":"AACA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIrD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW5E,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAmBF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,mBAAmB,GAAG,cAAc,CA+G1G"} \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/token.js b/dist/cjs/server/auth/handlers/token.js new file mode 100644 index 000000000..61a6cbf65 --- /dev/null +++ b/dist/cjs/server/auth/handlers/token.js @@ -0,0 +1,136 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tokenHandler = tokenHandler; +const z = __importStar(require("zod/v4")); +const express_1 = __importDefault(require("express")); +const cors_1 = __importDefault(require("cors")); +const pkce_challenge_1 = require("pkce-challenge"); +const clientAuth_js_1 = require("../middleware/clientAuth.js"); +const express_rate_limit_1 = require("express-rate-limit"); +const allowedMethods_js_1 = require("../middleware/allowedMethods.js"); +const errors_js_1 = require("../errors.js"); +const TokenRequestSchema = z.object({ + grant_type: z.string() +}); +const AuthorizationCodeGrantSchema = z.object({ + code: z.string(), + code_verifier: z.string(), + redirect_uri: z.string().optional(), + resource: z.string().url().optional() +}); +const RefreshTokenGrantSchema = z.object({ + refresh_token: z.string(), + scope: z.string().optional(), + resource: z.string().url().optional() +}); +function tokenHandler({ provider, rateLimit: rateLimitConfig }) { + // Nested router so we can configure middleware and restrict HTTP method + const router = express_1.default.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use((0, cors_1.default)()); + router.use((0, allowedMethods_js_1.allowedMethods)(['POST'])); + router.use(express_1.default.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use((0, express_rate_limit_1.rateLimit)({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 50, // 50 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for token requests').toResponseObject(), + ...rateLimitConfig + })); + } + // Authenticate and extract client details + router.use((0, clientAuth_js_1.authenticateClient)({ clientsStore: provider.clientsStore })); + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = TokenRequestSchema.safeParse(req.body); + if (!parseResult.success) { + throw new errors_js_1.InvalidRequestError(parseResult.error.message); + } + const { grant_type } = parseResult.data; + const client = req.client; + if (!client) { + // This should never happen + throw new errors_js_1.ServerError('Internal Server Error'); + } + switch (grant_type) { + case 'authorization_code': { + const parseResult = AuthorizationCodeGrantSchema.safeParse(req.body); + if (!parseResult.success) { + throw new errors_js_1.InvalidRequestError(parseResult.error.message); + } + const { code, code_verifier, redirect_uri, resource } = parseResult.data; + const skipLocalPkceValidation = provider.skipLocalPkceValidation; + // Perform local PKCE validation unless explicitly skipped + // (e.g. to validate code_verifier in upstream server) + if (!skipLocalPkceValidation) { + const codeChallenge = await provider.challengeForAuthorizationCode(client, code); + if (!(await (0, pkce_challenge_1.verifyChallenge)(code_verifier, codeChallenge))) { + throw new errors_js_1.InvalidGrantError('code_verifier does not match the challenge'); + } + } + // Passes the code_verifier to the provider if PKCE validation didn't occur locally + const tokens = await provider.exchangeAuthorizationCode(client, code, skipLocalPkceValidation ? code_verifier : undefined, redirect_uri, resource ? new URL(resource) : undefined); + res.status(200).json(tokens); + break; + } + case 'refresh_token': { + const parseResult = RefreshTokenGrantSchema.safeParse(req.body); + if (!parseResult.success) { + throw new errors_js_1.InvalidRequestError(parseResult.error.message); + } + const { refresh_token, scope, resource } = parseResult.data; + const scopes = scope === null || scope === void 0 ? void 0 : scope.split(' '); + const tokens = await provider.exchangeRefreshToken(client, refresh_token, scopes, resource ? new URL(resource) : undefined); + res.status(200).json(tokens); + break; + } + // Additional auth methods will not be added on the server side of the SDK. + case 'client_credentials': + default: + throw new errors_js_1.UnsupportedGrantTypeError('The grant type is not supported by this authorization server.'); + } + } + catch (error) { + if (error instanceof errors_js_1.OAuthError) { + const status = error instanceof errors_js_1.ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=token.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/handlers/token.js.map b/dist/cjs/server/auth/handlers/token.js.map new file mode 100644 index 000000000..ba22d11fc --- /dev/null +++ b/dist/cjs/server/auth/handlers/token.js.map @@ -0,0 +1 @@ +{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,oCA+GC;AA1JD,0CAA4B;AAC5B,sDAAkD;AAElD,gDAAwB;AACxB,mDAAiD;AACjD,+DAAiE;AACjE,2DAA4E;AAC5E,uEAAiE;AACjE,4CAOsB;AAWtB,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC;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gBAC1B;oBACI,MAAM,IAAI,qCAAyB,CAAC,+DAA+D,CAAC,CAAC;YAC7G,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,sBAAU,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,KAAK,YAAY,uBAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;gBACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,uBAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/allowedMethods.d.ts b/dist/cjs/server/auth/middleware/allowedMethods.d.ts new file mode 100644 index 000000000..ee6037e0d --- /dev/null +++ b/dist/cjs/server/auth/middleware/allowedMethods.d.ts @@ -0,0 +1,9 @@ +import { RequestHandler } from 'express'; +/** + * Middleware to handle unsupported HTTP methods with a 405 Method Not Allowed response. + * + * @param allowedMethods Array of allowed HTTP methods for this endpoint (e.g., ['GET', 'POST']) + * @returns Express middleware that returns a 405 error if method not in allowed list + */ +export declare function allowedMethods(allowedMethods: string[]): RequestHandler; +//# sourceMappingURL=allowedMethods.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/allowedMethods.d.ts.map b/dist/cjs/server/auth/middleware/allowedMethods.d.ts.map new file mode 100644 index 000000000..d3de93e24 --- /dev/null +++ b/dist/cjs/server/auth/middleware/allowedMethods.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"allowedMethods.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/allowedMethods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,cAAc,CAUvE"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/allowedMethods.js b/dist/cjs/server/auth/middleware/allowedMethods.js new file mode 100644 index 000000000..f44553745 --- /dev/null +++ b/dist/cjs/server/auth/middleware/allowedMethods.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.allowedMethods = allowedMethods; +const errors_js_1 = require("../errors.js"); +/** + * Middleware to handle unsupported HTTP methods with a 405 Method Not Allowed response. + * + * @param allowedMethods Array of allowed HTTP methods for this endpoint (e.g., ['GET', 'POST']) + * @returns Express middleware that returns a 405 error if method not in allowed list + */ +function allowedMethods(allowedMethods) { + return (req, res, next) => { + if (allowedMethods.includes(req.method)) { + next(); + return; + } + const error = new errors_js_1.MethodNotAllowedError(`The method ${req.method} is not allowed for this endpoint`); + res.status(405).set('Allow', allowedMethods.join(', ')).json(error.toResponseObject()); + }; +} +//# sourceMappingURL=allowedMethods.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/allowedMethods.js.map b/dist/cjs/server/auth/middleware/allowedMethods.js.map new file mode 100644 index 000000000..be69f3377 --- /dev/null +++ b/dist/cjs/server/auth/middleware/allowedMethods.js.map @@ -0,0 +1 @@ +{"version":3,"file":"allowedMethods.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/allowedMethods.ts"],"names":[],"mappings":";;AASA,wCAUC;AAlBD,4CAAqD;AAErD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,cAAwB;IACnD,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,IAAI,EAAE,CAAC;YACP,OAAO;QACX,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,iCAAqB,CAAC,cAAc,GAAG,CAAC,MAAM,mCAAmC,CAAC,CAAC;QACrG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC3F,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/bearerAuth.d.ts b/dist/cjs/server/auth/middleware/bearerAuth.d.ts new file mode 100644 index 000000000..10730758b --- /dev/null +++ b/dist/cjs/server/auth/middleware/bearerAuth.d.ts @@ -0,0 +1,35 @@ +import { RequestHandler } from 'express'; +import { OAuthTokenVerifier } from '../provider.js'; +import { AuthInfo } from '../types.js'; +export type BearerAuthMiddlewareOptions = { + /** + * A provider used to verify tokens. + */ + verifier: OAuthTokenVerifier; + /** + * Optional scopes that the token must have. + */ + requiredScopes?: string[]; + /** + * Optional resource metadata URL to include in WWW-Authenticate header. + */ + resourceMetadataUrl?: string; +}; +declare module 'express-serve-static-core' { + interface Request { + /** + * Information about the validated access token, if the `requireBearerAuth` middleware was used. + */ + auth?: AuthInfo; + } +} +/** + * Middleware that requires a valid Bearer token in the Authorization header. + * + * This will validate the token with the auth provider and add the resulting auth info to the request object. + * + * If resourceMetadataUrl is provided, it will be included in the WWW-Authenticate header + * for 401 responses as per the OAuth 2.0 Protected Resource Metadata spec. + */ +export declare function requireBearerAuth({ verifier, requiredScopes, resourceMetadataUrl }: BearerAuthMiddlewareOptions): RequestHandler; +//# sourceMappingURL=bearerAuth.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/bearerAuth.d.ts.map b/dist/cjs/server/auth/middleware/bearerAuth.d.ts.map new file mode 100644 index 000000000..c9d939f3b --- /dev/null +++ b/dist/cjs/server/auth/middleware/bearerAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bearerAuth.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/bearerAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,MAAM,2BAA2B,GAAG;IACtC;;OAEG;IACH,QAAQ,EAAE,kBAAkB,CAAC;IAE7B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,OAAO,QAAQ,2BAA2B,CAAC;IACvC,UAAU,OAAO;QACb;;WAEG;QACH,IAAI,CAAC,EAAE,QAAQ,CAAC;KACnB;CACJ;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,cAAmB,EAAE,mBAAmB,EAAE,EAAE,2BAA2B,GAAG,cAAc,CA8DrI"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/bearerAuth.js b/dist/cjs/server/auth/middleware/bearerAuth.js new file mode 100644 index 000000000..dcfc50935 --- /dev/null +++ b/dist/cjs/server/auth/middleware/bearerAuth.js @@ -0,0 +1,75 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.requireBearerAuth = requireBearerAuth; +const errors_js_1 = require("../errors.js"); +/** + * Middleware that requires a valid Bearer token in the Authorization header. + * + * This will validate the token with the auth provider and add the resulting auth info to the request object. + * + * If resourceMetadataUrl is provided, it will be included in the WWW-Authenticate header + * for 401 responses as per the OAuth 2.0 Protected Resource Metadata spec. + */ +function requireBearerAuth({ verifier, requiredScopes = [], resourceMetadataUrl }) { + return async (req, res, next) => { + try { + const authHeader = req.headers.authorization; + if (!authHeader) { + throw new errors_js_1.InvalidTokenError('Missing Authorization header'); + } + const [type, token] = authHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !token) { + throw new errors_js_1.InvalidTokenError("Invalid Authorization header format, expected 'Bearer TOKEN'"); + } + const authInfo = await verifier.verifyAccessToken(token); + // Check if token has the required scopes (if any) + if (requiredScopes.length > 0) { + const hasAllScopes = requiredScopes.every(scope => authInfo.scopes.includes(scope)); + if (!hasAllScopes) { + throw new errors_js_1.InsufficientScopeError('Insufficient scope'); + } + } + // Check if the token is set to expire or if it is expired + if (typeof authInfo.expiresAt !== 'number' || isNaN(authInfo.expiresAt)) { + throw new errors_js_1.InvalidTokenError('Token has no expiration time'); + } + else if (authInfo.expiresAt < Date.now() / 1000) { + throw new errors_js_1.InvalidTokenError('Token has expired'); + } + req.auth = authInfo; + next(); + } + catch (error) { + // Build WWW-Authenticate header parts + const buildWwwAuthHeader = (errorCode, message) => { + let header = `Bearer error="${errorCode}", error_description="${message}"`; + if (requiredScopes.length > 0) { + header += `, scope="${requiredScopes.join(' ')}"`; + } + if (resourceMetadataUrl) { + header += `, resource_metadata="${resourceMetadataUrl}"`; + } + return header; + }; + if (error instanceof errors_js_1.InvalidTokenError) { + res.set('WWW-Authenticate', buildWwwAuthHeader(error.errorCode, error.message)); + res.status(401).json(error.toResponseObject()); + } + else if (error instanceof errors_js_1.InsufficientScopeError) { + res.set('WWW-Authenticate', buildWwwAuthHeader(error.errorCode, error.message)); + res.status(403).json(error.toResponseObject()); + } + else if (error instanceof errors_js_1.ServerError) { + res.status(500).json(error.toResponseObject()); + } + else if (error instanceof errors_js_1.OAuthError) { + res.status(400).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }; +} +//# sourceMappingURL=bearerAuth.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/bearerAuth.js.map b/dist/cjs/server/auth/middleware/bearerAuth.js.map new file mode 100644 index 000000000..d111d36bf --- /dev/null +++ b/dist/cjs/server/auth/middleware/bearerAuth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bearerAuth.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/bearerAuth.ts"],"names":[],"mappings":";;AAuCA,8CA8DC;AApGD,4CAAkG;AA8BlG;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,cAAc,GAAG,EAAE,EAAE,mBAAmB,EAA+B;IACjH,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,CAAC;YACD,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;YAC7C,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,MAAM,IAAI,6BAAiB,CAAC,8BAA8B,CAAC,CAAC;YAChE,CAAC;YAED,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC5C,MAAM,IAAI,6BAAiB,CAAC,8DAA8D,CAAC,CAAC;YAChG,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YAEzD,kDAAkD;YAClD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;gBAEpF,IAAI,CAAC,YAAY,EAAE,CAAC;oBAChB,MAAM,IAAI,kCAAsB,CAAC,oBAAoB,CAAC,CAAC;gBAC3D,CAAC;YACL,CAAC;YAED,0DAA0D;YAC1D,IAAI,OAAO,QAAQ,CAAC,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KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBAChF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACnD,CAAC;iBAAM,IAAI,KAAK,YAAY,uBAAW,EAAE,CAAC;gBACtC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACnD,CAAC;iBAAM,IAAI,KAAK,YAAY,sBAAU,EAAE,CAAC;gBACrC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,uBAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/clientAuth.d.ts b/dist/cjs/server/auth/middleware/clientAuth.d.ts new file mode 100644 index 000000000..837f95fd2 --- /dev/null +++ b/dist/cjs/server/auth/middleware/clientAuth.d.ts @@ -0,0 +1,19 @@ +import { RequestHandler } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { OAuthClientInformationFull } from '../../../shared/auth.js'; +export type ClientAuthenticationMiddlewareOptions = { + /** + * A store used to read information about registered OAuth clients. + */ + clientsStore: OAuthRegisteredClientsStore; +}; +declare module 'express-serve-static-core' { + interface Request { + /** + * The authenticated client for this request, if the `authenticateClient` middleware was used. + */ + client?: OAuthClientInformationFull; + } +} +export declare function authenticateClient({ clientsStore }: ClientAuthenticationMiddlewareOptions): RequestHandler; +//# sourceMappingURL=clientAuth.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/clientAuth.d.ts.map b/dist/cjs/server/auth/middleware/clientAuth.d.ts.map new file mode 100644 index 000000000..5455132c9 --- /dev/null +++ b/dist/cjs/server/auth/middleware/clientAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"clientAuth.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/clientAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,qCAAqC,GAAG;IAChD;;OAEG;IACH,YAAY,EAAE,2BAA2B,CAAC;CAC7C,CAAC;AAOF,OAAO,QAAQ,2BAA2B,CAAC;IACvC,UAAU,OAAO;QACb;;WAEG;QACH,MAAM,CAAC,EAAE,0BAA0B,CAAC;KACvC;CACJ;AAED,wBAAgB,kBAAkB,CAAC,EAAE,YAAY,EAAE,EAAE,qCAAqC,GAAG,cAAc,CAoC1G"} \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/clientAuth.js b/dist/cjs/server/auth/middleware/clientAuth.js new file mode 100644 index 000000000..e54dd10e8 --- /dev/null +++ b/dist/cjs/server/auth/middleware/clientAuth.js @@ -0,0 +1,71 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.authenticateClient = authenticateClient; +const z = __importStar(require("zod/v4")); +const errors_js_1 = require("../errors.js"); +const ClientAuthenticatedRequestSchema = z.object({ + client_id: z.string(), + client_secret: z.string().optional() +}); +function authenticateClient({ clientsStore }) { + return async (req, res, next) => { + try { + const result = ClientAuthenticatedRequestSchema.safeParse(req.body); + if (!result.success) { + throw new errors_js_1.InvalidRequestError(String(result.error)); + } + const { client_id, client_secret } = result.data; + const client = await clientsStore.getClient(client_id); + if (!client) { + throw new errors_js_1.InvalidClientError('Invalid client_id'); + } + if (client.client_secret) { + if (!client_secret) { + throw new errors_js_1.InvalidClientError('Client secret is required'); + } + if (client.client_secret !== client_secret) { + throw new errors_js_1.InvalidClientError('Invalid client_secret'); + } + if (client.client_secret_expires_at && client.client_secret_expires_at < Math.floor(Date.now() / 1000)) { + throw new errors_js_1.InvalidClientError('Client secret has expired'); + } + } + req.client = client; + next(); + } + catch (error) { + if (error instanceof errors_js_1.OAuthError) { + const status = error instanceof errors_js_1.ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new errors_js_1.ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }; +} +//# sourceMappingURL=clientAuth.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/middleware/clientAuth.js.map b/dist/cjs/server/auth/middleware/clientAuth.js.map new file mode 100644 index 000000000..63184f4b5 --- /dev/null +++ b/dist/cjs/server/auth/middleware/clientAuth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"clientAuth.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/clientAuth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,gDAo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IAAI,8BAAkB,CAAC,2BAA2B,CAAC,CAAC;gBAC9D,CAAC;YACL,CAAC;YAED,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;YACpB,IAAI,EAAE,CAAC;QACX,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,sBAAU,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,KAAK,YAAY,uBAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;gBACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,uBAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/provider.d.ts b/dist/cjs/server/auth/provider.d.ts new file mode 100644 index 000000000..3e4eca392 --- /dev/null +++ b/dist/cjs/server/auth/provider.d.ts @@ -0,0 +1,68 @@ +import { Response } from 'express'; +import { OAuthRegisteredClientsStore } from './clients.js'; +import { OAuthClientInformationFull, OAuthTokenRevocationRequest, OAuthTokens } from '../../shared/auth.js'; +import { AuthInfo } from './types.js'; +export type AuthorizationParams = { + state?: string; + scopes?: string[]; + codeChallenge: string; + redirectUri: string; + resource?: URL; +}; +/** + * Implements an end-to-end OAuth server. + */ +export interface OAuthServerProvider { + /** + * A store used to read information about registered OAuth clients. + */ + get clientsStore(): OAuthRegisteredClientsStore; + /** + * Begins the authorization flow, which can either be implemented by this server itself or via redirection to a separate authorization server. + * + * This server must eventually issue a redirect with an authorization response or an error response to the given redirect URI. Per OAuth 2.1: + * - In the successful case, the redirect MUST include the `code` and `state` (if present) query parameters. + * - In the error case, the redirect MUST include the `error` query parameter, and MAY include an optional `error_description` query parameter. + */ + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + /** + * Returns the `codeChallenge` that was used when the indicated authorization began. + */ + challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise; + /** + * Exchanges an authorization code for an access token. + */ + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, codeVerifier?: string, redirectUri?: string, resource?: URL): Promise; + /** + * Exchanges a refresh token for an access token. + */ + exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: URL): Promise; + /** + * Verifies an access token and returns information about it. + */ + verifyAccessToken(token: string): Promise; + /** + * Revokes an access or refresh token. If unimplemented, token revocation is not supported (not recommended). + * + * If the given token is invalid or already revoked, this method should do nothing. + */ + revokeToken?(client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest): Promise; + /** + * Whether to skip local PKCE validation. + * + * If true, the server will not perform PKCE validation locally and will pass the code_verifier to the upstream server. + * + * NOTE: This should only be true if the upstream server is performing the actual PKCE validation. + */ + skipLocalPkceValidation?: boolean; +} +/** + * Slim implementation useful for token verification + */ +export interface OAuthTokenVerifier { + /** + * Verifies an access token and returns information about it. + */ + verifyAccessToken(token: string): Promise; +} +//# sourceMappingURL=provider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/provider.d.ts.map b/dist/cjs/server/auth/provider.d.ts.map new file mode 100644 index 000000000..d1a4bfff0 --- /dev/null +++ b/dist/cjs/server/auth/provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,WAAW,EAA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AAC,CAAC;IAEtG;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACvD"} \ No newline at end of file diff --git a/dist/cjs/server/auth/provider.js b/dist/cjs/server/auth/provider.js new file mode 100644 index 000000000..0903bb2ef --- /dev/null +++ b/dist/cjs/server/auth/provider.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=provider.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/provider.js.map b/dist/cjs/server/auth/provider.js.map new file mode 100644 index 000000000..b968414aa --- /dev/null +++ b/dist/cjs/server/auth/provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../src/server/auth/provider.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/server/auth/providers/proxyProvider.d.ts b/dist/cjs/server/auth/providers/proxyProvider.d.ts new file mode 100644 index 000000000..ee6f35081 --- /dev/null +++ b/dist/cjs/server/auth/providers/proxyProvider.d.ts @@ -0,0 +1,49 @@ +import { Response } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { OAuthClientInformationFull, OAuthTokenRevocationRequest, OAuthTokens } from '../../../shared/auth.js'; +import { AuthInfo } from '../types.js'; +import { AuthorizationParams, OAuthServerProvider } from '../provider.js'; +import { FetchLike } from '../../../shared/transport.js'; +export type ProxyEndpoints = { + authorizationUrl: string; + tokenUrl: string; + revocationUrl?: string; + registrationUrl?: string; +}; +export type ProxyOptions = { + /** + * Individual endpoint URLs for proxying specific OAuth operations + */ + endpoints: ProxyEndpoints; + /** + * Function to verify access tokens and return auth info + */ + verifyAccessToken: (token: string) => Promise; + /** + * Function to fetch client information from the upstream server + */ + getClient: (clientId: string) => Promise; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; +}; +/** + * Implements an OAuth server that proxies requests to another OAuth server. + */ +export declare class ProxyOAuthServerProvider implements OAuthServerProvider { + protected readonly _endpoints: ProxyEndpoints; + protected readonly _verifyAccessToken: (token: string) => Promise; + protected readonly _getClient: (clientId: string) => Promise; + protected readonly _fetch?: FetchLike; + skipLocalPkceValidation: boolean; + revokeToken?: (client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest) => Promise; + constructor(options: ProxyOptions); + get clientsStore(): OAuthRegisteredClientsStore; + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + challengeForAuthorizationCode(_client: OAuthClientInformationFull, _authorizationCode: string): Promise; + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, codeVerifier?: string, redirectUri?: string, resource?: URL): Promise; + exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: URL): Promise; + verifyAccessToken(token: string): Promise; +} +//# sourceMappingURL=proxyProvider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/providers/proxyProvider.d.ts.map b/dist/cjs/server/auth/providers/proxyProvider.d.ts.map new file mode 100644 index 000000000..124c105fa --- /dev/null +++ b/dist/cjs/server/auth/providers/proxyProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proxyProvider.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/providers/proxyProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACH,0BAA0B,EAE1B,2BAA2B,EAC3B,WAAW,EAEd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,M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AAO,CAAC,IAAI,CAAC;IAoBxG,6BAA6B,CAAC,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM/G,yBAAyB,CAC3B,MAAM,EAAE,0BAA0B,EAClC,iBAAiB,EAAE,MAAM,EACzB,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,WAAW,CAAC;IAwCjB,oBAAoB,CACtB,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,EAAE,EACjB,QAAQ,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,WAAW,CAAC;IAoCjB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAG5D"} \ No newline at end of file diff --git a/dist/cjs/server/auth/providers/proxyProvider.js b/dist/cjs/server/auth/providers/proxyProvider.js new file mode 100644 index 000000000..b76a386d8 --- /dev/null +++ b/dist/cjs/server/auth/providers/proxyProvider.js @@ -0,0 +1,165 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ProxyOAuthServerProvider = void 0; +const auth_js_1 = require("../../../shared/auth.js"); +const errors_js_1 = require("../errors.js"); +/** + * Implements an OAuth server that proxies requests to another OAuth server. + */ +class ProxyOAuthServerProvider { + constructor(options) { + var _a; + this.skipLocalPkceValidation = true; + this._endpoints = options.endpoints; + this._verifyAccessToken = options.verifyAccessToken; + this._getClient = options.getClient; + this._fetch = options.fetch; + if ((_a = options.endpoints) === null || _a === void 0 ? void 0 : _a.revocationUrl) { + this.revokeToken = async (client, request) => { + var _a, _b; + const revocationUrl = this._endpoints.revocationUrl; + if (!revocationUrl) { + throw new Error('No revocation endpoint configured'); + } + const params = new URLSearchParams(); + params.set('token', request.token); + params.set('client_id', client.client_id); + if (client.client_secret) { + params.set('client_secret', client.client_secret); + } + if (request.token_type_hint) { + params.set('token_type_hint', request.token_type_hint); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(revocationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + if (!response.ok) { + throw new errors_js_1.ServerError(`Token revocation failed: ${response.status}`); + } + }; + } + } + get clientsStore() { + const registrationUrl = this._endpoints.registrationUrl; + return { + getClient: this._getClient, + ...(registrationUrl && { + registerClient: async (client) => { + var _a, _b; + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(registrationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(client) + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new errors_js_1.ServerError(`Client registration failed: ${response.status}`); + } + const data = await response.json(); + return auth_js_1.OAuthClientInformationFullSchema.parse(data); + } + }) + }; + } + async authorize(client, params, res) { + var _a; + // Start with required OAuth parameters + const targetUrl = new URL(this._endpoints.authorizationUrl); + const searchParams = new URLSearchParams({ + client_id: client.client_id, + response_type: 'code', + redirect_uri: params.redirectUri, + code_challenge: params.codeChallenge, + code_challenge_method: 'S256' + }); + // Add optional standard OAuth parameters + if (params.state) + searchParams.set('state', params.state); + if ((_a = params.scopes) === null || _a === void 0 ? void 0 : _a.length) + searchParams.set('scope', params.scopes.join(' ')); + if (params.resource) + searchParams.set('resource', params.resource.href); + targetUrl.search = searchParams.toString(); + res.redirect(targetUrl.toString()); + } + async challengeForAuthorizationCode(_client, _authorizationCode) { + // In a proxy setup, we don't store the code challenge ourselves + // Instead, we proxy the token request and let the upstream server validate it + return ''; + } + async exchangeAuthorizationCode(client, authorizationCode, codeVerifier, redirectUri, resource) { + var _a, _b; + const params = new URLSearchParams({ + grant_type: 'authorization_code', + client_id: client.client_id, + code: authorizationCode + }); + if (client.client_secret) { + params.append('client_secret', client.client_secret); + } + if (codeVerifier) { + params.append('code_verifier', codeVerifier); + } + if (redirectUri) { + params.append('redirect_uri', redirectUri); + } + if (resource) { + params.append('resource', resource.href); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._endpoints.tokenUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new errors_js_1.ServerError(`Token exchange failed: ${response.status}`); + } + const data = await response.json(); + return auth_js_1.OAuthTokensSchema.parse(data); + } + async exchangeRefreshToken(client, refreshToken, scopes, resource) { + var _a, _b; + const params = new URLSearchParams({ + grant_type: 'refresh_token', + client_id: client.client_id, + refresh_token: refreshToken + }); + if (client.client_secret) { + params.set('client_secret', client.client_secret); + } + if (scopes === null || scopes === void 0 ? void 0 : scopes.length) { + params.set('scope', scopes.join(' ')); + } + if (resource) { + params.set('resource', resource.href); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._endpoints.tokenUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new errors_js_1.ServerError(`Token refresh failed: ${response.status}`); + } + const data = await response.json(); + return auth_js_1.OAuthTokensSchema.parse(data); + } + async verifyAccessToken(token) { + return this._verifyAccessToken(token); + } +} +exports.ProxyOAuthServerProvider = ProxyOAuthServerProvider; +//# sourceMappingURL=proxyProvider.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/providers/proxyProvider.js.map b/dist/cjs/server/auth/providers/proxyProvider.js.map new file mode 100644 index 000000000..e6010a140 --- /dev/null +++ b/dist/cjs/server/auth/providers/proxyProvider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proxyProvider.js","sourceRoot":"","sources":["../../../../../src/server/auth/providers/proxyProvider.ts"],"names":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diff --git a/dist/cjs/server/auth/router.d.ts b/dist/cjs/server/auth/router.d.ts new file mode 100644 index 000000000..43dabde7d --- /dev/null +++ b/dist/cjs/server/auth/router.d.ts @@ -0,0 +1,101 @@ +import express, { RequestHandler } from 'express'; +import { ClientRegistrationHandlerOptions } from './handlers/register.js'; +import { TokenHandlerOptions } from './handlers/token.js'; +import { AuthorizationHandlerOptions } from './handlers/authorize.js'; +import { RevocationHandlerOptions } from './handlers/revoke.js'; +import { OAuthServerProvider } from './provider.js'; +import { OAuthMetadata } from '../../shared/auth.js'; +export type AuthRouterOptions = { + /** + * A provider implementing the actual authorization logic for this router. + */ + provider: OAuthServerProvider; + /** + * The authorization server's issuer identifier, which is a URL that uses the "https" scheme and has no query or fragment components. + */ + issuerUrl: URL; + /** + * The base URL of the authorization server to use for the metadata endpoints. + * + * If not provided, the issuer URL will be used as the base URL. + */ + baseUrl?: URL; + /** + * An optional URL of a page containing human-readable information that developers might want or need to know when using the authorization server. + */ + serviceDocumentationUrl?: URL; + /** + * An optional list of scopes supported by this authorization server + */ + scopesSupported?: string[]; + /** + * The resource name to be displayed in protected resource metadata + */ + resourceName?: string; + /** + * The URL of the protected resource (RS) whose metadata we advertise. + * If not provided, falls back to `baseUrl` and then to `issuerUrl` (AS=RS). + */ + resourceServerUrl?: URL; + authorizationOptions?: Omit; + clientRegistrationOptions?: Omit; + revocationOptions?: Omit; + tokenOptions?: Omit; +}; +export declare const createOAuthMetadata: (options: { + provider: OAuthServerProvider; + issuerUrl: URL; + baseUrl?: URL; + serviceDocumentationUrl?: URL; + scopesSupported?: string[]; +}) => OAuthMetadata; +/** + * Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported). + * Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients. + * Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead. + * + * By default, rate limiting is applied to all endpoints to prevent abuse. + * + * This router MUST be installed at the application root, like so: + * + * const app = express(); + * app.use(mcpAuthRouter(...)); + */ +export declare function mcpAuthRouter(options: AuthRouterOptions): RequestHandler; +export type AuthMetadataOptions = { + /** + * OAuth Metadata as would be returned from the authorization server + * this MCP server relies on + */ + oauthMetadata: OAuthMetadata; + /** + * The url of the MCP server, for use in protected resource metadata + */ + resourceServerUrl: URL; + /** + * The url for documentation for the MCP server + */ + serviceDocumentationUrl?: URL; + /** + * An optional list of scopes supported by this MCP server + */ + scopesSupported?: string[]; + /** + * An optional resource name to display in resource metadata + */ + resourceName?: string; +}; +export declare function mcpAuthMetadataRouter(options: AuthMetadataOptions): express.Router; +/** + * Helper function to construct the OAuth 2.0 Protected Resource Metadata URL + * from a given server URL. This replaces the path with the standard metadata endpoint. + * + * @param serverUrl - The base URL of the protected resource server + * @returns The URL for the OAuth protected resource metadata endpoint + * + * @example + * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp')) + * // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp' + */ +export declare function getOAuthProtectedResourceMetadataUrl(serverUrl: URL): string; +//# sourceMappingURL=router.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/router.d.ts.map b/dist/cjs/server/auth/router.d.ts.map new file mode 100644 index 000000000..615cb964b --- /dev/null +++ b/dist/cjs/server/auth/router.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAA6B,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAgB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAwB,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAqB,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,aAAa,EAAkC,MAA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AE,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAuBlF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oCAAoC,CAAC,SAAS,EAAE,GAAG,GAAG,MAAM,CAI3E"} \ No newline at end of file diff --git a/dist/cjs/server/auth/router.js b/dist/cjs/server/auth/router.js new file mode 100644 index 000000000..94e915142 --- /dev/null +++ b/dist/cjs/server/auth/router.js @@ -0,0 +1,131 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createOAuthMetadata = void 0; +exports.mcpAuthRouter = mcpAuthRouter; +exports.mcpAuthMetadataRouter = mcpAuthMetadataRouter; +exports.getOAuthProtectedResourceMetadataUrl = getOAuthProtectedResourceMetadataUrl; +const express_1 = __importDefault(require("express")); +const register_js_1 = require("./handlers/register.js"); +const token_js_1 = require("./handlers/token.js"); +const authorize_js_1 = require("./handlers/authorize.js"); +const revoke_js_1 = require("./handlers/revoke.js"); +const metadata_js_1 = require("./handlers/metadata.js"); +// Check for dev mode flag that allows HTTP issuer URLs (for development/testing only) +const allowInsecureIssuerUrl = process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === 'true' || process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === '1'; +if (allowInsecureIssuerUrl) { + // eslint-disable-next-line no-console + console.warn('MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL is enabled - HTTP issuer URLs are allowed. Do not use in production.'); +} +const checkIssuerUrl = (issuer) => { + // Technically RFC 8414 does not permit a localhost HTTPS exemption, but this will be necessary for ease of testing + if (issuer.protocol !== 'https:' && issuer.hostname !== 'localhost' && issuer.hostname !== '127.0.0.1' && !allowInsecureIssuerUrl) { + throw new Error('Issuer URL must be HTTPS'); + } + if (issuer.hash) { + throw new Error(`Issuer URL must not have a fragment: ${issuer}`); + } + if (issuer.search) { + throw new Error(`Issuer URL must not have a query string: ${issuer}`); + } +}; +const createOAuthMetadata = (options) => { + var _a; + const issuer = options.issuerUrl; + const baseUrl = options.baseUrl; + checkIssuerUrl(issuer); + const authorization_endpoint = '/authorize'; + const token_endpoint = '/token'; + const registration_endpoint = options.provider.clientsStore.registerClient ? '/register' : undefined; + const revocation_endpoint = options.provider.revokeToken ? '/revoke' : undefined; + const metadata = { + issuer: issuer.href, + service_documentation: (_a = options.serviceDocumentationUrl) === null || _a === void 0 ? void 0 : _a.href, + authorization_endpoint: new URL(authorization_endpoint, baseUrl || issuer).href, + response_types_supported: ['code'], + code_challenge_methods_supported: ['S256'], + token_endpoint: new URL(token_endpoint, baseUrl || issuer).href, + token_endpoint_auth_methods_supported: ['client_secret_post', 'none'], + grant_types_supported: ['authorization_code', 'refresh_token'], + scopes_supported: options.scopesSupported, + revocation_endpoint: revocation_endpoint ? new URL(revocation_endpoint, baseUrl || issuer).href : undefined, + revocation_endpoint_auth_methods_supported: revocation_endpoint ? ['client_secret_post'] : undefined, + registration_endpoint: registration_endpoint ? new URL(registration_endpoint, baseUrl || issuer).href : undefined + }; + return metadata; +}; +exports.createOAuthMetadata = createOAuthMetadata; +/** + * Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported). + * Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients. + * Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead. + * + * By default, rate limiting is applied to all endpoints to prevent abuse. + * + * This router MUST be installed at the application root, like so: + * + * const app = express(); + * app.use(mcpAuthRouter(...)); + */ +function mcpAuthRouter(options) { + var _a, _b; + const oauthMetadata = (0, exports.createOAuthMetadata)(options); + const router = express_1.default.Router(); + router.use(new URL(oauthMetadata.authorization_endpoint).pathname, (0, authorize_js_1.authorizationHandler)({ provider: options.provider, ...options.authorizationOptions })); + router.use(new URL(oauthMetadata.token_endpoint).pathname, (0, token_js_1.tokenHandler)({ provider: options.provider, ...options.tokenOptions })); + router.use(mcpAuthMetadataRouter({ + oauthMetadata, + // Prefer explicit RS; otherwise fall back to AS baseUrl, then to issuer (back-compat) + resourceServerUrl: (_b = (_a = options.resourceServerUrl) !== null && _a !== void 0 ? _a : options.baseUrl) !== null && _b !== void 0 ? _b : new URL(oauthMetadata.issuer), + serviceDocumentationUrl: options.serviceDocumentationUrl, + scopesSupported: options.scopesSupported, + resourceName: options.resourceName + })); + if (oauthMetadata.registration_endpoint) { + router.use(new URL(oauthMetadata.registration_endpoint).pathname, (0, register_js_1.clientRegistrationHandler)({ + clientsStore: options.provider.clientsStore, + ...options.clientRegistrationOptions + })); + } + if (oauthMetadata.revocation_endpoint) { + router.use(new URL(oauthMetadata.revocation_endpoint).pathname, (0, revoke_js_1.revocationHandler)({ provider: options.provider, ...options.revocationOptions })); + } + return router; +} +function mcpAuthMetadataRouter(options) { + var _a; + checkIssuerUrl(new URL(options.oauthMetadata.issuer)); + const router = express_1.default.Router(); + const protectedResourceMetadata = { + resource: options.resourceServerUrl.href, + authorization_servers: [options.oauthMetadata.issuer], + scopes_supported: options.scopesSupported, + resource_name: options.resourceName, + resource_documentation: (_a = options.serviceDocumentationUrl) === null || _a === void 0 ? void 0 : _a.href + }; + // Serve PRM at the path-specific URL per RFC 9728 + const rsPath = new URL(options.resourceServerUrl.href).pathname; + router.use(`/.well-known/oauth-protected-resource${rsPath === '/' ? '' : rsPath}`, (0, metadata_js_1.metadataHandler)(protectedResourceMetadata)); + // Always add this for OAuth Authorization Server metadata per RFC 8414 + router.use('/.well-known/oauth-authorization-server', (0, metadata_js_1.metadataHandler)(options.oauthMetadata)); + return router; +} +/** + * Helper function to construct the OAuth 2.0 Protected Resource Metadata URL + * from a given server URL. This replaces the path with the standard metadata endpoint. + * + * @param serverUrl - The base URL of the protected resource server + * @returns The URL for the OAuth protected resource metadata endpoint + * + * @example + * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp')) + * // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp' + */ +function getOAuthProtectedResourceMetadataUrl(serverUrl) { + const u = new URL(serverUrl.href); + const rsPath = u.pathname && u.pathname !== '/' ? u.pathname : ''; + return new URL(`/.well-known/oauth-protected-resource${rsPath}`, u).href; +} +//# sourceMappingURL=router.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/router.js.map b/dist/cjs/server/auth/router.js.map new file mode 100644 index 000000000..8e45dd393 --- /dev/null +++ b/dist/cjs/server/auth/router.js.map @@ -0,0 +1 @@ +{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":";;;;;;AAgIA,sCAyCC;AA8BD,sDAuBC;AAaD,oFAIC;AA/OD,sDAAkD;AAClD,wDAAqG;AACrG,kDAAwE;AACxE,0DAA4F;AAC5F,oDAAmF;AACnF,wDAAyD;AAIzD,sFAAsF;AACtF,MAAM,sBAAsB,GACxB,OAAO,CAAC,GAAG,CAAC,yCAAyC,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,yCAAyC,KAAK,GAAG,CAAC;AACtI,IAAI,sBAAsB,EAAE,CAAC;IACzB,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,gHAAgH,CAAC,CAAC;AACnI,CAAC;AAgDD,MAAM,cAAc,GAAG,CAAC,MAAW,EAAQ,EAAE;IACzC,mHAAmH;IACnH,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChI,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,MAAM,EAAE,CAAC,CAAC;IAC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AAQ,CAAC;IAChE,MAAM,CAAC,GAAG,CAAC,wCAAwC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,IAAA,6BAAe,EAAC,yBAAyB,CAAC,CAAC,CAAC;IAE/H,uEAAuE;IACvE,MAAM,CAAC,GAAG,CAAC,yCAAyC,EAAE,IAAA,6BAAe,EAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IAE9F,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,oCAAoC,CAAC,SAAc;IAC/D,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,OAAO,IAAI,GAAG,CAAC,wCAAwC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/types.d.ts b/dist/cjs/server/auth/types.d.ts new file mode 100644 index 000000000..05ec8485a --- /dev/null +++ b/dist/cjs/server/auth/types.d.ts @@ -0,0 +1,32 @@ +/** + * Information about a validated access token, provided to request handlers. + */ +export interface AuthInfo { + /** + * The access token. + */ + token: string; + /** + * The client ID associated with this token. + */ + clientId: string; + /** + * Scopes associated with this token. + */ + scopes: string[]; + /** + * When the token expires (in seconds since epoch). + */ + expiresAt?: number; + /** + * The RFC 8707 resource server identifier for which this token is valid. + * If set, this MUST match the MCP server's resource identifier (minus hash fragment). + */ + resource?: URL; + /** + * Additional data associated with the token. + * This field should be used for any additional data that needs to be attached to the auth info. + */ + extra?: Record; +} +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/auth/types.d.ts.map b/dist/cjs/server/auth/types.d.ts.map new file mode 100644 index 000000000..021e94740 --- /dev/null +++ b/dist/cjs/server/auth/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"} \ No newline at end of file diff --git a/dist/cjs/server/auth/types.js b/dist/cjs/server/auth/types.js new file mode 100644 index 000000000..11e638d1e --- /dev/null +++ b/dist/cjs/server/auth/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/cjs/server/auth/types.js.map b/dist/cjs/server/auth/types.js.map new file mode 100644 index 000000000..0d8063dee --- /dev/null +++ b/dist/cjs/server/auth/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/cjs/server/completable.d.ts b/dist/cjs/server/completable.d.ts new file mode 100644 index 000000000..1b3159ac8 --- /dev/null +++ b/dist/cjs/server/completable.d.ts @@ -0,0 +1,38 @@ +import { AnySchema, SchemaInput } from './zod-compat.js'; +export declare const COMPLETABLE_SYMBOL: unique symbol; +export type CompleteCallback = (value: SchemaInput, context?: { + arguments?: Record; +}) => SchemaInput[] | Promise[]>; +export type CompletableMeta = { + complete: CompleteCallback; +}; +export type CompletableSchema = T & { + [COMPLETABLE_SYMBOL]: CompletableMeta; +}; +/** + * Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP. + * Works with both Zod v3 and v4 schemas. + */ +export declare function completable(schema: T, complete: CompleteCallback): CompletableSchema; +/** + * Checks if a schema is completable (has completion metadata). + */ +export declare function isCompletable(schema: unknown): schema is CompletableSchema; +/** + * Gets the completer callback from a completable schema, if it exists. + */ +export declare function getCompleter(schema: T): CompleteCallback | undefined; +/** + * Unwraps a completable schema to get the underlying schema. + * For backward compatibility with code that called `.unwrap()`. + */ +export declare function unwrapCompletable(schema: CompletableSchema): T; +export declare enum McpZodTypeKind { + Completable = "McpCompletable" +} +export interface CompletableDef { + type: T; + complete: CompleteCallback; + typeName: McpZodTypeKind.Completable; +} +//# sourceMappingURL=completable.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/completable.d.ts.map b/dist/cjs/server/completable.d.ts.map new file mode 100644 index 000000000..83ea2f1e2 --- /dev/null +++ b/dist/cjs/server/completable.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"completable.d.ts","sourceRoot":"","sources":["../../../src/server/completable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAAsC,CAAC;AAE/E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,CAC5D,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE;IACN,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,KACA,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI;IAC3D,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GAAG;IACrD,CAAC,kBAAkB,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAQ/G;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAErF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAG5F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAEtF;AAID,oBAAY,cAAc;IACtB,WAAW,mBAAmB;CACjC;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC3D,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,cAAc,CAAC,WAAW,CAAC;CACxC"} \ No newline at end of file diff --git a/dist/cjs/server/completable.js b/dist/cjs/server/completable.js new file mode 100644 index 000000000..cfddaeba4 --- /dev/null +++ b/dist/cjs/server/completable.js @@ -0,0 +1,48 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.McpZodTypeKind = exports.COMPLETABLE_SYMBOL = void 0; +exports.completable = completable; +exports.isCompletable = isCompletable; +exports.getCompleter = getCompleter; +exports.unwrapCompletable = unwrapCompletable; +exports.COMPLETABLE_SYMBOL = Symbol.for('mcp.completable'); +/** + * Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP. + * Works with both Zod v3 and v4 schemas. + */ +function completable(schema, complete) { + Object.defineProperty(schema, exports.COMPLETABLE_SYMBOL, { + value: { complete }, + enumerable: false, + writable: false, + configurable: false + }); + return schema; +} +/** + * Checks if a schema is completable (has completion metadata). + */ +function isCompletable(schema) { + return !!schema && typeof schema === 'object' && exports.COMPLETABLE_SYMBOL in schema; +} +/** + * Gets the completer callback from a completable schema, if it exists. + */ +function getCompleter(schema) { + const meta = schema[exports.COMPLETABLE_SYMBOL]; + return meta === null || meta === void 0 ? void 0 : meta.complete; +} +/** + * Unwraps a completable schema to get the underlying schema. + * For backward compatibility with code that called `.unwrap()`. + */ +function unwrapCompletable(schema) { + return schema; +} +// Legacy exports for backward compatibility +// These types are deprecated but kept for existing code +var McpZodTypeKind; +(function (McpZodTypeKind) { + McpZodTypeKind["Completable"] = "McpCompletable"; +})(McpZodTypeKind || (exports.McpZodTypeKind = McpZodTypeKind = {})); +//# sourceMappingURL=completable.js.map \ No newline at end of file diff --git a/dist/cjs/server/completable.js.map b/dist/cjs/server/completable.js.map new file mode 100644 index 000000000..728e58bdc --- /dev/null +++ b/dist/cjs/server/completable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"completable.js","sourceRoot":"","sources":["../../../src/server/completable.ts"],"names":[],"mappings":";;;AAuBA,kCAQC;AAKD,sCAEC;AAKD,oCAGC;AAMD,8CAEC;AApDY,QAAA,kBAAkB,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAiB/E;;;GAGG;AACH,SAAgB,WAAW,CAAsB,MAAS,EAAE,QAA6B;IACrF,MAAM,CAAC,cAAc,CAAC,MAAgB,EAAE,0BAAkB,EAAE;QACxD,KAAK,EAAE,EAAE,QAAQ,EAAwB;QACzC,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;KACtB,CAAC,CAAC;IACH,OAAO,MAA8B,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAe;IACzC,OAAO,CAAC,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,0BAAkB,IAAK,MAAiB,CAAC;AAC9F,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAsB,MAAS;IACvD,MAAM,IAAI,GAAI,MAAmE,CAAC,0BAAkB,CAAC,CAAC;IACtG,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAA2C,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAsB,MAA4B;IAC/E,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,4CAA4C;AAC5C,wDAAwD;AACxD,IAAY,cAEX;AAFD,WAAY,cAAc;IACtB,gDAA8B,CAAA;AAClC,CAAC,EAFW,cAAc,8BAAd,cAAc,QAEzB"} \ No newline at end of file diff --git a/dist/cjs/server/index.d.ts b/dist/cjs/server/index.d.ts new file mode 100644 index 000000000..e093d20eb --- /dev/null +++ b/dist/cjs/server/index.d.ts @@ -0,0 +1,358 @@ +import { Protocol, type NotificationOptions, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js'; +import { type ClientCapabilities, type CreateMessageRequest, type ElicitRequestFormParams, type ElicitRequestURLParams, type ElicitResult, type Implementation, type ListRootsRequest, type LoggingMessageNotification, type Notification, type Request, type ResourceUpdatedNotification, type Result, type ServerCapabilities, type ServerNotification, type ServerRequest, type ServerResult } from '../types.js'; +import type { jsonSchemaValidator } from '../validation/types.js'; +import { AnyObjectSchema, SchemaOutput } from './zod-compat.js'; +import { RequestHandlerExtra } from '../shared/protocol.js'; +import { ExperimentalServerTasks } from '../experimental/tasks/server.js'; +export type ServerOptions = ProtocolOptions & { + /** + * Capabilities to advertise as being supported by this server. + */ + capabilities?: ServerCapabilities; + /** + * Optional instructions describing how to use the server and its features. + */ + instructions?: string; + /** + * JSON Schema validator for elicitation response validation. + * + * The validator is used to validate user input returned from elicitation + * requests against the requested schema. + * + * @default AjvJsonSchemaValidator + * + * @example + * ```typescript + * // ajv (default) + * const server = new Server( + * { name: 'my-server', version: '1.0.0' }, + * { + * capabilities: {} + * jsonSchemaValidator: new AjvJsonSchemaValidator() + * } + * ); + * + * // @cfworker/json-schema + * const server = new Server( + * { name: 'my-server', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new CfWorkerJsonSchemaValidator() + * } + * ); + * ``` + */ + jsonSchemaValidator?: jsonSchemaValidator; +}; +/** + * An MCP server on top of a pluggable transport. + * + * This server will automatically respond to the initialization flow as initiated from the client. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed server + * const server = new Server({ + * name: "CustomServer", + * version: "1.0.0" + * }) + * ``` + * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases. + */ +export declare class Server extends Protocol { + private _serverInfo; + private _clientCapabilities?; + private _clientVersion?; + private _capabilities; + private _instructions?; + private _jsonSchemaValidator; + private _experimental?; + /** + * Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification). + */ + oninitialized?: () => void; + /** + * Initializes this server with the given name and version information. + */ + constructor(_serverInfo: Implementation, options?: ServerOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalServerTasks; + }; + private _loggingLevels; + private readonly LOG_LEVEL_SEVERITY; + private isMessageIgnored; + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities: ServerCapabilities): void; + /** + * Override request handler registration to enforce server-side validation for tools/call. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => ServerResult | ResultT | Promise): void; + protected assertCapabilityForMethod(method: RequestT['method']): void; + protected assertNotificationCapability(method: (ServerNotification | NotificationT)['method']): void; + protected assertRequestHandlerCapability(method: string): void; + protected assertTaskCapability(method: string): void; + protected assertTaskHandlerCapability(method: string): void; + private _oninitialize; + /** + * After initialization has completed, this will be populated with the client's reported capabilities. + */ + getClientCapabilities(): ClientCapabilities | undefined; + /** + * After initialization has completed, this will be populated with information about the client's name and version. + */ + getClientVersion(): Implementation | undefined; + private getCapabilities; + ping(): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + model: string; + role: "user" | "assistant"; + content: { + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + [x: string]: unknown; + type: "tool_use"; + name: string; + id: string; + input: { + [x: string]: unknown; + }; + _meta?: { + [x: string]: unknown; + } | undefined; + } | { + [x: string]: unknown; + type: "tool_result"; + toolUseId: string; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + structuredContent?: { + [x: string]: unknown; + } | undefined; + isError?: boolean | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + } | ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + [x: string]: unknown; + type: "tool_use"; + name: string; + id: string; + input: { + [x: string]: unknown; + }; + _meta?: { + [x: string]: unknown; + } | undefined; + } | { + [x: string]: unknown; + type: "tool_result"; + toolUseId: string; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + structuredContent?: { + [x: string]: unknown; + } | undefined; + isError?: boolean | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + stopReason?: string | undefined; + }>; + /** + * Creates an elicitation request for the given parameters. + * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`. + * @param params The parameters for the elicitation request. + * @param options Optional request options. + * @returns The result of the elicitation request. + */ + elicitInput(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise; + /** + * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete` + * notification for the specified elicitation ID. + * + * @param elicitationId The ID of the elicitation to mark as complete. + * @param options Optional notification options. Useful when the completion notification should be related to a prior request. + * @returns A function that emits the completion notification when awaited. + */ + createElicitationCompletionNotifier(elicitationId: string, options?: NotificationOptions): () => Promise; + listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + roots: { + uri: string; + name?: string | undefined; + _meta?: Record | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise; + sendResourceUpdated(params: ResourceUpdatedNotification['params']): Promise; + sendResourceListChanged(): Promise; + sendToolListChanged(): Promise; + sendPromptListChanged(): Promise; +} +export type { SessionStore, SessionData, SessionStorageMode } from './streamableHttp.js'; +export { RedisSessionStore, InMemorySessionStore } from './session-stores/redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './session-stores/redis.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/index.d.ts.map b/dist/cjs/server/index.d.ts.map new file mode 100644 index 000000000..2acfb7162 --- /dev/null +++ b/dist/cjs/server/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzI,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAIjB,KAAK,cAAc,EAMnB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server/index.js @@ -0,0 +1,452 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemorySessionStore = exports.RedisSessionStore = exports.Server = void 0; +const protocol_js_1 = require("../shared/protocol.js"); +const types_js_1 = require("../types.js"); +const ajv_provider_js_1 = require("../validation/ajv-provider.js"); +const zod_compat_js_1 = require("./zod-compat.js"); +const server_js_1 = require("../experimental/tasks/server.js"); +const helpers_js_1 = require("../experimental/tasks/helpers.js"); +/** + * An MCP server on top of a pluggable transport. + * + * This server will automatically respond to the initialization flow as initiated from the client. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed server + * const server = new Server({ + * name: "CustomServer", + * version: "1.0.0" + * }) + * ``` + * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases. + */ +class Server extends protocol_js_1.Protocol { + /** + * Initializes this server with the given name and version information. + */ + constructor(_serverInfo, options) { + var _a, _b; + super(options); + this._serverInfo = _serverInfo; + // Map log levels by session id + this._loggingLevels = new Map(); + // Map LogLevelSchema to severity index + this.LOG_LEVEL_SEVERITY = new Map(types_js_1.LoggingLevelSchema.options.map((level, index) => [level, index])); + // Is a message with the given level ignored in the log level set for the given session id? + this.isMessageIgnored = (level, sessionId) => { + const currentLevel = this._loggingLevels.get(sessionId); + return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false; + }; + this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {}; + this._instructions = options === null || options === void 0 ? void 0 : options.instructions; + this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new ajv_provider_js_1.AjvJsonSchemaValidator(); + this.setRequestHandler(types_js_1.InitializeRequestSchema, request => this._oninitialize(request)); + this.setNotificationHandler(types_js_1.InitializedNotificationSchema, () => { var _a; return (_a = this.oninitialized) === null || _a === void 0 ? void 0 : _a.call(this); }); + if (this._capabilities.logging) { + this.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request, extra) => { + var _a; + const transportSessionId = extra.sessionId || ((_a = extra.requestInfo) === null || _a === void 0 ? void 0 : _a.headers['mcp-session-id']) || undefined; + const { level } = request.params; + const parseResult = types_js_1.LoggingLevelSchema.safeParse(level); + if (parseResult.success) { + this._loggingLevels.set(transportSessionId, parseResult.data); + } + return {}; + }); + } + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new server_js_1.ExperimentalServerTasks(this) + }; + } + return this._experimental; + } + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities) { + if (this.transport) { + throw new Error('Cannot register capabilities after connecting to transport'); + } + this._capabilities = (0, protocol_js_1.mergeCapabilities)(this._capabilities, capabilities); + } + /** + * Override request handler registration to enforce server-side validation for tools/call. + */ + setRequestHandler(requestSchema, handler) { + var _a, _b, _c; + const shape = (0, zod_compat_js_1.getObjectShape)(requestSchema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value using type-safe property access + let methodValue; + if ((0, zod_compat_js_1.isZ4Schema)(methodSchema)) { + const v4Schema = methodSchema; + const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + methodValue = (_b = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b !== void 0 ? _b : v4Schema.value; + } + else { + const v3Schema = methodSchema; + const legacyDef = v3Schema._def; + methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value; + } + if (typeof methodValue !== 'string') { + throw new Error('Schema method literal must be a string'); + } + const method = methodValue; + if (method === 'tools/call') { + const wrappedHandler = async (request, extra) => { + const validatedRequest = (0, zod_compat_js_1.safeParse)(types_js_1.CallToolRequestSchema, request); + if (!validatedRequest.success) { + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = (0, zod_compat_js_1.safeParse)(types_js_1.CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against CallToolResultSchema + const validationResult = (0, zod_compat_js_1.safeParse)(types_js_1.CallToolResultSchema, result); + if (!validationResult.success) { + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`); + } + return validationResult.data; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + // Other handlers use default behavior + return super.setRequestHandler(requestSchema, handler); + } + assertCapabilityForMethod(method) { + var _a, _b, _c; + switch (method) { + case 'sampling/createMessage': + if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) { + throw new Error(`Client does not support sampling (required for ${method})`); + } + break; + case 'elicitation/create': + if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) { + throw new Error(`Client does not support elicitation (required for ${method})`); + } + break; + case 'roots/list': + if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) { + throw new Error(`Client does not support listing roots (required for ${method})`); + } + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertNotificationCapability(method) { + var _a, _b; + switch (method) { + case 'notifications/message': + if (!this._capabilities.logging) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'notifications/resources/updated': + case 'notifications/resources/list_changed': + if (!this._capabilities.resources) { + throw new Error(`Server does not support notifying about resources (required for ${method})`); + } + break; + case 'notifications/tools/list_changed': + if (!this._capabilities.tools) { + throw new Error(`Server does not support notifying of tool list changes (required for ${method})`); + } + break; + case 'notifications/prompts/list_changed': + if (!this._capabilities.prompts) { + throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`); + } + break; + case 'notifications/elicitation/complete': + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) { + throw new Error(`Client does not support URL elicitation (required for ${method})`); + } + break; + case 'notifications/cancelled': + // Cancellation notifications are always allowed + break; + case 'notifications/progress': + // Progress notifications are always allowed + break; + } + } + assertRequestHandlerCapability(method) { + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + switch (method) { + case 'completion/complete': + if (!this._capabilities.completions) { + throw new Error(`Server does not support completions (required for ${method})`); + } + break; + case 'logging/setLevel': + if (!this._capabilities.logging) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'prompts/get': + case 'prompts/list': + if (!this._capabilities.prompts) { + throw new Error(`Server does not support prompts (required for ${method})`); + } + break; + case 'resources/list': + case 'resources/templates/list': + case 'resources/read': + if (!this._capabilities.resources) { + throw new Error(`Server does not support resources (required for ${method})`); + } + break; + case 'tools/call': + case 'tools/list': + if (!this._capabilities.tools) { + throw new Error(`Server does not support tools (required for ${method})`); + } + break; + case 'tasks/get': + case 'tasks/list': + case 'tasks/result': + case 'tasks/cancel': + if (!this._capabilities.tasks) { + throw new Error(`Server does not support tasks capability (required for ${method})`); + } + break; + case 'ping': + case 'initialize': + // No specific capability required for these methods + break; + } + } + assertTaskCapability(method) { + var _a, _b; + (0, helpers_js_1.assertClientRequestTaskCapability)((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests, method, 'Client'); + } + assertTaskHandlerCapability(method) { + var _a; + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + (0, helpers_js_1.assertToolsCallTaskCapability)((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, 'Server'); + } + async _oninitialize(request) { + const requestedVersion = request.params.protocolVersion; + this._clientCapabilities = request.params.capabilities; + this._clientVersion = request.params.clientInfo; + const protocolVersion = types_js_1.SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : types_js_1.LATEST_PROTOCOL_VERSION; + return { + protocolVersion, + capabilities: this.getCapabilities(), + serverInfo: this._serverInfo, + ...(this._instructions && { instructions: this._instructions }) + }; + } + /** + * After initialization has completed, this will be populated with the client's reported capabilities. + */ + getClientCapabilities() { + return this._clientCapabilities; + } + /** + * After initialization has completed, this will be populated with information about the client's name and version. + */ + getClientVersion() { + return this._clientVersion; + } + getCapabilities() { + return this._capabilities; + } + async ping() { + return this.request({ method: 'ping' }, types_js_1.EmptyResultSchema); + } + async createMessage(params, options) { + var _a, _b; + // Capability check - only required when tools/toolChoice are provided + if (params.tools || params.toolChoice) { + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling) === null || _b === void 0 ? void 0 : _b.tools)) { + throw new Error('Client does not support sampling tools capability.'); + } + } + // Message structure validation - always validate tool_use/tool_result pairs. + // These may appear even without tools/toolChoice in the current request when + // a previous sampling request returned tool_use and this is a follow-up with results. + if (params.messages.length > 0) { + const lastMessage = params.messages[params.messages.length - 1]; + const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content]; + const hasToolResults = lastContent.some(c => c.type === 'tool_result'); + const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : undefined; + const previousContent = previousMessage + ? Array.isArray(previousMessage.content) + ? previousMessage.content + : [previousMessage.content] + : []; + const hasPreviousToolUse = previousContent.some(c => c.type === 'tool_use'); + if (hasToolResults) { + if (lastContent.some(c => c.type !== 'tool_result')) { + throw new Error('The last message must contain only tool_result content if any is present'); + } + if (!hasPreviousToolUse) { + throw new Error('tool_result blocks are not matching any tool_use from the previous message'); + } + } + if (hasPreviousToolUse) { + const toolUseIds = new Set(previousContent.filter(c => c.type === 'tool_use').map(c => c.id)); + const toolResultIds = new Set(lastContent.filter(c => c.type === 'tool_result').map(c => c.toolUseId)); + if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every(id => toolResultIds.has(id))) { + throw new Error('ids of tool_result blocks and tool_use blocks from previous message do not match'); + } + } + } + return this.request({ method: 'sampling/createMessage', params }, types_js_1.CreateMessageResultSchema, options); + } + /** + * Creates an elicitation request for the given parameters. + * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`. + * @param params The parameters for the elicitation request. + * @param options Optional request options. + * @returns The result of the elicitation request. + */ + async elicitInput(params, options) { + var _a, _b, _c, _d, _e; + const mode = ((_a = params.mode) !== null && _a !== void 0 ? _a : 'form'); + switch (mode) { + case 'url': { + if (!((_c = (_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation) === null || _c === void 0 ? void 0 : _c.url)) { + throw new Error('Client does not support url elicitation.'); + } + const urlParams = params; + return this.request({ method: 'elicitation/create', params: urlParams }, types_js_1.ElicitResultSchema, options); + } + case 'form': { + if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) { + throw new Error('Client does not support form elicitation.'); + } + const formParams = params.mode === 'form' ? params : { ...params, mode: 'form' }; + const result = await this.request({ method: 'elicitation/create', params: formParams }, types_js_1.ElicitResultSchema, options); + if (result.action === 'accept' && result.content && formParams.requestedSchema) { + try { + const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema); + const validationResult = validator(result.content); + if (!validationResult.valid) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`); + } + } + catch (error) { + if (error instanceof types_js_1.McpError) { + throw error; + } + throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`); + } + } + return result; + } + } + } + /** + * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete` + * notification for the specified elicitation ID. + * + * @param elicitationId The ID of the elicitation to mark as complete. + * @param options Optional notification options. Useful when the completion notification should be related to a prior request. + * @returns A function that emits the completion notification when awaited. + */ + createElicitationCompletionNotifier(elicitationId, options) { + var _a, _b; + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) { + throw new Error('Client does not support URL elicitation (required for notifications/elicitation/complete)'); + } + return () => this.notification({ + method: 'notifications/elicitation/complete', + params: { + elicitationId + } + }, options); + } + async listRoots(params, options) { + return this.request({ method: 'roots/list', params }, types_js_1.ListRootsResultSchema, options); + } + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + async sendLoggingMessage(params, sessionId) { + if (this._capabilities.logging) { + if (!this.isMessageIgnored(params.level, sessionId)) { + return this.notification({ method: 'notifications/message', params }); + } + } + } + async sendResourceUpdated(params) { + return this.notification({ + method: 'notifications/resources/updated', + params + }); + } + async sendResourceListChanged() { + return this.notification({ + method: 'notifications/resources/list_changed' + }); + } + async sendToolListChanged() { + return this.notification({ method: 'notifications/tools/list_changed' }); + } + async sendPromptListChanged() { + return this.notification({ method: 'notifications/prompts/list_changed' }); + } +} +exports.Server = Server; +var redis_js_1 = require("./session-stores/redis.js"); +Object.defineProperty(exports, "RedisSessionStore", { enumerable: true, get: function () { return redis_js_1.RedisSessionStore; } }); +Object.defineProperty(exports, "InMemorySessionStore", { enumerable: true, get: function () { return redis_js_1.InMemorySessionStore; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/server/index.js.map b/dist/cjs/server/index.js.map new file mode 100644 index 000000000..e9d6c81db --- /dev/null +++ b/dist/cjs/server/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":";;;AAAA,uDAAyI;AACzI,0CAqCqB;AACrB,mEAAuE;AAEvE,mDAQyB;AAEzB,+DAA0E;AAC1E,iEAAoH;AA6CpH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,MAIX,SAAQ,sBAA8F;IAapG;;OAEG;IACH,YACY,WAA2B,EACnC,OAAuB;;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHP,gBAAW,GAAX,WAAW,CAAgB;QAyCvC,+BAA+B;QACvB,mBAAc,GAAG,IAAI,GAAG,EAAoC,CAAC;QAErE,uCAAuC;QACtB,uBAAkB,GAAG,IAAI,GAAG,CAAC,6BAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAEhH,2FAA2F;QACnF,qBAAgB,GAAG,CAAC,KAAmB,EAAE,SAAkB,EAAW,EAAE;YAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACxD,OAAO,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC,CAAC,CAAC,K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CAAkC,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,qBAAqB;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,oCAAoC,EAAE,CAAC,CAAC;IAC/E,CAAC;CACJ;AA/fD,wBA+fC;AAID,sDAAoF;AAA3E,6GAAA,iBAAiB,OAAA;AAAE,gHAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/cjs/server/mcp.d.ts b/dist/cjs/server/mcp.d.ts new file mode 100644 index 000000000..1bc0c6829 --- /dev/null +++ b/dist/cjs/server/mcp.d.ts @@ -0,0 +1,364 @@ +import { Server, ServerOptions } from './index.js'; +import { AnySchema, AnyObjectSchema, ZodRawShapeCompat, SchemaOutput, ShapeOutput } from './zod-compat.js'; +import { Implementation, CallToolResult, Resource, ListResourcesResult, GetPromptResult, ReadResourceResult, ServerRequest, ServerNotification, ToolAnnotations, LoggingMessageNotification, Result, ToolExecution } from '../types.js'; +import { UriTemplate, Variables } from '../shared/uriTemplate.js'; +import { RequestHandlerExtra } from '../shared/protocol.js'; +import { Transport } from '../shared/transport.js'; +import { ExperimentalMcpServerTasks } from '../experimental/tasks/mcp-server.js'; +import type { ToolTaskHandler } from '../experimental/tasks/interfaces.js'; +/** + * High-level MCP server that provides a simpler API for working with resources, tools, and prompts. + * For advanced usage (like sending notifications or setting custom request handlers), use the underlying + * Server instance available via the `server` property. + */ +export declare class McpServer { + /** + * The underlying Server instance, useful for advanced operations like sending notifications. + */ + readonly server: Server; + private _registeredResources; + private _registeredResourceTemplates; + private _registeredTools; + private _registeredPrompts; + private _experimental?; + constructor(serverInfo: Implementation, options?: ServerOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalMcpServerTasks; + }; + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + connect(transport: Transport): Promise; + /** + * Closes the connection. + */ + close(): Promise; + private _toolHandlersInitialized; + private setToolRequestHandlers; + /** + * Creates a tool error result. + * + * @param errorMessage - The error message. + * @returns The tool error result. + */ + private createToolError; + /** + * Validates tool input arguments against the tool's input schema. + */ + private validateToolInput; + /** + * Validates tool output against the tool's output schema. + */ + private validateToolOutput; + /** + * Executes a tool handler (either regular or task-based). + */ + private executeToolHandler; + /** + * Handles automatic task polling for tools with taskSupport 'optional'. + */ + private handleAutomaticTaskPolling; + private _completionHandlerInitialized; + private setCompletionRequestHandler; + private handlePromptCompletion; + private handleResourceCompletion; + private _resourceHandlersInitialized; + private setResourceRequestHandlers; + private _promptHandlersInitialized; + private setPromptRequestHandlers; + /** + * Registers a resource `name` at a fixed URI, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, uri: string, readCallback: ReadResourceCallback): RegisteredResource; + /** + * Registers a resource `name` at a fixed URI with metadata, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, uri: string, metadata: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; + /** + * Registers a resource `name` with a template pattern, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, template: ResourceTemplate, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + /** + * Registers a resource `name` with a template pattern and metadata, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, template: ResourceTemplate, metadata: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + /** + * Registers a resource with a config object and callback. + * For static resources, use a URI string. For dynamic resources, use a ResourceTemplate. + */ + registerResource(name: string, uriOrTemplate: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; + registerResource(name: string, uriOrTemplate: ResourceTemplate, config: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + private _createRegisteredResource; + private _createRegisteredResourceTemplate; + private _createRegisteredPrompt; + private _createRegisteredTool; + /** + * Registers a zero-argument tool `name`, which will run the given function when the client calls it. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, cb: ToolCallback): RegisteredTool; + /** + * Registers a zero-argument tool `name` (with a description) which will run the given function when the client calls it. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool taking either a parameter schema for validation or annotations for additional metadata. + * This unified overload handles both `tool(name, paramsSchema, cb)` and `tool(name, annotations, cb)` cases. + * + * Note: We use a union type for the second parameter because TypeScript cannot reliably disambiguate + * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool `name` (with a description) taking either parameter schema or annotations. + * This unified overload handles both `tool(name, description, paramsSchema, cb)` and + * `tool(name, description, annotations, cb)` cases. + * + * Note: We use a union type for the third parameter because TypeScript cannot reliably disambiguate + * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with both parameter schema and annotations. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with description, parameter schema, and annotations. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with a config object and callback. + */ + registerTool(name: string, config: { + title?: string; + description?: string; + inputSchema?: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + _meta?: Record; + }, cb: ToolCallback): RegisteredTool; + /** + * Registers a zero-argument prompt `name`, which will run the given function when the client calls it. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a zero-argument prompt `name` (with a description) which will run the given function when the client calls it. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, description: string, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, argsSchema: Args, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, description: string, argsSchema: Args, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt with a config object and callback. + */ + registerPrompt(name: string, config: { + title?: string; + description?: string; + argsSchema?: Args; + }, cb: PromptCallback): RegisteredPrompt; + /** + * Checks if the server is connected to a transport. + * @returns True if the server is connected + */ + isConnected(): boolean; + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise; + /** + * Sends a resource list changed event to the client, if connected. + */ + sendResourceListChanged(): void; + /** + * Sends a tool list changed event to the client, if connected. + */ + sendToolListChanged(): void; + /** + * Sends a prompt list changed event to the client, if connected. + */ + sendPromptListChanged(): void; +} +/** + * A callback to complete one variable within a resource template's URI template. + */ +export type CompleteResourceTemplateCallback = (value: string, context?: { + arguments?: Record; +}) => string[] | Promise; +/** + * A resource template combines a URI pattern with optional functionality to enumerate + * all resources matching that pattern. + */ +export declare class ResourceTemplate { + private _callbacks; + private _uriTemplate; + constructor(uriTemplate: string | UriTemplate, _callbacks: { + /** + * A callback to list all resources matching this template. This is required to specified, even if `undefined`, to avoid accidentally forgetting resource listing. + */ + list: ListResourcesCallback | undefined; + /** + * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values. + */ + complete?: { + [variable: string]: CompleteResourceTemplateCallback; + }; + }); + /** + * Gets the URI template pattern. + */ + get uriTemplate(): UriTemplate; + /** + * Gets the list callback, if one was provided. + */ + get listCallback(): ListResourcesCallback | undefined; + /** + * Gets the callback for completing a specific URI template variable, if one was provided. + */ + completeCallback(variable: string): CompleteResourceTemplateCallback | undefined; +} +export type BaseToolCallback, Args extends undefined | ZodRawShapeCompat | AnySchema> = Args extends ZodRawShapeCompat ? (args: ShapeOutput, extra: Extra) => SendResultT | Promise : Args extends AnySchema ? (args: SchemaOutput, extra: Extra) => SendResultT | Promise : (extra: Extra) => SendResultT | Promise; +/** + * Callback for a tool handler registered with Server.tool(). + * + * Parameters will include tool arguments, if applicable, as well as other request handler context. + * + * The callback should return: + * - `structuredContent` if the tool has an outputSchema defined + * - `content` if the tool does not have an outputSchema + * - Both fields are optional but typically one should be provided + */ +export type ToolCallback = BaseToolCallback, Args>; +/** + * Supertype that can handle both regular tools (simple callback) and task-based tools (task handler object). + */ +export type AnyToolHandler = ToolCallback | ToolTaskHandler; +export type RegisteredTool = { + title?: string; + description?: string; + inputSchema?: AnySchema; + outputSchema?: AnySchema; + annotations?: ToolAnnotations; + execution?: ToolExecution; + _meta?: Record; + handler: AnyToolHandler; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + description?: string; + paramsSchema?: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + _meta?: Record; + callback?: ToolCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +/** + * Additional, optional information for annotating a resource. + */ +export type ResourceMetadata = Omit; +/** + * Callback to list all resources matching a given template. + */ +export type ListResourcesCallback = (extra: RequestHandlerExtra) => ListResourcesResult | Promise; +/** + * Callback to read a resource at a given URI. + */ +export type ReadResourceCallback = (uri: URL, extra: RequestHandlerExtra) => ReadResourceResult | Promise; +export type RegisteredResource = { + name: string; + title?: string; + metadata?: ResourceMetadata; + readCallback: ReadResourceCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string; + title?: string; + uri?: string | null; + metadata?: ResourceMetadata; + callback?: ReadResourceCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +/** + * Callback to read a resource at a given URI, following a filled-in URI template. + */ +export type ReadResourceTemplateCallback = (uri: URL, variables: Variables, extra: RequestHandlerExtra) => ReadResourceResult | Promise; +export type RegisteredResourceTemplate = { + resourceTemplate: ResourceTemplate; + title?: string; + metadata?: ResourceMetadata; + readCallback: ReadResourceTemplateCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + template?: ResourceTemplate; + metadata?: ResourceMetadata; + callback?: ReadResourceTemplateCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +type PromptArgsRawShape = ZodRawShapeCompat; +export type PromptCallback = Args extends PromptArgsRawShape ? (args: ShapeOutput, extra: RequestHandlerExtra) => GetPromptResult | Promise : (extra: RequestHandlerExtra) => GetPromptResult | Promise; +export type RegisteredPrompt = { + title?: string; + description?: string; + argsSchema?: AnyObjectSchema; + callback: PromptCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + description?: string; + argsSchema?: Args; + callback?: PromptCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +export {}; +//# sourceMappingURL=mcp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/mcp.d.ts.map b/dist/cjs/server/mcp.d.ts.map new file mode 100644 index 000000000..d5815c38a --- /dev/null +++ b/dist/cjs/server/mcp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACH,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,WAAW,EASd,MAAM,iBAAiB,CAAC;AAEzB,OAAO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AAc,CAAC,SAAS,GAAG,kBAAkB,CAAC,CAAC;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,MAAM,CAAC,IAAI,SAAS,kBAAkB,EAAE,OAAO,EAAE;QAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,IAAI,CAAC;QAClB,QAAQ,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,IAAI,CAAC;IACT,MAAM,IAAI,IAAI,CAAC;CAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/mcp.js b/dist/cjs/server/mcp.js new file mode 100644 index 000000000..c7cbf1bc6 --- /dev/null +++ b/dist/cjs/server/mcp.js @@ -0,0 +1,875 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ResourceTemplate = exports.McpServer = void 0; +const index_js_1 = require("./index.js"); +const zod_compat_js_1 = require("./zod-compat.js"); +const zod_json_schema_compat_js_1 = require("./zod-json-schema-compat.js"); +const types_js_1 = require("../types.js"); +const completable_js_1 = require("./completable.js"); +const uriTemplate_js_1 = require("../shared/uriTemplate.js"); +const toolNameValidation_js_1 = require("../shared/toolNameValidation.js"); +const mcp_server_js_1 = require("../experimental/tasks/mcp-server.js"); +/** + * High-level MCP server that provides a simpler API for working with resources, tools, and prompts. + * For advanced usage (like sending notifications or setting custom request handlers), use the underlying + * Server instance available via the `server` property. + */ +class McpServer { + constructor(serverInfo, options) { + this._registeredResources = {}; + this._registeredResourceTemplates = {}; + this._registeredTools = {}; + this._registeredPrompts = {}; + this._toolHandlersInitialized = false; + this._completionHandlerInitialized = false; + this._resourceHandlersInitialized = false; + this._promptHandlersInitialized = false; + this.server = new index_js_1.Server(serverInfo, options); + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new mcp_server_js_1.ExperimentalMcpServerTasks(this) + }; + } + return this._experimental; + } + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + async connect(transport) { + return await this.server.connect(transport); + } + /** + * Closes the connection. + */ + async close() { + await this.server.close(); + } + setToolRequestHandlers() { + if (this._toolHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.ListToolsRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.CallToolRequestSchema)); + this.server.registerCapabilities({ + tools: { + listChanged: true + } + }); + this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, () => ({ + tools: Object.entries(this._registeredTools) + .filter(([, tool]) => tool.enabled) + .map(([name, tool]) => { + const toolDefinition = { + name, + title: tool.title, + description: tool.description, + inputSchema: (() => { + const obj = (0, zod_compat_js_1.normalizeObjectSchema)(tool.inputSchema); + return obj + ? (0, zod_json_schema_compat_js_1.toJsonSchemaCompat)(obj, { + strictUnions: true, + pipeStrategy: 'input' + }) + : EMPTY_OBJECT_JSON_SCHEMA; + })(), + annotations: tool.annotations, + execution: tool.execution, + _meta: tool._meta + }; + if (tool.outputSchema) { + const obj = (0, zod_compat_js_1.normalizeObjectSchema)(tool.outputSchema); + if (obj) { + toolDefinition.outputSchema = (0, zod_json_schema_compat_js_1.toJsonSchemaCompat)(obj, { + strictUnions: true, + pipeStrategy: 'output' + }); + } + } + return toolDefinition; + }) + })); + this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request, extra) => { + var _a; + try { + const tool = this._registeredTools[request.params.name]; + if (!tool) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Tool ${request.params.name} not found`); + } + if (!tool.enabled) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`); + } + const isTaskRequest = !!request.params.task; + const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport; + const isTaskHandler = 'createTask' in tool.handler; + // Validate task hint configuration + if ((taskSupport === 'required' || taskSupport === 'optional') && !isTaskHandler) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`); + } + // Handle taskSupport 'required' without task augmentation + if (taskSupport === 'required' && !isTaskRequest) { + throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`); + } + // Handle taskSupport 'optional' without task augmentation - automatic polling + if (taskSupport === 'optional' && !isTaskRequest && isTaskHandler) { + return await this.handleAutomaticTaskPolling(tool, request, extra); + } + // Normal execution path + const args = await this.validateToolInput(tool, request.params.arguments, request.params.name); + const result = await this.executeToolHandler(tool, args, extra); + // Return CreateTaskResult immediately for task requests + if (isTaskRequest) { + return result; + } + // Validate output schema for non-task requests + await this.validateToolOutput(tool, result, request.params.name); + return result; + } + catch (error) { + if (error instanceof types_js_1.McpError) { + if (error.code === types_js_1.ErrorCode.UrlElicitationRequired) { + throw error; // Return the error to the caller without wrapping in CallToolResult + } + } + return this.createToolError(error instanceof Error ? error.message : String(error)); + } + }); + this._toolHandlersInitialized = true; + } + /** + * Creates a tool error result. + * + * @param errorMessage - The error message. + * @returns The tool error result. + */ + createToolError(errorMessage) { + return { + content: [ + { + type: 'text', + text: errorMessage + } + ], + isError: true + }; + } + /** + * Validates tool input arguments against the tool's input schema. + */ + async validateToolInput(tool, args, toolName) { + if (!tool.inputSchema) { + return undefined; + } + // Try to normalize to object schema first (for raw shapes and object schemas) + // If that fails, use the schema directly (for union/intersection/etc) + const inputObj = (0, zod_compat_js_1.normalizeObjectSchema)(tool.inputSchema); + const schemaToParse = inputObj !== null && inputObj !== void 0 ? inputObj : tool.inputSchema; + const parseResult = await (0, zod_compat_js_1.safeParseAsync)(schemaToParse, args); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = (0, zod_compat_js_1.getParseErrorMessage)(error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`); + } + return parseResult.data; + } + /** + * Validates tool output against the tool's output schema. + */ + async validateToolOutput(tool, result, toolName) { + if (!tool.outputSchema) { + return; + } + // Only validate CallToolResult, not CreateTaskResult + if (!('content' in result)) { + return; + } + if (result.isError) { + return; + } + if (!result.structuredContent) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`); + } + // if the tool has an output schema, validate structured content + const outputObj = (0, zod_compat_js_1.normalizeObjectSchema)(tool.outputSchema); + const parseResult = await (0, zod_compat_js_1.safeParseAsync)(outputObj, result.structuredContent); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = (0, zod_compat_js_1.getParseErrorMessage)(error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`); + } + } + /** + * Executes a tool handler (either regular or task-based). + */ + async executeToolHandler(tool, args, extra) { + const handler = tool.handler; + const isTaskHandler = 'createTask' in handler; + if (isTaskHandler) { + if (!extra.taskStore) { + throw new Error('No task store provided.'); + } + const taskExtra = { ...extra, taskStore: extra.taskStore }; + if (tool.inputSchema) { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler.createTask(args, taskExtra)); + } + else { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler.createTask(taskExtra)); + } + } + if (tool.inputSchema) { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler(args, extra)); + } + else { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler(extra)); + } + } + /** + * Handles automatic task polling for tools with taskSupport 'optional'. + */ + async handleAutomaticTaskPolling(tool, request, extra) { + var _a; + if (!extra.taskStore) { + throw new Error('No task store provided for task-capable tool.'); + } + // Validate input and create task + const args = await this.validateToolInput(tool, request.params.arguments, request.params.name); + const handler = tool.handler; + const taskExtra = { ...extra, taskStore: extra.taskStore }; + const createTaskResult = args // undefined only if tool.inputSchema is undefined + ? await Promise.resolve(handler.createTask(args, taskExtra)) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any + await Promise.resolve(handler.createTask(taskExtra)); + // Poll until completion + const taskId = createTaskResult.task.taskId; + let task = createTaskResult.task; + const pollInterval = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : 5000; + while (task.status !== 'completed' && task.status !== 'failed' && task.status !== 'cancelled') { + await new Promise(resolve => setTimeout(resolve, pollInterval)); + const updatedTask = await extra.taskStore.getTask(taskId); + if (!updatedTask) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Task ${taskId} not found during polling`); + } + task = updatedTask; + } + // Return the final result + return (await extra.taskStore.getTaskResult(taskId)); + } + setCompletionRequestHandler() { + if (this._completionHandlerInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.CompleteRequestSchema)); + this.server.registerCapabilities({ + completions: {} + }); + this.server.setRequestHandler(types_js_1.CompleteRequestSchema, async (request) => { + switch (request.params.ref.type) { + case 'ref/prompt': + (0, types_js_1.assertCompleteRequestPrompt)(request); + return this.handlePromptCompletion(request, request.params.ref); + case 'ref/resource': + (0, types_js_1.assertCompleteRequestResourceTemplate)(request); + return this.handleResourceCompletion(request, request.params.ref); + default: + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`); + } + }); + this._completionHandlerInitialized = true; + } + async handlePromptCompletion(request, ref) { + const prompt = this._registeredPrompts[ref.name]; + if (!prompt) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt ${ref.name} not found`); + } + if (!prompt.enabled) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt ${ref.name} disabled`); + } + if (!prompt.argsSchema) { + return EMPTY_COMPLETION_RESULT; + } + const promptShape = (0, zod_compat_js_1.getObjectShape)(prompt.argsSchema); + const field = promptShape === null || promptShape === void 0 ? void 0 : promptShape[request.params.argument.name]; + if (!(0, completable_js_1.isCompletable)(field)) { + return EMPTY_COMPLETION_RESULT; + } + const completer = (0, completable_js_1.getCompleter)(field); + if (!completer) { + return EMPTY_COMPLETION_RESULT; + } + const suggestions = await completer(request.params.argument.value, request.params.context); + return createCompletionResult(suggestions); + } + async handleResourceCompletion(request, ref) { + const template = Object.values(this._registeredResourceTemplates).find(t => t.resourceTemplate.uriTemplate.toString() === ref.uri); + if (!template) { + if (this._registeredResources[ref.uri]) { + // Attempting to autocomplete a fixed resource URI is not an error in the spec (but probably should be). + return EMPTY_COMPLETION_RESULT; + } + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`); + } + const completer = template.resourceTemplate.completeCallback(request.params.argument.name); + if (!completer) { + return EMPTY_COMPLETION_RESULT; + } + const suggestions = await completer(request.params.argument.value, request.params.context); + return createCompletionResult(suggestions); + } + setResourceRequestHandlers() { + if (this._resourceHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.ListResourcesRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.ListResourceTemplatesRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.ReadResourceRequestSchema)); + this.server.registerCapabilities({ + resources: { + listChanged: true + } + }); + this.server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async (request, extra) => { + const resources = Object.entries(this._registeredResources) + .filter(([_, resource]) => resource.enabled) + .map(([uri, resource]) => ({ + uri, + name: resource.name, + ...resource.metadata + })); + const templateResources = []; + for (const template of Object.values(this._registeredResourceTemplates)) { + if (!template.resourceTemplate.listCallback) { + continue; + } + const result = await template.resourceTemplate.listCallback(extra); + for (const resource of result.resources) { + templateResources.push({ + ...template.metadata, + // the defined resource metadata should override the template metadata if present + ...resource + }); + } + } + return { resources: [...resources, ...templateResources] }; + }); + this.server.setRequestHandler(types_js_1.ListResourceTemplatesRequestSchema, async () => { + const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({ + name, + uriTemplate: template.resourceTemplate.uriTemplate.toString(), + ...template.metadata + })); + return { resourceTemplates }; + }); + this.server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request, extra) => { + const uri = new URL(request.params.uri); + // First check for exact resource match + const resource = this._registeredResources[uri.toString()]; + if (resource) { + if (!resource.enabled) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Resource ${uri} disabled`); + } + return resource.readCallback(uri, extra); + } + // Then check templates + for (const template of Object.values(this._registeredResourceTemplates)) { + const variables = template.resourceTemplate.uriTemplate.match(uri.toString()); + if (variables) { + return template.readCallback(uri, variables, extra); + } + } + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Resource ${uri} not found`); + }); + this.setCompletionRequestHandler(); + this._resourceHandlersInitialized = true; + } + setPromptRequestHandlers() { + if (this._promptHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.ListPromptsRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(types_js_1.GetPromptRequestSchema)); + this.server.registerCapabilities({ + prompts: { + listChanged: true + } + }); + this.server.setRequestHandler(types_js_1.ListPromptsRequestSchema, () => ({ + prompts: Object.entries(this._registeredPrompts) + .filter(([, prompt]) => prompt.enabled) + .map(([name, prompt]) => { + return { + name, + title: prompt.title, + description: prompt.description, + arguments: prompt.argsSchema ? promptArgumentsFromSchema(prompt.argsSchema) : undefined + }; + }) + })); + this.server.setRequestHandler(types_js_1.GetPromptRequestSchema, async (request, extra) => { + const prompt = this._registeredPrompts[request.params.name]; + if (!prompt) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt ${request.params.name} not found`); + } + if (!prompt.enabled) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`); + } + if (prompt.argsSchema) { + const argsObj = (0, zod_compat_js_1.normalizeObjectSchema)(prompt.argsSchema); + const parseResult = await (0, zod_compat_js_1.safeParseAsync)(argsObj, request.params.arguments); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = (0, zod_compat_js_1.getParseErrorMessage)(error); + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`); + } + const args = parseResult.data; + const cb = prompt.callback; + return await Promise.resolve(cb(args, extra)); + } + else { + const cb = prompt.callback; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(cb(extra)); + } + }); + this.setCompletionRequestHandler(); + this._promptHandlersInitialized = true; + } + resource(name, uriOrTemplate, ...rest) { + let metadata; + if (typeof rest[0] === 'object') { + metadata = rest.shift(); + } + const readCallback = rest[0]; + if (typeof uriOrTemplate === 'string') { + if (this._registeredResources[uriOrTemplate]) { + throw new Error(`Resource ${uriOrTemplate} is already registered`); + } + const registeredResource = this._createRegisteredResource(name, undefined, uriOrTemplate, metadata, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResource; + } + else { + if (this._registeredResourceTemplates[name]) { + throw new Error(`Resource template ${name} is already registered`); + } + const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, undefined, uriOrTemplate, metadata, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResourceTemplate; + } + } + registerResource(name, uriOrTemplate, config, readCallback) { + if (typeof uriOrTemplate === 'string') { + if (this._registeredResources[uriOrTemplate]) { + throw new Error(`Resource ${uriOrTemplate} is already registered`); + } + const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, config, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResource; + } + else { + if (this._registeredResourceTemplates[name]) { + throw new Error(`Resource template ${name} is already registered`); + } + const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, config, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResourceTemplate; + } + } + _createRegisteredResource(name, title, uri, metadata, readCallback) { + const registeredResource = { + name, + title, + metadata, + readCallback, + enabled: true, + disable: () => registeredResource.update({ enabled: false }), + enable: () => registeredResource.update({ enabled: true }), + remove: () => registeredResource.update({ uri: null }), + update: updates => { + if (typeof updates.uri !== 'undefined' && updates.uri !== uri) { + delete this._registeredResources[uri]; + if (updates.uri) + this._registeredResources[updates.uri] = registeredResource; + } + if (typeof updates.name !== 'undefined') + registeredResource.name = updates.name; + if (typeof updates.title !== 'undefined') + registeredResource.title = updates.title; + if (typeof updates.metadata !== 'undefined') + registeredResource.metadata = updates.metadata; + if (typeof updates.callback !== 'undefined') + registeredResource.readCallback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredResource.enabled = updates.enabled; + this.sendResourceListChanged(); + } + }; + this._registeredResources[uri] = registeredResource; + return registeredResource; + } + _createRegisteredResourceTemplate(name, title, template, metadata, readCallback) { + const registeredResourceTemplate = { + resourceTemplate: template, + title, + metadata, + readCallback, + enabled: true, + disable: () => registeredResourceTemplate.update({ enabled: false }), + enable: () => registeredResourceTemplate.update({ enabled: true }), + remove: () => registeredResourceTemplate.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + delete this._registeredResourceTemplates[name]; + if (updates.name) + this._registeredResourceTemplates[updates.name] = registeredResourceTemplate; + } + if (typeof updates.title !== 'undefined') + registeredResourceTemplate.title = updates.title; + if (typeof updates.template !== 'undefined') + registeredResourceTemplate.resourceTemplate = updates.template; + if (typeof updates.metadata !== 'undefined') + registeredResourceTemplate.metadata = updates.metadata; + if (typeof updates.callback !== 'undefined') + registeredResourceTemplate.readCallback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredResourceTemplate.enabled = updates.enabled; + this.sendResourceListChanged(); + } + }; + this._registeredResourceTemplates[name] = registeredResourceTemplate; + return registeredResourceTemplate; + } + _createRegisteredPrompt(name, title, description, argsSchema, callback) { + const registeredPrompt = { + title, + description, + argsSchema: argsSchema === undefined ? undefined : (0, zod_compat_js_1.objectFromShape)(argsSchema), + callback, + enabled: true, + disable: () => registeredPrompt.update({ enabled: false }), + enable: () => registeredPrompt.update({ enabled: true }), + remove: () => registeredPrompt.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + delete this._registeredPrompts[name]; + if (updates.name) + this._registeredPrompts[updates.name] = registeredPrompt; + } + if (typeof updates.title !== 'undefined') + registeredPrompt.title = updates.title; + if (typeof updates.description !== 'undefined') + registeredPrompt.description = updates.description; + if (typeof updates.argsSchema !== 'undefined') + registeredPrompt.argsSchema = (0, zod_compat_js_1.objectFromShape)(updates.argsSchema); + if (typeof updates.callback !== 'undefined') + registeredPrompt.callback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredPrompt.enabled = updates.enabled; + this.sendPromptListChanged(); + } + }; + this._registeredPrompts[name] = registeredPrompt; + return registeredPrompt; + } + _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) { + // Validate tool name according to SEP specification + (0, toolNameValidation_js_1.validateAndWarnToolName)(name); + const registeredTool = { + title, + description, + inputSchema: getZodSchemaObject(inputSchema), + outputSchema: getZodSchemaObject(outputSchema), + annotations, + execution, + _meta, + handler: handler, + enabled: true, + disable: () => registeredTool.update({ enabled: false }), + enable: () => registeredTool.update({ enabled: true }), + remove: () => registeredTool.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + if (typeof updates.name === 'string') { + (0, toolNameValidation_js_1.validateAndWarnToolName)(updates.name); + } + delete this._registeredTools[name]; + if (updates.name) + this._registeredTools[updates.name] = registeredTool; + } + if (typeof updates.title !== 'undefined') + registeredTool.title = updates.title; + if (typeof updates.description !== 'undefined') + registeredTool.description = updates.description; + if (typeof updates.paramsSchema !== 'undefined') + registeredTool.inputSchema = (0, zod_compat_js_1.objectFromShape)(updates.paramsSchema); + if (typeof updates.callback !== 'undefined') + registeredTool.handler = updates.callback; + if (typeof updates.annotations !== 'undefined') + registeredTool.annotations = updates.annotations; + if (typeof updates._meta !== 'undefined') + registeredTool._meta = updates._meta; + if (typeof updates.enabled !== 'undefined') + registeredTool.enabled = updates.enabled; + this.sendToolListChanged(); + } + }; + this._registeredTools[name] = registeredTool; + this.setToolRequestHandlers(); + this.sendToolListChanged(); + return registeredTool; + } + /** + * tool() implementation. Parses arguments passed to overrides defined above. + */ + tool(name, ...rest) { + if (this._registeredTools[name]) { + throw new Error(`Tool ${name} is already registered`); + } + let description; + let inputSchema; + let outputSchema; + let annotations; + // Tool properties are passed as separate arguments, with omissions allowed. + // Support for this style is frozen as of protocol version 2025-03-26. Future additions + // to tool definition should *NOT* be added. + if (typeof rest[0] === 'string') { + description = rest.shift(); + } + // Handle the different overload combinations + if (rest.length > 1) { + // We have at least one more arg before the callback + const firstArg = rest[0]; + if (isZodRawShapeCompat(firstArg)) { + // We have a params schema as the first arg + inputSchema = rest.shift(); + // Check if the next arg is potentially annotations + if (rest.length > 1 && typeof rest[0] === 'object' && rest[0] !== null && !isZodRawShapeCompat(rest[0])) { + // Case: tool(name, paramsSchema, annotations, cb) + // Or: tool(name, description, paramsSchema, annotations, cb) + annotations = rest.shift(); + } + } + else if (typeof firstArg === 'object' && firstArg !== null) { + // Not a ZodRawShapeCompat, so must be annotations in this position + // Case: tool(name, annotations, cb) + // Or: tool(name, description, annotations, cb) + annotations = rest.shift(); + } + } + const callback = rest[0]; + return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, undefined, callback); + } + /** + * Registers a tool with a config object and callback. + */ + registerTool(name, config, cb) { + if (this._registeredTools[name]) { + throw new Error(`Tool ${name} is already registered`); + } + const { title, description, inputSchema, outputSchema, annotations, _meta } = config; + return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, _meta, cb); + } + prompt(name, ...rest) { + if (this._registeredPrompts[name]) { + throw new Error(`Prompt ${name} is already registered`); + } + let description; + if (typeof rest[0] === 'string') { + description = rest.shift(); + } + let argsSchema; + if (rest.length > 1) { + argsSchema = rest.shift(); + } + const cb = rest[0]; + const registeredPrompt = this._createRegisteredPrompt(name, undefined, description, argsSchema, cb); + this.setPromptRequestHandlers(); + this.sendPromptListChanged(); + return registeredPrompt; + } + /** + * Registers a prompt with a config object and callback. + */ + registerPrompt(name, config, cb) { + if (this._registeredPrompts[name]) { + throw new Error(`Prompt ${name} is already registered`); + } + const { title, description, argsSchema } = config; + const registeredPrompt = this._createRegisteredPrompt(name, title, description, argsSchema, cb); + this.setPromptRequestHandlers(); + this.sendPromptListChanged(); + return registeredPrompt; + } + /** + * Checks if the server is connected to a transport. + * @returns True if the server is connected + */ + isConnected() { + return this.server.transport !== undefined; + } + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + async sendLoggingMessage(params, sessionId) { + return this.server.sendLoggingMessage(params, sessionId); + } + /** + * Sends a resource list changed event to the client, if connected. + */ + sendResourceListChanged() { + if (this.isConnected()) { + this.server.sendResourceListChanged(); + } + } + /** + * Sends a tool list changed event to the client, if connected. + */ + sendToolListChanged() { + if (this.isConnected()) { + this.server.sendToolListChanged(); + } + } + /** + * Sends a prompt list changed event to the client, if connected. + */ + sendPromptListChanged() { + if (this.isConnected()) { + this.server.sendPromptListChanged(); + } + } +} +exports.McpServer = McpServer; +/** + * A resource template combines a URI pattern with optional functionality to enumerate + * all resources matching that pattern. + */ +class ResourceTemplate { + constructor(uriTemplate, _callbacks) { + this._callbacks = _callbacks; + this._uriTemplate = typeof uriTemplate === 'string' ? new uriTemplate_js_1.UriTemplate(uriTemplate) : uriTemplate; + } + /** + * Gets the URI template pattern. + */ + get uriTemplate() { + return this._uriTemplate; + } + /** + * Gets the list callback, if one was provided. + */ + get listCallback() { + return this._callbacks.list; + } + /** + * Gets the callback for completing a specific URI template variable, if one was provided. + */ + completeCallback(variable) { + var _a; + return (_a = this._callbacks.complete) === null || _a === void 0 ? void 0 : _a[variable]; + } +} +exports.ResourceTemplate = ResourceTemplate; +const EMPTY_OBJECT_JSON_SCHEMA = { + type: 'object', + properties: {} +}; +// Helper to check if an object is a Zod schema (ZodRawShapeCompat) +function isZodRawShapeCompat(obj) { + if (typeof obj !== 'object' || obj === null) + return false; + const isEmptyObject = Object.keys(obj).length === 0; + // Check if object is empty or at least one property is a ZodType instance + // Note: use heuristic check to avoid instanceof failure across different Zod versions + return isEmptyObject || Object.values(obj).some(isZodTypeLike); +} +function isZodTypeLike(value) { + return (value !== null && + typeof value === 'object' && + 'parse' in value && + typeof value.parse === 'function' && + 'safeParse' in value && + typeof value.safeParse === 'function'); +} +/** + * Converts a provided Zod schema to a Zod object if it is a ZodRawShapeCompat, + * otherwise returns the schema as is. + */ +function getZodSchemaObject(schema) { + if (!schema) { + return undefined; + } + if (isZodRawShapeCompat(schema)) { + return (0, zod_compat_js_1.objectFromShape)(schema); + } + return schema; +} +function promptArgumentsFromSchema(schema) { + const shape = (0, zod_compat_js_1.getObjectShape)(schema); + if (!shape) + return []; + return Object.entries(shape).map(([name, field]) => { + // Get description - works for both v3 and v4 + const description = (0, zod_compat_js_1.getSchemaDescription)(field); + // Check if optional - works for both v3 and v4 + const isOptional = (0, zod_compat_js_1.isSchemaOptional)(field); + return { + name, + description, + required: !isOptional + }; + }); +} +function getMethodValue(schema) { + const shape = (0, zod_compat_js_1.getObjectShape)(schema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value - works for both v3 and v4 + const value = (0, zod_compat_js_1.getLiteralValue)(methodSchema); + if (typeof value === 'string') { + return value; + } + throw new Error('Schema method literal must be a string'); +} +function createCompletionResult(suggestions) { + return { + completion: { + values: suggestions.slice(0, 100), + total: suggestions.length, + hasMore: suggestions.length > 100 + } + }; +} +const EMPTY_COMPLETION_RESULT = { + completion: { + values: [], + hasMore: false + } +}; +//# sourceMappingURL=mcp.js.map \ No newline at end of file diff --git a/dist/cjs/server/mcp.js.map b/dist/cjs/server/mcp.js.map new file mode 100644 index 000000000..ac756f08a --- /dev/null +++ b/dist/cjs/server/mcp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,mDAcyB;AACzB,2EAAiE;AACjE,0CAsCqB;AACrB,qDAA+D;AAC/D,6DAAkE;AAIlE,2EAA0E;AAC1E,uEAAiF;AAGjF;;;;GAIG;AACH,MAAa,SAAS;IAclB,YAAY,UAA0B,EAAE,OAAuB;QARvD,yBAAoB,GAA0C,EAAE,CAAC;QACjE,iCAA4B,GAEhC,EAAE,CAAC;QACC,qBAAgB,GAAuC,EAAE,CAAC;QAC1D,uBAAkB,GAAyC,EAAE,CAAC;QAuC9D,6BAAwB,GAAG,KAAK,CAAC;QAsRjC,kCAA6B,GAAG,KAAK,CAAC;QAmFtC,iCAA4B,GAAG,KAAK,CAAC;QAmFrC,+BAA0B,GAAG,KAAK,CAAC;QA/dvC,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,IAAI,YAAY;QACZ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACtB,IAAI,CAAC,aAAa,GAAG;gBACjB,KAAK,EAAE,IAAI,0CAA0B,CAAC,IAAI,CAAC;aAC9C,CAAC;QACN,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C;KACJ,CAAC;AACN,CAAC;AAED,MAAM,uBAAuB,GAAmB;IAC5C,UAAU,EAAE;QACR,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,KAAK;KACjB;CACJ,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/session-stores/index.d.ts b/dist/cjs/server/session-stores/index.d.ts new file mode 100644 index 000000000..a430e4410 --- /dev/null +++ b/dist/cjs/server/session-stores/index.d.ts @@ -0,0 +1,6 @@ +/** + * Session Store implementations for distributed MCP deployments + */ +export { RedisSessionStore, InMemorySessionStore } from './redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './redis.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/session-stores/index.d.ts.map b/dist/cjs/server/session-stores/index.d.ts.map new file mode 100644 index 000000000..fc5fbf1dc --- /dev/null +++ b/dist/cjs/server/session-stores/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/session-stores/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/session-stores/index.js b/dist/cjs/server/session-stores/index.js new file mode 100644 index 000000000..9a0cf29f5 --- /dev/null +++ b/dist/cjs/server/session-stores/index.js @@ -0,0 +1,10 @@ +"use strict"; +/** + * Session Store implementations for distributed MCP deployments + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemorySessionStore = exports.RedisSessionStore = void 0; +var redis_js_1 = require("./redis.js"); +Object.defineProperty(exports, "RedisSessionStore", { enumerable: true, get: function () { return redis_js_1.RedisSessionStore; } }); +Object.defineProperty(exports, "InMemorySessionStore", { enumerable: true, get: function () { return redis_js_1.InMemorySessionStore; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/server/session-stores/index.js.map b/dist/cjs/server/session-stores/index.js.map new file mode 100644 index 000000000..7ccaacad5 --- /dev/null +++ b/dist/cjs/server/session-stores/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/server/session-stores/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uCAAqE;AAA5D,6GAAA,iBAAiB,OAAA;AAAE,gHAAA,oBAAoB,OAAA"} \ No newline at end of file diff --git a/dist/cjs/server/session-stores/redis.d.ts b/dist/cjs/server/session-stores/redis.d.ts new file mode 100644 index 000000000..1a0975a5c --- /dev/null +++ b/dist/cjs/server/session-stores/redis.d.ts @@ -0,0 +1,122 @@ +/** + * Redis Session Store Implementation + * + * This module provides a Redis-based implementation of the SessionStore interface + * for distributed MCP server deployments. + * + * Usage: + * ```typescript + * import Redis from 'ioredis'; + * import { RedisSessionStore } from '@modelcontextprotocol/sdk/server/session-stores/redis.js'; + * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; + * + * const redis = new Redis({ + * host: 'redis.example.com', + * port: 6379, + * password: 'your-password' + * }); + * + * const sessionStore = new RedisSessionStore({ + * redis, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 // 1 hour + * }); + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore + * }); + * ``` + */ +import { SessionStore, SessionData } from '../streamableHttp.js'; +/** + * Generic Redis client interface + * Compatible with ioredis, node-redis, and other Redis clients + */ +export interface RedisClient { + get(key: string): Promise; + setex(key: string, seconds: number, value: string): Promise; + del(key: string | string[]): Promise; + exists(key: string | string[]): Promise; + expire(key: string, seconds: number): Promise; +} +/** + * Configuration options for RedisSessionStore + */ +export interface RedisSessionStoreOptions { + /** + * Redis client instance (ioredis, node-redis, or compatible) + */ + redis: RedisClient; + /** + * Key prefix for session data in Redis + * @default 'mcp:session:' + */ + keyPrefix?: string; + /** + * Session TTL in seconds + * @default 3600 (1 hour) + */ + ttlSeconds?: number; + /** + * Optional callback for logging + */ + onLog?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: unknown[]) => void; +} +/** + * Redis-based session store for distributed MCP deployments + * + * Features: + * - Automatic TTL management with activity-based refresh + * - Cross-pod session sharing + * - Graceful handling of Redis connection issues + */ +export declare class RedisSessionStore implements SessionStore { + private readonly redis; + private readonly keyPrefix; + private readonly ttlSeconds; + private readonly log; + constructor(options: RedisSessionStoreOptions); + /** + * Get the Redis key for a session + */ + private getKey; + /** + * Store session data in Redis + */ + storeSession(sessionId: string, data: SessionData): Promise; + /** + * Retrieve session data from Redis + */ + getSession(sessionId: string): Promise; + /** + * Update session activity timestamp and refresh TTL + */ + updateSessionActivity(sessionId: string): Promise; + /** + * Delete a session from Redis + */ + deleteSession(sessionId: string): Promise; + /** + * Check if a session exists in Redis + */ + sessionExists(sessionId: string): Promise; +} +/** + * In-Memory Session Store (for development/testing) + * + * NOT suitable for production multi-pod deployments! + * Use RedisSessionStore or implement your own SessionStore for production. + */ +export declare class InMemorySessionStore implements SessionStore { + private sessions; + private readonly ttlMs; + constructor(ttlSeconds?: number); + storeSession(sessionId: string, data: SessionData): Promise; + getSession(sessionId: string): Promise; + updateSessionActivity(sessionId: string): Promise; + deleteSession(sessionId: string): Promise; + sessionExists(sessionId: string): Promise; + private cleanup; +} +//# sourceMappingURL=redis.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/session-stores/redis.d.ts.map b/dist/cjs/server/session-stores/redis.d.ts.map new file mode 100644 index 000000000..faa297e98 --- /dev/null +++ b/dist/cjs/server/session-stores/redis.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../src/server/session-stores/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;;GA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E,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvE;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmBhE;;OAEG;IACG,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB7D;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAU3D;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACrD,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,UAAU,GAAE,MAAa;IAO/B,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAa1D,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD,OAAO,CAAC,OAAO;CAQlB"} \ No newline at end of file diff --git a/dist/cjs/server/session-stores/redis.js b/dist/cjs/server/session-stores/redis.js new file mode 100644 index 000000000..aadaab9ef --- /dev/null +++ b/dist/cjs/server/session-stores/redis.js @@ -0,0 +1,192 @@ +"use strict"; +/** + * Redis Session Store Implementation + * + * This module provides a Redis-based implementation of the SessionStore interface + * for distributed MCP server deployments. + * + * Usage: + * ```typescript + * import Redis from 'ioredis'; + * import { RedisSessionStore } from '@modelcontextprotocol/sdk/server/session-stores/redis.js'; + * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; + * + * const redis = new Redis({ + * host: 'redis.example.com', + * port: 6379, + * password: 'your-password' + * }); + * + * const sessionStore = new RedisSessionStore({ + * redis, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 // 1 hour + * }); + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore + * }); + * ``` + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.InMemorySessionStore = exports.RedisSessionStore = void 0; +/** + * Redis-based session store for distributed MCP deployments + * + * Features: + * - Automatic TTL management with activity-based refresh + * - Cross-pod session sharing + * - Graceful handling of Redis connection issues + */ +class RedisSessionStore { + constructor(options) { + var _a, _b, _c; + this.redis = options.redis; + this.keyPrefix = (_a = options.keyPrefix) !== null && _a !== void 0 ? _a : 'mcp:session:'; + this.ttlSeconds = (_b = options.ttlSeconds) !== null && _b !== void 0 ? _b : 3600; + this.log = (_c = options.onLog) !== null && _c !== void 0 ? _c : (() => { }); + } + /** + * Get the Redis key for a session + */ + getKey(sessionId) { + return `${this.keyPrefix}${sessionId}`; + } + /** + * Store session data in Redis + */ + async storeSession(sessionId, data) { + try { + const key = this.getKey(sessionId); + const serialized = JSON.stringify(data); + await this.redis.setex(key, this.ttlSeconds, serialized); + this.log('debug', `Session stored: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to store session ${sessionId}:`, error); + throw error; + } + } + /** + * Retrieve session data from Redis + */ + async getSession(sessionId) { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + if (!data) { + this.log('debug', `Session not found: ${sessionId}`); + return null; + } + const parsed = JSON.parse(data); + this.log('debug', `Session retrieved: ${sessionId}`); + return parsed; + } + catch (error) { + this.log('error', `Failed to get session ${sessionId}:`, error); + throw error; + } + } + /** + * Update session activity timestamp and refresh TTL + */ + async updateSessionActivity(sessionId) { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + if (!data) { + this.log('warn', `Cannot update activity for non-existent session: ${sessionId}`); + return; + } + const parsed = JSON.parse(data); + parsed.lastActivity = Date.now(); + await this.redis.setex(key, this.ttlSeconds, JSON.stringify(parsed)); + this.log('debug', `Session activity updated: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to update session activity ${sessionId}:`, error); + // Don't throw - activity update failures shouldn't break the request + } + } + /** + * Delete a session from Redis + */ + async deleteSession(sessionId) { + try { + const key = this.getKey(sessionId); + await this.redis.del(key); + this.log('debug', `Session deleted: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to delete session ${sessionId}:`, error); + throw error; + } + } + /** + * Check if a session exists in Redis + */ + async sessionExists(sessionId) { + try { + const key = this.getKey(sessionId); + const exists = await this.redis.exists(key); + return exists === 1; + } + catch (error) { + this.log('error', `Failed to check session existence ${sessionId}:`, error); + throw error; + } + } +} +exports.RedisSessionStore = RedisSessionStore; +/** + * In-Memory Session Store (for development/testing) + * + * NOT suitable for production multi-pod deployments! + * Use RedisSessionStore or implement your own SessionStore for production. + */ +class InMemorySessionStore { + constructor(ttlSeconds = 3600) { + this.sessions = new Map(); + this.ttlMs = ttlSeconds * 1000; + // Cleanup expired sessions every minute + setInterval(() => this.cleanup(), 60000); + } + async storeSession(sessionId, data) { + this.sessions.set(sessionId, data); + } + async getSession(sessionId) { + const data = this.sessions.get(sessionId); + if (!data) + return null; + // Check if expired + if (Date.now() - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + return null; + } + return data; + } + async updateSessionActivity(sessionId) { + const data = this.sessions.get(sessionId); + if (data) { + data.lastActivity = Date.now(); + } + } + async deleteSession(sessionId) { + this.sessions.delete(sessionId); + } + async sessionExists(sessionId) { + const data = await this.getSession(sessionId); + return data !== null; + } + cleanup() { + const now = Date.now(); + for (const [sessionId, data] of this.sessions) { + if (now - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + } + } + } +} +exports.InMemorySessionStore = InMemorySessionStore; +//# sourceMappingURL=redis.js.map \ No newline at end of file diff --git a/dist/cjs/server/session-stores/redis.js.map b/dist/cjs/server/session-stores/redis.js.map new file mode 100644 index 000000000..b0077dbce --- /dev/null +++ b/dist/cjs/server/session-stores/redis.js.map @@ -0,0 +1 @@ +{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../../src/server/session-stores/redis.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;AA2CH;;;;;;;GAOG;AACH,MAAa,iBAAiB;IAM1B,YAAY,OAAiC;;QACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,cAAc,CAAC;QACrD,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,GAAG,GAAG,MAAA,OAAO,CAAC,KAAK,mCAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,SAAiB;QAC5B,OAAO,GAAG,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,SAAiB,EAAE,IAAiB;QACnD,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACxC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACzD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,mBAAmB,SAAS,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,GAAG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AAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC9C,OAAO,IAAI,KAAK,IAAI,CAAC;IACzB,CAAC;IAEO,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;gBACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACpC,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AApDD,oDAoDC"} \ No newline at end of file diff --git a/dist/cjs/server/sse.d.ts b/dist/cjs/server/sse.d.ts new file mode 100644 index 000000000..aba8d5120 --- /dev/null +++ b/dist/cjs/server/sse.d.ts @@ -0,0 +1,76 @@ +import { IncomingMessage, ServerResponse } from 'node:http'; +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage, MessageExtraInfo } from '../types.js'; +import { AuthInfo } from './auth/types.js'; +/** + * Configuration options for SSEServerTransport. + */ +export interface SSEServerTransportOptions { + /** + * List of allowed host header values for DNS rebinding protection. + * If not specified, host validation is disabled. + */ + allowedHosts?: string[]; + /** + * List of allowed origin header values for DNS rebinding protection. + * If not specified, origin validation is disabled. + */ + allowedOrigins?: string[]; + /** + * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured). + * Default is false for backwards compatibility. + */ + enableDnsRebindingProtection?: boolean; +} +/** + * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests. + * + * This transport is only available in Node.js environments. + * @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead. + */ +export declare class SSEServerTransport implements Transport { + private _endpoint; + private res; + private _sseResponse?; + private _sessionId; + private _options; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void; + /** + * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`. + */ + constructor(_endpoint: string, res: ServerResponse, options?: SSEServerTransportOptions); + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + private validateRequestHeaders; + /** + * Handles the initial SSE connection request. + * + * This should be called when a GET request is made to establish the SSE stream. + */ + start(): Promise; + /** + * Handles incoming POST messages. + * + * This should be called when a POST request is made to send a message to the server. + */ + handlePostMessage(req: IncomingMessage & { + auth?: AuthInfo; + }, res: ServerResponse, parsedBody?: unknown): Promise; + /** + * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST. + */ + handleMessage(message: unknown, extra?: MessageExtraInfo): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; + /** + * Returns the session ID for this transport. + * + * This can be used to route incoming POST requests. + */ + get sessionId(): string; +} +//# sourceMappingURL=sse.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/sse.d.ts.map b/dist/cjs/server/sse.d.ts.map new file mode 100644 index 000000000..c3c267cd8 --- /dev/null +++ b/dist/cjs/server/sse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAwB,gBAAgB,EAAe,MAAM,aAAa,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;OAG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mode 100644 index 000000000..86f404026 --- /dev/null +++ b/dist/cjs/server/sse.js @@ -0,0 +1,168 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SSEServerTransport = void 0; +const node_crypto_1 = require("node:crypto"); +const types_js_1 = require("../types.js"); +const raw_body_1 = __importDefault(require("raw-body")); +const content_type_1 = __importDefault(require("content-type")); +const node_url_1 = require("node:url"); +const MAXIMUM_MESSAGE_SIZE = '4mb'; +/** + * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests. + * + * This transport is only available in Node.js environments. + * @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead. + */ +class SSEServerTransport { + /** + * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`. + */ + constructor(_endpoint, res, options) { + this._endpoint = _endpoint; + this.res = res; + this._sessionId = (0, node_crypto_1.randomUUID)(); + this._options = options || { enableDnsRebindingProtection: false }; + } + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + validateRequestHeaders(req) { + // Skip validation if protection is not enabled + if (!this._options.enableDnsRebindingProtection) { + return undefined; + } + // Validate Host header if allowedHosts is configured + if (this._options.allowedHosts && this._options.allowedHosts.length > 0) { + const hostHeader = req.headers.host; + if (!hostHeader || !this._options.allowedHosts.includes(hostHeader)) { + return `Invalid Host header: ${hostHeader}`; + } + } + // Validate Origin header if allowedOrigins is configured + if (this._options.allowedOrigins && this._options.allowedOrigins.length > 0) { + const originHeader = req.headers.origin; + if (!originHeader || !this._options.allowedOrigins.includes(originHeader)) { + return `Invalid Origin header: ${originHeader}`; + } + } + return undefined; + } + /** + * Handles the initial SSE connection request. + * + * This should be called when a GET request is made to establish the SSE stream. + */ + async start() { + if (this._sseResponse) { + throw new Error('SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.'); + } + this.res.writeHead(200, { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }); + // Send the endpoint event + // Use a dummy base URL because this._endpoint is relative. + // This allows using URL/URLSearchParams for robust parameter handling. + const dummyBase = 'http://localhost'; // Any valid base works + const endpointUrl = new node_url_1.URL(this._endpoint, dummyBase); + endpointUrl.searchParams.set('sessionId', this._sessionId); + // Reconstruct the relative URL string (pathname + search + hash) + const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash; + this.res.write(`event: endpoint\ndata: ${relativeUrlWithSession}\n\n`); + this._sseResponse = this.res; + this.res.on('close', () => { + var _a; + this._sseResponse = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }); + } + /** + * Handles incoming POST messages. + * + * This should be called when a POST request is made to send a message to the server. + */ + async handlePostMessage(req, res, parsedBody) { + var _a, _b, _c, _d; + if (!this._sseResponse) { + const message = 'SSE connection not established'; + res.writeHead(500).end(message); + throw new Error(message); + } + // Validate request headers for DNS rebinding protection + const validationError = this.validateRequestHeaders(req); + if (validationError) { + res.writeHead(403).end(validationError); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(validationError)); + return; + } + const authInfo = req.auth; + const requestInfo = { headers: req.headers }; + let body; + try { + const ct = content_type_1.default.parse((_b = req.headers['content-type']) !== null && _b !== void 0 ? _b : ''); + if (ct.type !== 'application/json') { + throw new Error(`Unsupported content-type: ${ct.type}`); + } + body = + parsedBody !== null && parsedBody !== void 0 ? parsedBody : (await (0, raw_body_1.default)(req, { + limit: MAXIMUM_MESSAGE_SIZE, + encoding: (_c = ct.parameters.charset) !== null && _c !== void 0 ? _c : 'utf-8' + })); + } + catch (error) { + res.writeHead(400).end(String(error)); + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + return; + } + try { + await this.handleMessage(typeof body === 'string' ? JSON.parse(body) : body, { requestInfo, authInfo }); + } + catch (_e) { + res.writeHead(400).end(`Invalid message: ${body}`); + return; + } + res.writeHead(202).end('Accepted'); + } + /** + * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST. + */ + async handleMessage(message, extra) { + var _a, _b; + let parsedMessage; + try { + parsedMessage = types_js_1.JSONRPCMessageSchema.parse(message); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, parsedMessage, extra); + } + async close() { + var _a, _b; + (_a = this._sseResponse) === null || _a === void 0 ? void 0 : _a.end(); + this._sseResponse = undefined; + (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this); + } + async send(message) { + if (!this._sseResponse) { + throw new Error('Not connected'); + } + this._sseResponse.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`); + } + /** + * Returns the session ID for this transport. + * + * This can be used to route incoming POST requests. + */ + get sessionId() { + return this._sessionId; + } +} +exports.SSEServerTransport = SSEServerTransport; +//# sourceMappingURL=sse.js.map \ No newline at end of file diff --git a/dist/cjs/server/sse.js.map b/dist/cjs/server/sse.js.map new file mode 100644 index 000000000..dbac8f81e --- /dev/null +++ b/dist/cjs/server/sse.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAyC;AAGzC,0CAAkG;AAClG,wDAAkC;AAClC,gEAAuC;AAEvC,uCAA+B;AAE/B,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAyBnC;;;;;GAKG;AACH,MAAa,kBAAkB;IAQ3B;;OAEG;IACH,YACY,SAAiB,EACjB,GAAmB,EAC3B,OAAmC;QAF3B,cAAS,GAAT,SAAS,CAAQ;QACjB,QAAG,GAAH,GAAG,CAAgB;QAG3B,IAAI,CAAC,UAAU,GAAG,IAAA,wBAAU,GAAE,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,EAAE,4BAA4B,EAAE,KAAK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G,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;YACnD,OAAO;QACX,CAAC;QAED,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAAgB,EAAE,KAAwB;;QAC1D,IAAI,aAA6B,CAAC;QAClC,IAAI,CAAC;YACD,aAAa,GAAG,+BAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;QAChB,CAAC;QAED,MAAA,IAAI,CAAC,SAAS,qDAAG,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAuB;QAC9B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AA7KD,gDA6KC"} \ No newline at end of file diff --git a/dist/cjs/server/stdio.d.ts b/dist/cjs/server/stdio.d.ts new file mode 100644 index 000000000..df3029d0d --- /dev/null +++ b/dist/cjs/server/stdio.d.ts @@ -0,0 +1,28 @@ +import { Readable, Writable } from 'node:stream'; +import { JSONRPCMessage } from '../types.js'; +import { Transport } from '../shared/transport.js'; +/** + * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout. + * + * This transport is only available in Node.js environments. + */ +export declare class StdioServerTransport implements Transport { + private _stdin; + private _stdout; + private _readBuffer; + private _started; + constructor(_stdin?: Readable, _stdout?: Writable); + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + _ondata: (chunk: Buffer) => void; + _onerror: (error: Error) => void; + /** + * Starts listening for messages on stdin. + */ + start(): Promise; + private processReadBuffer; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/stdio.d.ts.map b/dist/cjs/server/stdio.d.ts.map new file mode 100644 index 000000000..fdd2dfe48 --- /dev/null +++ b/dist/cjs/server/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/server/stdio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IAK9C,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IALnB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,QAAQ,CAAS;gBAGb,MAAM,GAAE,QAAwB,EAChC,OAAO,GAAE,QAAyB;IAG9C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAG9C,OAAO,UAAW,MAAM,UAGtB;IACF,QAAQ,UAAW,KAAK,UAEtB;IAEF;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B,OAAO,CAAC,iBAAiB;IAenB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAU/C"} \ No newline at end of file diff --git a/dist/cjs/server/stdio.js b/dist/cjs/server/stdio.js new file mode 100644 index 000000000..e60d19caf --- /dev/null +++ b/dist/cjs/server/stdio.js @@ -0,0 +1,85 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StdioServerTransport = void 0; +const node_process_1 = __importDefault(require("node:process")); +const stdio_js_1 = require("../shared/stdio.js"); +/** + * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout. + * + * This transport is only available in Node.js environments. + */ +class StdioServerTransport { + constructor(_stdin = node_process_1.default.stdin, _stdout = node_process_1.default.stdout) { + this._stdin = _stdin; + this._stdout = _stdout; + this._readBuffer = new stdio_js_1.ReadBuffer(); + this._started = false; + // Arrow functions to bind `this` properly, while maintaining function identity. + this._ondata = (chunk) => { + this._readBuffer.append(chunk); + this.processReadBuffer(); + }; + this._onerror = (error) => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + } + /** + * Starts listening for messages on stdin. + */ + async start() { + if (this._started) { + throw new Error('StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.'); + } + this._started = true; + this._stdin.on('data', this._ondata); + this._stdin.on('error', this._onerror); + } + processReadBuffer() { + var _a, _b; + while (true) { + try { + const message = this._readBuffer.readMessage(); + if (message === null) { + break; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + async close() { + var _a; + // Remove our event listeners first + this._stdin.off('data', this._ondata); + this._stdin.off('error', this._onerror); + // Check if we were the only data listener + const remainingDataListeners = this._stdin.listenerCount('data'); + if (remainingDataListeners === 0) { + // Only pause stdin if we were the only listener + // This prevents interfering with other parts of the application that might be using stdin + this._stdin.pause(); + } + // Clear the buffer and notify closure + this._readBuffer.clear(); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + send(message) { + return new Promise(resolve => { + const json = (0, stdio_js_1.serializeMessage)(message); + if (this._stdout.write(json)) { + resolve(); + } + else { + this._stdout.once('drain', resolve); + } + }); + } +} +exports.StdioServerTransport = StdioServerTransport; +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/cjs/server/stdio.js.map b/dist/cjs/server/stdio.js.map new file mode 100644 index 000000000..9397ec5d2 --- /dev/null +++ b/dist/cjs/server/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/server/stdio.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAmC;AAEnC,iDAAkE;AAIlE;;;;GAIG;AACH,MAAa,oBAAoB;IAI7B,YACY,SAAmB,sBAAO,CAAC,KAAK,EAChC,UAAoB,sBAAO,CAAC,MAAM;QADlC,WAAM,GAAN,MAAM,CAA0B;QAChC,YAAO,GAAP,OAAO,CAA2B;QALtC,gBAAW,GAAe,IAAI,qBAAU,EAAE,CAAC;QAC3C,aAAQ,GAAG,KAAK,CAAC;QAWzB,gFAAgF;QAChF,YAAO,GAAG,CAAC,KAAa,EAAE,EAAE;YACxB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC;QACF,aAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;;YACxB,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IAbC,CAAC;IAeJ;;OAEG;IACH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;QACzB,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,OAAuB;QACxB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YACzB,MAAM,IAAI,GAAG,IAAA,2BAAgB,EAAC,OAAO,CAAC,CAAC;YACvC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACd,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACxC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhFD,oDAgFC"} \ No newline at end of file diff --git a/dist/cjs/server/streamableHttp.d.ts b/dist/cjs/server/streamableHttp.d.ts new file mode 100644 index 000000000..97291ab3b --- /dev/null +++ b/dist/cjs/server/streamableHttp.d.ts @@ -0,0 +1,369 @@ +import { IncomingMessage, ServerResponse } from 'node:http'; +import { Transport } from '../shared/transport.js'; +import { MessageExtraInfo, JSONRPCMessage, RequestId } from '../types.js'; +import { AuthInfo } from './auth/types.js'; +export type StreamId = string; +export type EventId = string; +/** + * Interface for resumability support via event storage + */ +export interface EventStore { + /** + * Stores an event for later retrieval + * @param streamId ID of the stream the event belongs to + * @param message The JSON-RPC message to store + * @returns The generated event ID for the stored event + */ + storeEvent(streamId: StreamId, message: JSONRPCMessage): Promise; + /** + * Get the stream ID associated with a given event ID. + * @param eventId The event ID to look up + * @returns The stream ID, or undefined if not found + * + * Optional: If not provided, the SDK will use the streamId returned by + * replayEventsAfter for stream mapping. + */ + getStreamIdForEventId?(eventId: EventId): Promise; + replayEventsAfter(lastEventId: EventId, { send }: { + send: (eventId: EventId, message: JSONRPCMessage) => Promise; + }): Promise; +} +/** + * Session data structure for distributed session storage + */ +export interface SessionData { + /** + * The unique session identifier + */ + sessionId: string; + /** + * Whether the session has been initialized (received initialize request) + */ + initialized: boolean; + /** + * Timestamp when the session was created (Unix ms) + */ + createdAt: number; + /** + * Timestamp of last activity (Unix ms) + */ + lastActivity: number; + /** + * Optional metadata for custom use cases (e.g., serverId, userId) + */ + metadata?: Record; +} +/** + * Interface for distributed session storage (e.g., Redis, PostgreSQL, etc.) + * + * This interface enables multi-node/multi-pod deployments where session state + * must be shared across multiple server instances. Without this, sessions are + * stored in-memory and requests routed to different pods will fail. + * + * Usage example with Redis: + * ```typescript + * const sessionStore: SessionStore = { + * async storeSession(sessionId, data) { + * await redis.setex(`mcp:session:${sessionId}`, 3600, JSON.stringify(data)); + * }, + * async getSession(sessionId) { + * const data = await redis.get(`mcp:session:${sessionId}`); + * return data ? JSON.parse(data) : null; + * }, + * async updateSessionActivity(sessionId) { + * const data = await this.getSession(sessionId); + * if (data) { + * data.lastActivity = Date.now(); + * await this.storeSession(sessionId, data); + * } + * }, + * async deleteSession(sessionId) { + * await redis.del(`mcp:session:${sessionId}`); + * }, + * async sessionExists(sessionId) { + * return await redis.exists(`mcp:session:${sessionId}`) === 1; + * } + * }; + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: sessionStore + * }); + * ``` + */ +export interface SessionStore { + /** + * Store session data + * @param sessionId The session identifier + * @param data The session data to store + */ + storeSession(sessionId: string, data: SessionData): Promise; + /** + * Retrieve session data + * @param sessionId The session identifier + * @returns The session data, or null if not found + */ + getSession(sessionId: string): Promise; + /** + * Update session activity timestamp (e.g., refresh TTL) + * @param sessionId The session identifier + */ + updateSessionActivity(sessionId: string): Promise; + /** + * Delete a session + * @param sessionId The session identifier + */ + deleteSession(sessionId: string): Promise; + /** + * Check if a session exists + * @param sessionId The session identifier + * @returns true if the session exists + */ + sessionExists(sessionId: string): Promise; +} +/** + * Session storage mode for the transport + */ +export type SessionStorageMode = 'memory' | 'external'; +/** + * Configuration options for StreamableHTTPServerTransport + */ +export interface StreamableHTTPServerTransportOptions { + /** + * Function that generates a session ID for the transport. + * The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash) + * + * Return undefined to disable session management. + */ + sessionIdGenerator: (() => string) | undefined; + /** + * A callback for session initialization events + * This is called when the server initializes a new session. + * Useful in cases when you need to register multiple mcp sessions + * and need to keep track of them. + * @param sessionId The generated session ID + */ + onsessioninitialized?: (sessionId: string) => void | Promise; + /** + * A callback for session close events + * This is called when the server closes a session due to a DELETE request. + * Useful in cases when you need to clean up resources associated with the session. + * Note that this is different from the transport closing, if you are handling + * HTTP requests from multiple nodes you might want to close each + * StreamableHTTPServerTransport after a request is completed while still keeping the + * session open/running. + * @param sessionId The session ID that was closed + */ + onsessionclosed?: (sessionId: string) => void | Promise; + /** + * If true, the server will return JSON responses instead of starting an SSE stream. + * This can be useful for simple request/response scenarios without streaming. + * Default is false (SSE streams are preferred). + */ + enableJsonResponse?: boolean; + /** + * Event store for resumability support + * If provided, resumability will be enabled, allowing clients to reconnect and resume messages + */ + eventStore?: EventStore; + /** + * Session storage mode - explicitly choose between in-memory and external storage. + * + * - 'memory': Sessions stored in process memory (single-node only, default) + * - 'external': Sessions stored in external store (requires sessionStore option) + * + * When 'external' is selected but sessionStore is not provided, an error will be thrown. + * + * @default 'memory' + */ + sessionStorageMode?: SessionStorageMode; + /** + * Session store for distributed session management. + * Required when sessionStorageMode is 'external'. + * + * This enables multi-node/multi-pod deployments where requests may be routed + * to different server instances. + * + * When sessionStore is provided with mode 'external': + * - Session validation checks the external store instead of local memory + * - Session data is persisted across server restarts + * - Multiple server instances can share session state + * - Cross-pod session recovery is handled automatically + * + * @example + * ```typescript + * // Redis session store for multi-pod deployment + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStorageMode: 'external', + * sessionStore: new RedisSessionStore({ + * redis: redisClient, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 + * }) + * }); + * ``` + */ + sessionStore?: SessionStore; + /** + * List of allowed host header values for DNS rebinding protection. + * If not specified, host validation is disabled. + */ + allowedHosts?: string[]; + /** + * List of allowed origin header values for DNS rebinding protection. + * If not specified, origin validation is disabled. + */ + allowedOrigins?: string[]; + /** + * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured). + * Default is false for backwards compatibility. + */ + enableDnsRebindingProtection?: boolean; + /** + * Retry interval in milliseconds to suggest to clients in SSE retry field. + * When set, the server will send a retry field in SSE priming events to control + * client reconnection timing for polling behavior. + */ + retryInterval?: number; +} +/** + * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It supports both SSE streaming and direct HTTP responses. + * + * Usage example: + * + * ```typescript + * // Stateful mode - server sets the session ID + * const statefulTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * }); + * + * // Stateless mode - explicitly set session ID to undefined + * const statelessTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: undefined, + * }); + * + * // Using with pre-parsed request body + * app.post('/mcp', (req, res) => { + * transport.handleRequest(req, res, req.body); + * }); + * + * // With distributed session store (Redis) for multi-pod deployments + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: myRedisSessionStore + * }); + * ``` + * + * In stateful mode: + * - Session ID is generated and included in response headers + * - Session ID is always included in initialization responses + * - Requests with invalid session IDs are rejected with 404 Not Found + * - Non-initialization requests without a session ID are rejected with 400 Bad Request + * - State is maintained in-memory (connections, message history) or externally via sessionStore + * + * In stateless mode: + * - No Session ID is included in any responses + * - No session validation is performed + */ +export declare class StreamableHTTPServerTransport implements Transport { + private sessionIdGenerator; + private _started; + private _streamMapping; + private _requestToStreamMapping; + private _requestResponseMap; + private _initialized; + private _enableJsonResponse; + private _standaloneSseStreamId; + private _eventStore?; + private _sessionStorageMode; + private _sessionStore?; + private _onsessioninitialized?; + private _onsessionclosed?; + private _allowedHosts?; + private _allowedOrigins?; + private _enableDnsRebindingProtection; + private _retryInterval?; + sessionId?: string; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void; + constructor(options: StreamableHTTPServerTransportOptions); + /** + * Returns the current session storage mode + */ + get sessionStorageMode(): SessionStorageMode; + /** + * Returns true if using external session storage + */ + get isUsingExternalSessionStore(): boolean; + /** + * Starts the transport. This is required by the Transport interface but is a no-op + * for the Streamable HTTP transport as connections are managed per-request. + */ + start(): Promise; + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + private validateRequestHeaders; + /** + * Handles an incoming HTTP request, whether GET or POST + */ + handleRequest(req: IncomingMessage & { + auth?: AuthInfo; + }, res: ServerResponse, parsedBody?: unknown): Promise; + /** + * Writes a priming event to establish resumption capability. + * Only sends if eventStore is configured (opt-in for resumability). + */ + private _maybeWritePrimingEvent; + /** + * Handles GET requests for SSE stream + */ + private handleGetRequest; + /** + * Replays events that would have been sent after the specified event ID + * Only used when resumability is enabled + */ + private replayEvents; + /** + * Writes an event to the SSE stream with proper formatting + */ + private writeSSEEvent; + /** + * Handles unsupported requests (PUT, PATCH, etc.) + */ + private handleUnsupportedRequest; + /** + * Handles POST requests containing JSON-RPC messages + */ + private handlePostRequest; + /** + * Handles DELETE requests to terminate sessions + */ + private handleDeleteRequest; + /** + * Validates session ID for non-initialization requests. + * + * When sessionStore is provided, validation checks the external store, + * enabling multi-node deployments where different pods may handle requests + * for the same session. + * + * Returns true if the session is valid, false otherwise. + */ + private validateSession; + private validateProtocolVersion; + close(): Promise; + /** + * Close an SSE stream for a specific request, triggering client reconnection. + * Use this to implement polling behavior during long-running operations - + * client will reconnect after the retry interval specified in the priming event. + */ + closeSSEStream(requestId: RequestId): void; + send(message: JSONRPCMessage, options?: { + relatedRequestId?: RequestId; + }): Promise; +} +//# sourceMappingURL=streamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/streamableHttp.d.ts.map b/dist/cjs/server/streamableHttp.d.ts.map new file mode 100644 index 000000000..907ee061f --- /dev/null +++ b/dist/cjs/server/streamable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,OAAO,CAEzC;IAED;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAyB9B;;OAEG;IACG,aAAa,CAAC,GAAG,EAAE,eAAe,GAAG;QAAE,IAAI,CAAC,EAAE,QAAQ,CAAA;KAAE,EAAE,GAAG,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BzH;;;OAGG;YACW,uBAAuB;IAcrC;;OAEG;YACW,gBAAgB;IAiF9B;;;OAGG;YACW,YAAY;IA6E1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;YACW,wBAAwB;IAetC;;OAEG;YACW,iBAAiB;IAiN/B;;OAEG;YACW,mBAAmB;IAkBjC;;;;;;;;OAQG;YACW,eAAe;IAyI7B,OAAO,CAAC,uBAAuB;IAsBzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B;;;;OAIG;IACH,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAWpC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA+FjG"} \ No newline at end of file diff --git a/dist/cjs/server/streamableHttp.js b/dist/cjs/server/streamableHttp.js new file mode 100644 index 000000000..f42ad625f --- /dev/null +++ b/dist/cjs/server/streamableHttp.js @@ -0,0 +1,808 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StreamableHTTPServerTransport = void 0; +const types_js_1 = require("../types.js"); +const raw_body_1 = __importDefault(require("raw-body")); +const content_type_1 = __importDefault(require("content-type")); +const node_crypto_1 = require("node:crypto"); +const MAXIMUM_MESSAGE_SIZE = '4mb'; +/** + * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It supports both SSE streaming and direct HTTP responses. + * + * Usage example: + * + * ```typescript + * // Stateful mode - server sets the session ID + * const statefulTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * }); + * + * // Stateless mode - explicitly set session ID to undefined + * const statelessTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: undefined, + * }); + * + * // Using with pre-parsed request body + * app.post('/mcp', (req, res) => { + * transport.handleRequest(req, res, req.body); + * }); + * + * // With distributed session store (Redis) for multi-pod deployments + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: myRedisSessionStore + * }); + * ``` + * + * In stateful mode: + * - Session ID is generated and included in response headers + * - Session ID is always included in initialization responses + * - Requests with invalid session IDs are rejected with 404 Not Found + * - Non-initialization requests without a session ID are rejected with 400 Bad Request + * - State is maintained in-memory (connections, message history) or externally via sessionStore + * + * In stateless mode: + * - No Session ID is included in any responses + * - No session validation is performed + */ +class StreamableHTTPServerTransport { + constructor(options) { + var _a, _b, _c; + this._started = false; + this._streamMapping = new Map(); + this._requestToStreamMapping = new Map(); + this._requestResponseMap = new Map(); + this._initialized = false; + this._enableJsonResponse = false; + this._standaloneSseStreamId = '_GET_stream'; + this.sessionIdGenerator = options.sessionIdGenerator; + this._enableJsonResponse = (_a = options.enableJsonResponse) !== null && _a !== void 0 ? _a : false; + this._eventStore = options.eventStore; + this._sessionStorageMode = (_b = options.sessionStorageMode) !== null && _b !== void 0 ? _b : 'memory'; + this._sessionStore = options.sessionStore; + this._onsessioninitialized = options.onsessioninitialized; + this._onsessionclosed = options.onsessionclosed; + this._allowedHosts = options.allowedHosts; + this._allowedOrigins = options.allowedOrigins; + this._enableDnsRebindingProtection = (_c = options.enableDnsRebindingProtection) !== null && _c !== void 0 ? _c : false; + this._retryInterval = options.retryInterval; + // Validate configuration + if (this._sessionStorageMode === 'external' && !this._sessionStore) { + throw new Error('SessionStore is required when sessionStorageMode is "external". ' + + 'Please provide a sessionStore implementation (e.g., RedisSessionStore) or use sessionStorageMode: "memory".'); + } + } + /** + * Returns the current session storage mode + */ + get sessionStorageMode() { + return this._sessionStorageMode; + } + /** + * Returns true if using external session storage + */ + get isUsingExternalSessionStore() { + return this._sessionStorageMode === 'external' && this._sessionStore !== undefined; + } + /** + * Starts the transport. This is required by the Transport interface but is a no-op + * for the Streamable HTTP transport as connections are managed per-request. + */ + async start() { + if (this._started) { + throw new Error('Transport already started'); + } + this._started = true; + } + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + validateRequestHeaders(req) { + // Skip validation if protection is not enabled + if (!this._enableDnsRebindingProtection) { + return undefined; + } + // Validate Host header if allowedHosts is configured + if (this._allowedHosts && this._allowedHosts.length > 0) { + const hostHeader = req.headers.host; + if (!hostHeader || !this._allowedHosts.includes(hostHeader)) { + return `Invalid Host header: ${hostHeader}`; + } + } + // Validate Origin header if allowedOrigins is configured + if (this._allowedOrigins && this._allowedOrigins.length > 0) { + const originHeader = req.headers.origin; + if (!originHeader || !this._allowedOrigins.includes(originHeader)) { + return `Invalid Origin header: ${originHeader}`; + } + } + return undefined; + } + /** + * Handles an incoming HTTP request, whether GET or POST + */ + async handleRequest(req, res, parsedBody) { + var _a; + // Validate request headers for DNS rebinding protection + const validationError = this.validateRequestHeaders(req); + if (validationError) { + res.writeHead(403).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: validationError + }, + id: null + })); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(validationError)); + return; + } + if (req.method === 'POST') { + await this.handlePostRequest(req, res, parsedBody); + } + else if (req.method === 'GET') { + await this.handleGetRequest(req, res); + } + else if (req.method === 'DELETE') { + await this.handleDeleteRequest(req, res); + } + else { + await this.handleUnsupportedRequest(res); + } + } + /** + * Writes a priming event to establish resumption capability. + * Only sends if eventStore is configured (opt-in for resumability). + */ + async _maybeWritePrimingEvent(res, streamId) { + if (!this._eventStore) { + return; + } + const primingEventId = await this._eventStore.storeEvent(streamId, {}); + let primingEvent = `id: ${primingEventId}\ndata: \n\n`; + if (this._retryInterval !== undefined) { + primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`; + } + res.write(primingEvent); + } + /** + * Handles GET requests for SSE stream + */ + async handleGetRequest(req, res) { + // The client MUST include an Accept header, listing text/event-stream as a supported content type. + const acceptHeader = req.headers.accept; + if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('text/event-stream'))) { + res.writeHead(406).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Not Acceptable: Client must accept text/event-stream' + }, + id: null + })); + return; + } + // If an Mcp-Session-Id is returned by the server during initialization, + // clients using the Streamable HTTP transport MUST include it + // in the Mcp-Session-Id header on all of their subsequent HTTP requests. + if (!await this.validateSession(req, res)) { + return; + } + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Handle resumability: check for Last-Event-ID header + if (this._eventStore) { + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + await this.replayEvents(lastEventId, res); + return; + } + } + // The server MUST either return Content-Type: text/event-stream in response to this HTTP GET, + // or else return HTTP 405 Method Not Allowed + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }; + // After initialization, always include the session ID if we have one + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + // Check if there's already an active standalone SSE stream for this session + if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) { + // Only one GET SSE stream is allowed per session + res.writeHead(409).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Conflict: Only one SSE stream is allowed per session' + }, + id: null + })); + return; + } + // We need to send headers immediately as messages will arrive much later, + // otherwise the client will just wait for the first message + res.writeHead(200, headers).flushHeaders(); + // Assign the response to the standalone SSE stream + this._streamMapping.set(this._standaloneSseStreamId, res); + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(this._standaloneSseStreamId); + }); + // Add error handler for standalone SSE stream + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + } + /** + * Replays events that would have been sent after the specified event ID + * Only used when resumability is enabled + */ + async replayEvents(lastEventId, res) { + var _a; + if (!this._eventStore) { + return; + } + try { + // If getStreamIdForEventId is available, use it for conflict checking + let streamId; + if (this._eventStore.getStreamIdForEventId) { + streamId = await this._eventStore.getStreamIdForEventId(lastEventId); + if (!streamId) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Invalid event ID format' + }, + id: null + })); + return; + } + // Check conflict with the SAME streamId we'll use for mapping + if (this._streamMapping.get(streamId) !== undefined) { + res.writeHead(409).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Conflict: Stream already has an active connection' + }, + id: null + })); + return; + } + } + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }; + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + res.writeHead(200, headers).flushHeaders(); + // Replay events - returns the streamId for backwards compatibility + const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, { + send: async (eventId, message) => { + var _a; + if (!this.writeSSEEvent(res, message, eventId)) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error('Failed replay events')); + res.end(); + } + } + }); + this._streamMapping.set(replayedStreamId, res); + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(replayedStreamId); + }); + // Add error handler for replay stream + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + } + } + /** + * Writes an event to the SSE stream with proper formatting + */ + writeSSEEvent(res, message, eventId) { + let eventData = `event: message\n`; + // Include event ID if provided - this is important for resumability + if (eventId) { + eventData += `id: ${eventId}\n`; + } + eventData += `data: ${JSON.stringify(message)}\n\n`; + return res.write(eventData); + } + /** + * Handles unsupported requests (PUT, PATCH, etc.) + */ + async handleUnsupportedRequest(res) { + res.writeHead(405, { + Allow: 'GET, POST, DELETE' + }).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); + } + /** + * Handles POST requests containing JSON-RPC messages + */ + async handlePostRequest(req, res, parsedBody) { + var _a, _b, _c, _d, _e; + try { + // Validate the Accept header + const acceptHeader = req.headers.accept; + // The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types. + if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('application/json')) || !acceptHeader.includes('text/event-stream')) { + res.writeHead(406).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Not Acceptable: Client must accept both application/json and text/event-stream' + }, + id: null + })); + return; + } + const ct = req.headers['content-type']; + if (!ct || !ct.includes('application/json')) { + res.writeHead(415).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Unsupported Media Type: Content-Type must be application/json' + }, + id: null + })); + return; + } + const authInfo = req.auth; + const requestInfo = { headers: req.headers }; + let rawMessage; + if (parsedBody !== undefined) { + rawMessage = parsedBody; + } + else { + const parsedCt = content_type_1.default.parse(ct); + const body = await (0, raw_body_1.default)(req, { + limit: MAXIMUM_MESSAGE_SIZE, + encoding: (_a = parsedCt.parameters.charset) !== null && _a !== void 0 ? _a : 'utf-8' + }); + rawMessage = JSON.parse(body.toString()); + } + let messages; + // handle batch and single messages + if (Array.isArray(rawMessage)) { + messages = rawMessage.map(msg => types_js_1.JSONRPCMessageSchema.parse(msg)); + } + else { + messages = [types_js_1.JSONRPCMessageSchema.parse(rawMessage)]; + } + // Check if this is an initialization request + // https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/ + const isInitializationRequest = messages.some(types_js_1.isInitializeRequest); + if (isInitializationRequest) { + // Check if session already exists (either in-memory or in session store) + let sessionAlreadyExists = this._initialized && this.sessionId !== undefined; + // If using external session storage, also check there + if (!sessionAlreadyExists && this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + sessionAlreadyExists = await this._sessionStore.sessionExists(this.sessionId); + } + // If it's a server with session management and the session ID is already set we should reject the request + // to avoid re-initialization. + if (sessionAlreadyExists) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32600, + message: 'Invalid Request: Server already initialized' + }, + id: null + })); + return; + } + if (messages.length > 1) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32600, + message: 'Invalid Request: Only one initialization request is allowed' + }, + id: null + })); + return; + } + this.sessionId = (_b = this.sessionIdGenerator) === null || _b === void 0 ? void 0 : _b.call(this); + this._initialized = true; + // Store session in external store if using external storage mode + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + const sessionData = { + sessionId: this.sessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + await this._sessionStore.storeSession(this.sessionId, sessionData); + } + // If we have a session ID and an onsessioninitialized handler, call it immediately + // This is needed in cases where the server needs to keep track of multiple sessions + if (this.sessionId && this._onsessioninitialized) { + await Promise.resolve(this._onsessioninitialized(this.sessionId)); + } + } + if (!isInitializationRequest) { + // If an Mcp-Session-Id is returned by the server during initialization, + // clients using the Streamable HTTP transport MUST include it + // in the Mcp-Session-Id header on all of their subsequent HTTP requests. + if (!await this.validateSession(req, res)) { + return; + } + // Mcp-Protocol-Version header is required for all requests after initialization. + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Update session activity if using external session storage + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.updateSessionActivity(this.sessionId); + } + } + // check if it contains requests + const hasRequests = messages.some(types_js_1.isJSONRPCRequest); + if (!hasRequests) { + // if it only contains notifications or responses, return 202 + res.writeHead(202).end(); + // handle each message + for (const message of messages) { + (_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, message, { authInfo, requestInfo }); + } + } + else if (hasRequests) { + // The default behavior is to use SSE streaming + // but in some cases server will return JSON responses + const streamId = (0, node_crypto_1.randomUUID)(); + if (!this._enableJsonResponse) { + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache', + Connection: 'keep-alive' + }; + // After initialization, always include the session ID if we have one + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + res.writeHead(200, headers); + await this._maybeWritePrimingEvent(res, streamId); + } + // Store the response for this request to send messages back through this connection + // We need to track by request ID to maintain the connection + for (const message of messages) { + if ((0, types_js_1.isJSONRPCRequest)(message)) { + this._streamMapping.set(streamId, res); + this._requestToStreamMapping.set(message.id, streamId); + } + } + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(streamId); + }); + // Add error handler for stream write errors + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + // handle each message + for (const message of messages) { + (_d = this.onmessage) === null || _d === void 0 ? void 0 : _d.call(this, message, { authInfo, requestInfo }); + } + // The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses + // This will be handled by the send() method when responses are ready + } + } + catch (error) { + // return JSON-RPC formatted error + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32700, + message: 'Parse error', + data: String(error) + }, + id: null + })); + (_e = this.onerror) === null || _e === void 0 ? void 0 : _e.call(this, error); + } + } + /** + * Handles DELETE requests to terminate sessions + */ + async handleDeleteRequest(req, res) { + var _a; + if (!await this.validateSession(req, res)) { + return; + } + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Delete session from external store if using external storage mode + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.deleteSession(this.sessionId); + } + await Promise.resolve((_a = this._onsessionclosed) === null || _a === void 0 ? void 0 : _a.call(this, this.sessionId)); + await this.close(); + res.writeHead(200).end(); + } + /** + * Validates session ID for non-initialization requests. + * + * When sessionStore is provided, validation checks the external store, + * enabling multi-node deployments where different pods may handle requests + * for the same session. + * + * Returns true if the session is valid, false otherwise. + */ + async validateSession(req, res) { + if (this.sessionIdGenerator === undefined) { + // If the sessionIdGenerator ID is not set, the session management is disabled + // and we don't need to validate the session ID + return true; + } + const requestSessionId = req.headers['mcp-session-id']; + // If using external session storage mode, check external store + if (this._sessionStorageMode === 'external' && this._sessionStore) { + if (!requestSessionId) { + // Non-initialization requests without a session ID should return 400 Bad Request + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header is required' + }, + id: null + })); + return false; + } + else if (Array.isArray(requestSessionId)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header must be a single value' + }, + id: null + })); + return false; + } + // Check if session exists in external store + const sessionData = await this._sessionStore.getSession(requestSessionId); + if (!sessionData) { + res.writeHead(404).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32001, + message: 'Session not found' + }, + id: null + })); + return false; + } + if (!sessionData.initialized) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Server not initialized' + }, + id: null + })); + return false; + } + // Session is valid - update local state if needed + // This enables cross-pod session recovery + if (this.sessionId !== requestSessionId) { + this.sessionId = requestSessionId; + this._initialized = true; + } + return true; + } + // Original in-memory validation logic (no session store) + if (!this._initialized) { + // If the server has not been initialized yet, reject all requests + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Server not initialized' + }, + id: null + })); + return false; + } + if (!requestSessionId) { + // Non-initialization requests without a session ID should return 400 Bad Request + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header is required' + }, + id: null + })); + return false; + } + else if (Array.isArray(requestSessionId)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header must be a single value' + }, + id: null + })); + return false; + } + else if (requestSessionId !== this.sessionId) { + // Reject requests with invalid session ID with 404 Not Found + res.writeHead(404).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32001, + message: 'Session not found' + }, + id: null + })); + return false; + } + return true; + } + validateProtocolVersion(req, res) { + var _a; + let protocolVersion = (_a = req.headers['mcp-protocol-version']) !== null && _a !== void 0 ? _a : types_js_1.DEFAULT_NEGOTIATED_PROTOCOL_VERSION; + if (Array.isArray(protocolVersion)) { + protocolVersion = protocolVersion[protocolVersion.length - 1]; + } + if (!types_js_1.SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: `Bad Request: Unsupported protocol version (supported versions: ${types_js_1.SUPPORTED_PROTOCOL_VERSIONS.join(', ')})` + }, + id: null + })); + return false; + } + return true; + } + async close() { + var _a; + // Close all SSE connections + this._streamMapping.forEach(response => { + response.end(); + }); + this._streamMapping.clear(); + // Clear any pending responses + this._requestResponseMap.clear(); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + /** + * Close an SSE stream for a specific request, triggering client reconnection. + * Use this to implement polling behavior during long-running operations - + * client will reconnect after the retry interval specified in the priming event. + */ + closeSSEStream(requestId) { + const streamId = this._requestToStreamMapping.get(requestId); + if (!streamId) + return; + const stream = this._streamMapping.get(streamId); + if (stream) { + stream.end(); + this._streamMapping.delete(streamId); + } + } + async send(message, options) { + let requestId = options === null || options === void 0 ? void 0 : options.relatedRequestId; + if ((0, types_js_1.isJSONRPCResponse)(message) || (0, types_js_1.isJSONRPCError)(message)) { + // If the message is a response, use the request ID from the message + requestId = message.id; + } + // Check if this message should be sent on the standalone SSE stream (no request ID) + // Ignore notifications from tools (which have relatedRequestId set) + // Those will be sent via dedicated response SSE streams + if (requestId === undefined) { + // For standalone SSE streams, we can only send requests and notifications + if ((0, types_js_1.isJSONRPCResponse)(message) || (0, types_js_1.isJSONRPCError)(message)) { + throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request'); + } + const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId); + if (standaloneSse === undefined) { + // The spec says the server MAY send messages on the stream, so it's ok to discard if no stream + return; + } + // Generate and store event ID if event store is provided + let eventId; + if (this._eventStore) { + // Stores the event and gets the generated event ID + eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message); + } + // Send the message to the standalone SSE stream + this.writeSSEEvent(standaloneSse, message, eventId); + return; + } + // Get the response for this request + const streamId = this._requestToStreamMapping.get(requestId); + const response = this._streamMapping.get(streamId); + if (!streamId) { + throw new Error(`No connection established for request ID: ${String(requestId)}`); + } + if (!this._enableJsonResponse) { + // For SSE responses, generate event ID if event store is provided + let eventId; + if (this._eventStore) { + eventId = await this._eventStore.storeEvent(streamId, message); + } + if (response) { + // Write the event to the response stream + this.writeSSEEvent(response, message, eventId); + } + } + if ((0, types_js_1.isJSONRPCResponse)(message) || (0, types_js_1.isJSONRPCError)(message)) { + this._requestResponseMap.set(requestId, message); + const relatedIds = Array.from(this._requestToStreamMapping.entries()) + .filter(([_, streamId]) => this._streamMapping.get(streamId) === response) + .map(([id]) => id); + // Check if we have responses for all requests using this connection + const allResponsesReady = relatedIds.every(id => this._requestResponseMap.has(id)); + if (allResponsesReady) { + if (!response) { + throw new Error(`No connection established for request ID: ${String(requestId)}`); + } + if (this._enableJsonResponse) { + // All responses ready, send as JSON + const headers = { + 'Content-Type': 'application/json' + }; + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + const responses = relatedIds.map(id => this._requestResponseMap.get(id)); + response.writeHead(200, headers); + if (responses.length === 1) { + response.end(JSON.stringify(responses[0])); + } + else { + response.end(JSON.stringify(responses)); + } + } + else { + // End the SSE stream + response.end(); + } + // Clean up + for (const id of relatedIds) { + this._requestResponseMap.delete(id); + this._requestToStreamMapping.delete(id); + } + } + } + } +} +exports.StreamableHTTPServerTransport = StreamableHTTPServerTransport; +//# sourceMappingURL=streamableHttp.js.map \ No newline at end of file diff --git a/dist/cjs/server/streamableHttp.js.map b/dist/cjs/server/streamableHttp.js.map new file mode 100644 index 000000000..7fd440112 --- /dev/null +++ b/dist/cjs/server/streamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.js","sourceRoot":"","sources":["../../../src/server/streamableHttp.ts"],"names":[],"mappings":";;;;;;AAEA,0CAYqB;AACrB,wDAAkC;AAClC,gEAAuC;AACvC,6CAAyC;AAGzC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAkQnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,6BAA6B;IAyBtC,YAAY,OAA6C;;QAtBjD,aAAQ,GAAY,KAAK,CAAC;QAC1B,mBAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;QACxD,4BAAuB,GAA2B,IAAI,GAAG,EAAE,CAAC;QAC5D,wBAAmB,GAAmC,IAAI,GAAG,EAAE,CAAC;QAChE,iBAAY,GAAY,KAAK,CAAC;QAC9B,wBAAmB,GAAY,KAAK,CAAC;QACrC,2BAAsB,GAAW,aAAa,CAAC;QAiBnD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,mBAAmB,GAAG,MAAA,OAAO,CAAC,kBAAkB,mCAAI,KAAK,CAAC;QAC/D,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,MAAA,OAAO,CAAC,kBAAkB,mCAAI,QAAQ,CAAC;QAClE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAC1D,IAAI,CAAC,gBAAgB,GAAG,OAAO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AAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,CAAC;oBAE1E,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;oBACjC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;wBACzB,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC/C,CAAC;yBAAM,CAAC;wBACJ,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;oBAC5C,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,qBAAqB;oBACrB,QAAQ,CAAC,GAAG,EAAE,CAAC;gBACnB,CAAC;gBACD,WAAW;gBACX,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;oBAC1B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACpC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC5C,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAx2BD,sEAw2BC"} \ No newline at end of file diff --git a/dist/cjs/server/zod-compat.d.ts b/dist/cjs/server/zod-compat.d.ts new file mode 100644 index 000000000..13fb9723c --- /dev/null +++ b/dist/cjs/server/zod-compat.d.ts @@ -0,0 +1,82 @@ +import type * as z3 from 'zod/v3'; +import type * as z4 from 'zod/v4/core'; +export type AnySchema = z3.ZodTypeAny | z4.$ZodType; +export type AnyObjectSchema = z3.AnyZodObject | z4.$ZodObject | AnySchema; +export type ZodRawShapeCompat = Record; +export interface ZodV3Internal { + _def?: { + typeName?: string; + value?: unknown; + values?: unknown[]; + shape?: Record | (() => Record); + description?: string; + }; + shape?: Record | (() => Record); + value?: unknown; +} +export interface ZodV4Internal { + _zod?: { + def?: { + typeName?: string; + value?: unknown; + values?: unknown[]; + shape?: Record | (() => Record); + description?: string; + }; + }; + value?: unknown; +} +export type SchemaOutput = S extends z3.ZodTypeAny ? z3.infer : S extends z4.$ZodType ? z4.output : never; +export type SchemaInput = S extends z3.ZodTypeAny ? z3.input : S extends z4.$ZodType ? z4.input : never; +/** + * Infers the output type from a ZodRawShapeCompat (raw shape object). + * Maps over each key in the shape and infers the output type from each schema. + */ +export type ShapeOutput = { + [K in keyof Shape]: SchemaOutput; +}; +export declare function isZ4Schema(s: AnySchema): s is z4.$ZodType; +export declare function objectFromShape(shape: ZodRawShapeCompat): AnyObjectSchema; +export declare function safeParse(schema: S, data: unknown): { + success: true; + data: SchemaOutput; +} | { + success: false; + error: unknown; +}; +export declare function safeParseAsync(schema: S, data: unknown): Promise<{ + success: true; + data: SchemaOutput; +} | { + success: false; + error: unknown; +}>; +export declare function getObjectShape(schema: AnyObjectSchema | undefined): Record | undefined; +/** + * Normalizes a schema to an object schema. Handles both: + * - Already-constructed object schemas (v3 or v4) + * - Raw shapes that need to be wrapped into object schemas + */ +export declare function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | undefined): AnyObjectSchema | undefined; +/** + * Safely extracts an error message from a parse result error. + * Zod errors can have different structures, so we handle various cases. + */ +export declare function getParseErrorMessage(error: unknown): string; +/** + * Gets the description from a schema, if available. + * Works with both Zod v3 and v4. + */ +export declare function getSchemaDescription(schema: AnySchema): string | undefined; +/** + * Checks if a schema is optional. + * Works with both Zod v3 and v4. + */ +export declare function isSchemaOptional(schema: AnySchema): boolean; +/** + * Gets the literal value from a schema, if it's a literal schema. + * Works with both Zod v3 and v4. + * Returns undefined if the schema is not a literal or the value cannot be determined. + */ +export declare function getLiteralValue(schema: AnySchema): unknown; +//# sourceMappingURL=zod-compat.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/zod-compat.d.ts.map b/dist/cjs/server/zod-compat.d.ts.map new file mode 100644 index 000000000..608ca930c --- /dev/null +++ b/dist/cjs/server/zod-compat.d.ts.map @@ -0,0 +1 @@ +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IAAI,CAAC;IAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CASxF;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,CAyBzG;AAGD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,iBAAiB,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,CAiDpH;AAGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAoB3D;AAGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAQ1E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAW3D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAwB1D"} \ No newline at end of file diff --git a/dist/cjs/server/zod-compat.js b/dist/cjs/server/zod-compat.js new file mode 100644 index 000000000..602a9bf18 --- /dev/null +++ b/dist/cjs/server/zod-compat.js @@ -0,0 +1,252 @@ +"use strict"; +// zod-compat.ts +// ---------------------------------------------------- +// Unified types + helpers to accept Zod v3 and v4 (Mini) +// ---------------------------------------------------- +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isZ4Schema = isZ4Schema; +exports.objectFromShape = objectFromShape; +exports.safeParse = safeParse; +exports.safeParseAsync = safeParseAsync; +exports.getObjectShape = getObjectShape; +exports.normalizeObjectSchema = normalizeObjectSchema; +exports.getParseErrorMessage = getParseErrorMessage; +exports.getSchemaDescription = getSchemaDescription; +exports.isSchemaOptional = isSchemaOptional; +exports.getLiteralValue = getLiteralValue; +const z3rt = __importStar(require("zod/v3")); +const z4mini = __importStar(require("zod/v4-mini")); +// --- Runtime detection --- +function isZ4Schema(s) { + // Present on Zod 4 (Classic & Mini) schemas; absent on Zod 3 + const schema = s; + return !!schema._zod; +} +// --- Schema construction --- +function objectFromShape(shape) { + const values = Object.values(shape); + if (values.length === 0) + return z4mini.object({}); // default to v4 Mini + const allV4 = values.every(isZ4Schema); + const allV3 = values.every(s => !isZ4Schema(s)); + if (allV4) + return z4mini.object(shape); + if (allV3) + return z3rt.object(shape); + throw new Error('Mixed Zod versions detected in object shape.'); +} +// --- Unified parsing --- +function safeParse(schema, data) { + if (isZ4Schema(schema)) { + // Mini exposes top-level safeParse + const result = z4mini.safeParse(schema, data); + return result; + } + const v3Schema = schema; + const result = v3Schema.safeParse(data); + return result; +} +async function safeParseAsync(schema, data) { + if (isZ4Schema(schema)) { + // Mini exposes top-level safeParseAsync + const result = await z4mini.safeParseAsync(schema, data); + return result; + } + const v3Schema = schema; + const result = await v3Schema.safeParseAsync(data); + return result; +} +// --- Shape extraction --- +function getObjectShape(schema) { + var _a, _b; + if (!schema) + return undefined; + // Zod v3 exposes `.shape`; Zod v4 keeps the shape on `_zod.def.shape` + let rawShape; + if (isZ4Schema(schema)) { + const v4Schema = schema; + rawShape = (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.shape; + } + else { + const v3Schema = schema; + rawShape = v3Schema.shape; + } + if (!rawShape) + return undefined; + if (typeof rawShape === 'function') { + try { + return rawShape(); + } + catch (_c) { + return undefined; + } + } + return rawShape; +} +// --- Schema normalization --- +/** + * Normalizes a schema to an object schema. Handles both: + * - Already-constructed object schemas (v3 or v4) + * - Raw shapes that need to be wrapped into object schemas + */ +function normalizeObjectSchema(schema) { + var _a; + if (!schema) + return undefined; + // First check if it's a raw shape (Record) + // Raw shapes don't have _def or _zod properties and aren't schemas themselves + if (typeof schema === 'object') { + // Check if it's actually a ZodRawShapeCompat (not a schema instance) + // by checking if it lacks schema-like internal properties + const asV3 = schema; + const asV4 = schema; + // If it's not a schema instance (no _def or _zod), it might be a raw shape + if (!asV3._def && !asV4._zod) { + // Check if all values are schemas (heuristic to confirm it's a raw shape) + const values = Object.values(schema); + if (values.length > 0 && + values.every(v => typeof v === 'object' && + v !== null && + (v._def !== undefined || + v._zod !== undefined || + typeof v.parse === 'function'))) { + return objectFromShape(schema); + } + } + } + // If we get here, it should be an AnySchema (not a raw shape) + // Check if it's already an object schema + if (isZ4Schema(schema)) { + // Check if it's a v4 object + const v4Schema = schema; + const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + if (def && (def.typeName === 'object' || def.shape !== undefined)) { + return schema; + } + } + else { + // Check if it's a v3 object + const v3Schema = schema; + if (v3Schema.shape !== undefined) { + return schema; + } + } + return undefined; +} +// --- Error message extraction --- +/** + * Safely extracts an error message from a parse result error. + * Zod errors can have different structures, so we handle various cases. + */ +function getParseErrorMessage(error) { + if (error && typeof error === 'object') { + // Try common error structures + if ('message' in error && typeof error.message === 'string') { + return error.message; + } + if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) { + const firstIssue = error.issues[0]; + if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) { + return String(firstIssue.message); + } + } + // Fallback: try to stringify the error + try { + return JSON.stringify(error); + } + catch (_a) { + return String(error); + } + } + return String(error); +} +// --- Schema metadata access --- +/** + * Gets the description from a schema, if available. + * Works with both Zod v3 and v4. + */ +function getSchemaDescription(schema) { + var _a, _b, _c, _d; + if (isZ4Schema(schema)) { + const v4Schema = schema; + return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description; + } + const v3Schema = schema; + // v3 may have description on the schema itself or in _def + return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description; +} +/** + * Checks if a schema is optional. + * Works with both Zod v3 and v4. + */ +function isSchemaOptional(schema) { + var _a, _b, _c; + if (isZ4Schema(schema)) { + const v4Schema = schema; + return ((_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.typeName) === 'ZodOptional'; + } + const v3Schema = schema; + // v3 has isOptional() method + if (typeof schema.isOptional === 'function') { + return schema.isOptional(); + } + return ((_c = v3Schema._def) === null || _c === void 0 ? void 0 : _c.typeName) === 'ZodOptional'; +} +/** + * Gets the literal value from a schema, if it's a literal schema. + * Works with both Zod v3 and v4. + * Returns undefined if the schema is not a literal or the value cannot be determined. + */ +function getLiteralValue(schema) { + var _a; + if (isZ4Schema(schema)) { + const v4Schema = schema; + const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + if (def) { + // Try various ways to get the literal value + if (def.value !== undefined) + return def.value; + if (Array.isArray(def.values) && def.values.length > 0) { + return def.values[0]; + } + } + } + const v3Schema = schema; + const def = v3Schema._def; + if (def) { + if (def.value !== undefined) + return def.value; + if (Array.isArray(def.values) && def.values.length > 0) { + return def.values[0]; + } + } + // Fallback: check for direct value property (some Zod versions) + const directValue = schema.value; + if (directValue !== undefined) + return directValue; + return undefined; +} +//# sourceMappingURL=zod-compat.js.map \ No newline at end of file diff --git a/dist/cjs/server/zod-compat.js.map b/dist/cjs/server/zod-compat.js.map new file mode 100644 index 000000000..ef6828d20 --- /dev/null +++ b/dist/cjs/server/zod-compat.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-compat.js","sourceRoot":"","sources":["../../../src/server/zod-compat.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,uDAAuD;AACvD,yDAAyD;AACzD,uDAAuD;;;;;;;;;;;;;;;;;;;;;;;;;AAsDvD,gCAIC;AAGD,0CAWC;AAGD,8BAYC;AAED,wCAYC;AAGD,wCAyBC;AAQD,sDAiDC;AAOD,oDAoBC;AAOD,oDAQC;AAMD,4CAWC;AAOD,0CAwBC;AA/QD,6CAA+B;AAC/B,oDAAsC;AA+CtC,4BAA4B;AAC5B,SAAgB,UAAU,CAAC,CAAY;IACnC,6DAA6D;IAC7D,MAAM,MAAM,GAAG,CAA6B,CAAC;IAC7C,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;AACzB,CAAC;AAED,8BAA8B;AAC9B,SAAgB,eAAe,CAAC,KAAwB;IACpD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB;IAExE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,IAAI,KAAK;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,KAAoC,CAAC,CAAC;IACtE,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAsC,CAAC,CAAC;IAEtE,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AE,CAAC;YACN,4CAA4C;YAC5C,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;gBAAE,OAAO,GAAG,CAAC,KAAK,CAAC;YAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,MAAkC,CAAC;IACpD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC1B,IAAI,GAAG,EAAE,CAAC;QACN,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;IACL,CAAC;IACD,gEAAgE;IAChE,MAAM,WAAW,GAAI,MAA8B,CAAC,KAAK,CAAC;IAC1D,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAClD,OAAO,SAAS,CAAC;AACrB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/server/zod-json-schema-compat.d.ts b/dist/cjs/server/zod-json-schema-compat.d.ts new file mode 100644 index 000000000..3a04452b4 --- /dev/null +++ b/dist/cjs/server/zod-json-schema-compat.d.ts @@ -0,0 +1,12 @@ +import { AnySchema, AnyObjectSchema } from './zod-compat.js'; +type JsonSchema = Record; +type CommonOpts = { + strictUnions?: boolean; + pipeStrategy?: 'input' | 'output'; + target?: 'jsonSchema7' | 'draft-7' | 'jsonSchema2019-09' | 'draft-2020-12'; +}; +export declare function toJsonSchemaCompat(schema: AnyObjectSchema, opts?: CommonOpts): JsonSchema; +export declare function getMethodLiteral(schema: AnyObjectSchema): string; +export declare function parseWithCompat(schema: AnySchema, data: unknown): unknown; +export {}; +//# sourceMappingURL=zod-json-schema-compat.d.ts.map \ No newline at end of file diff --git a/dist/cjs/server/zod-json-schema-compat.d.ts.map b/dist/cjs/server/zod-json-schema-compat.d.ts.map new file mode 100644 index 000000000..0b851bf50 --- /dev/null +++ b/dist/cjs/server/zod-json-schema-compat.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-json-schema-compat.d.ts","sourceRoot":"","sources":["../../../src/server/zod-json-schema-compat.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,eAAe,EAA0D,MAAM,iBAAiB,CAAC;AAGrH,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAG1C,KAAK,UAAU,GAAG;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,mBAAmB,GAAG,eAAe,CAAC;CAC9E,CAAC;AASF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,CAczF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAahE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAMzE"} \ No newline at end of file diff --git a/dist/cjs/server/zod-json-schema-compat.js b/dist/cjs/server/zod-json-schema-compat.js new file mode 100644 index 000000000..e42265d4c --- /dev/null +++ b/dist/cjs/server/zod-json-schema-compat.js @@ -0,0 +1,80 @@ +"use strict"; +// zod-json-schema-compat.ts +// ---------------------------------------------------- +// JSON Schema conversion for both Zod v3 and Zod v4 (Mini) +// v3 uses your vendored converter; v4 uses Mini's toJSONSchema +// ---------------------------------------------------- +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toJsonSchemaCompat = toJsonSchemaCompat; +exports.getMethodLiteral = getMethodLiteral; +exports.parseWithCompat = parseWithCompat; +const z4mini = __importStar(require("zod/v4-mini")); +const zod_compat_js_1 = require("./zod-compat.js"); +const zod_to_json_schema_1 = require("zod-to-json-schema"); +function mapMiniTarget(t) { + if (!t) + return 'draft-7'; + if (t === 'jsonSchema7' || t === 'draft-7') + return 'draft-7'; + if (t === 'jsonSchema2019-09' || t === 'draft-2020-12') + return 'draft-2020-12'; + return 'draft-7'; // fallback +} +function toJsonSchemaCompat(schema, opts) { + var _a, _b, _c; + if ((0, zod_compat_js_1.isZ4Schema)(schema)) { + // v4 branch — use Mini's built-in toJSONSchema + return z4mini.toJSONSchema(schema, { + target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target), + io: (_a = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _a !== void 0 ? _a : 'input' + }); + } + // v3 branch — use vendored converter + return (0, zod_to_json_schema_1.zodToJsonSchema)(schema, { + strictUnions: (_b = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b !== void 0 ? _b : true, + pipeStrategy: (_c = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _c !== void 0 ? _c : 'input' + }); +} +function getMethodLiteral(schema) { + const shape = (0, zod_compat_js_1.getObjectShape)(schema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + const value = (0, zod_compat_js_1.getLiteralValue)(methodSchema); + if (typeof value !== 'string') { + throw new Error('Schema method literal must be a string'); + } + return value; +} +function parseWithCompat(schema, data) { + const result = (0, zod_compat_js_1.safeParse)(schema, data); + if (!result.success) { + throw result.error; + } + return result.data; +} +//# sourceMappingURL=zod-json-schema-compat.js.map \ No newline at end of file diff --git a/dist/cjs/server/zod-json-schema-compat.js.map b/dist/cjs/server/zod-json-schema-compat.js.map new file mode 100644 index 000000000..4cda29da4 --- /dev/null +++ b/dist/cjs/server/zod-json-schema-compat.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-json-schema-compat.js","sourceRoot":"","sources":["../../../src/server/zod-json-schema-compat.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,uDAAuD;AACvD,2DAA2D;AAC3D,+DAA+D;AAC/D,uDAAuD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BvD,gDAcC;AAED,4CAaC;AAED,0CAMC;AA1DD,oDAAsC;AAEtC,mDAAqH;AACrH,2DAAqD;AAWrD,SAAS,aAAa,CAAC,CAAmC;IACtD,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC7D,IAAI,CAAC,KAAK,mBAAmB,IAAI,CAAC,KAAK,eAAe;QAAE,OAAO,eAAe,CAAC;IAC/E,OAAO,SAAS,CAAC,CAAC,WAAW;AACjC,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAuB,EAAE,IAAiB;;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MAAM,CAAC,KAAK,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACvB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/auth-utils.d.ts b/dist/cjs/shared/auth-utils.d.ts new file mode 100644 index 000000000..c966e30e7 --- /dev/null +++ b/dist/cjs/shared/auth-utils.d.ts @@ -0,0 +1,23 @@ +/** + * Utilities for handling OAuth resource URIs. + */ +/** + * Converts a server URL to a resource URL by removing the fragment. + * RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component". + * Keeps everything else unchanged (scheme, domain, port, path, query). + */ +export declare function resourceUrlFromServerUrl(url: URL | string): URL; +/** + * Checks if a requested resource URL matches a configured resource URL. + * A requested resource matches if it has the same scheme, domain, port, + * and its path starts with the configured resource's path. + * + * @param requestedResource The resource URL being requested + * @param configuredResource The resource URL that has been configured + * @returns true if the requested resource matches the configured resource, false otherwise + */ +export declare function checkResourceAllowed({ requestedResource, configuredResource }: { + requestedResource: URL | string; + configuredResource: URL | string; +}): boolean; +//# sourceMappingURL=auth-utils.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/auth-utils.d.ts.map b/dist/cjs/shared/auth-utils.d.ts.map new file mode 100644 index 000000000..30873de55 --- /dev/null +++ b/dist/cjs/shared/auth-utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../../src/shared/auth-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,CAI/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EACjC,iBAAiB,EACjB,kBAAkB,EACrB,EAAE;IACC,iBAAiB,EAAE,GAAG,GAAG,MAAM,CAAC;IAChC,kBAAkB,EAAE,GAAG,GAAG,MAAM,CAAC;CACpC,GAAG,OAAO,CAwBV"} \ No newline at end of file diff --git a/dist/cjs/shared/auth-utils.js b/dist/cjs/shared/auth-utils.js new file mode 100644 index 000000000..f2fe61734 --- /dev/null +++ b/dist/cjs/shared/auth-utils.js @@ -0,0 +1,48 @@ +"use strict"; +/** + * Utilities for handling OAuth resource URIs. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.resourceUrlFromServerUrl = resourceUrlFromServerUrl; +exports.checkResourceAllowed = checkResourceAllowed; +/** + * Converts a server URL to a resource URL by removing the fragment. + * RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component". + * Keeps everything else unchanged (scheme, domain, port, path, query). + */ +function resourceUrlFromServerUrl(url) { + const resourceURL = typeof url === 'string' ? new URL(url) : new URL(url.href); + resourceURL.hash = ''; // Remove fragment + return resourceURL; +} +/** + * Checks if a requested resource URL matches a configured resource URL. + * A requested resource matches if it has the same scheme, domain, port, + * and its path starts with the configured resource's path. + * + * @param requestedResource The resource URL being requested + * @param configuredResource The resource URL that has been configured + * @returns true if the requested resource matches the configured resource, false otherwise + */ +function checkResourceAllowed({ requestedResource, configuredResource }) { + const requested = typeof requestedResource === 'string' ? new URL(requestedResource) : new URL(requestedResource.href); + const configured = typeof configuredResource === 'string' ? new URL(configuredResource) : new URL(configuredResource.href); + // Compare the origin (scheme, domain, and port) + if (requested.origin !== configured.origin) { + return false; + } + // Handle cases like requested=/foo and configured=/foo/ + if (requested.pathname.length < configured.pathname.length) { + return false; + } + // Check if the requested path starts with the configured path + // Ensure both paths end with / for proper comparison + // This ensures that if we have paths like "/api" and "/api/users", + // we properly detect that "/api/users" is a subpath of "/api" + // By adding a trailing slash if missing, we avoid false positives + // where paths like "/api123" would incorrectly match "/api" + const requestedPath = requested.pathname.endsWith('/') ? requested.pathname : requested.pathname + '/'; + const configuredPath = configured.pathname.endsWith('/') ? configured.pathname : configured.pathname + '/'; + return requestedPath.startsWith(configuredPath); +} +//# sourceMappingURL=auth-utils.js.map \ No newline at end of file diff --git a/dist/cjs/shared/auth-utils.js.map b/dist/cjs/shared/auth-utils.js.map new file mode 100644 index 000000000..4a71b257b --- /dev/null +++ b/dist/cjs/shared/auth-utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-utils.js","sourceRoot":"","sources":["../../../src/shared/auth-utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAOH,4DAIC;AAWD,oDA8BC;AAlDD;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,GAAiB;IACtD,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/E,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,kBAAkB;IACzC,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,EACjC,iBAAiB,EACjB,kBAAkB,EAIrB;IACG,MAAM,SAAS,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvH,MAAM,UAAU,GAAG,OAAO,kBAAkB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAE3H,gDAAgD;IAChD,IAAI,SAAS,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,wDAAwD;IACxD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,8DAA8D;IAC9D,qDAAqD;IACrD,mEAAmE;IACnE,8DAA8D;IAC9D,kEAAkE;IAClE,4DAA4D;IAC5D,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,GAAG,GAAG,CAAC;IACvG,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,GAAG,GAAG,CAAC;IAE3G,OAAO,aAAa,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACpD,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/auth.d.ts b/dist/cjs/shared/auth.d.ts new file mode 100644 index 000000000..4e47be12b --- /dev/null +++ b/dist/cjs/shared/auth.d.ts @@ -0,0 +1,240 @@ +import * as z from 'zod/v4'; +/** + * Reusable URL validation that disallows javascript: scheme + */ +export declare const SafeUrlSchema: z.ZodURL; +/** + * RFC 9728 OAuth Protected Resource Metadata + */ +export declare const OAuthProtectedResourceMetadataSchema: z.ZodObject<{ + resource: z.ZodString; + authorization_servers: z.ZodOptional>; + jwks_uri: z.ZodOptional; + scopes_supported: z.ZodOptional>; + bearer_methods_supported: z.ZodOptional>; + resource_signing_alg_values_supported: z.ZodOptional>; + resource_name: z.ZodOptional; + resource_documentation: z.ZodOptional; + resource_policy_uri: z.ZodOptional; + resource_tos_uri: z.ZodOptional; + tls_client_certificate_bound_access_tokens: z.ZodOptional; + authorization_details_types_supported: z.ZodOptional>; + dpop_signing_alg_values_supported: z.ZodOptional>; + dpop_bound_access_tokens_required: z.ZodOptional; +}, z.core.$loose>; +/** + * RFC 8414 OAuth 2.0 Authorization Server Metadata + */ +export declare const OAuthMetadataSchema: z.ZodObject<{ + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + revocation_endpoint: z.ZodOptional; + revocation_endpoint_auth_methods_supported: z.ZodOptional>; + revocation_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + introspection_endpoint: z.ZodOptional; + introspection_endpoint_auth_methods_supported: z.ZodOptional>; + introspection_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + code_challenge_methods_supported: z.ZodOptional>; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$loose>; +/** + * OpenID Connect Discovery 1.0 Provider Metadata + * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata + */ +export declare const OpenIdProviderMetadataSchema: z.ZodObject<{ + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + userinfo_endpoint: z.ZodOptional; + jwks_uri: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + acr_values_supported: z.ZodOptional>; + subject_types_supported: z.ZodArray; + id_token_signing_alg_values_supported: z.ZodArray; + id_token_encryption_alg_values_supported: z.ZodOptional>; + id_token_encryption_enc_values_supported: z.ZodOptional>; + userinfo_signing_alg_values_supported: z.ZodOptional>; + userinfo_encryption_alg_values_supported: z.ZodOptional>; + userinfo_encryption_enc_values_supported: z.ZodOptional>; + request_object_signing_alg_values_supported: z.ZodOptional>; + request_object_encryption_alg_values_supported: z.ZodOptional>; + request_object_encryption_enc_values_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + display_values_supported: z.ZodOptional>; + claim_types_supported: z.ZodOptional>; + claims_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + claims_locales_supported: z.ZodOptional>; + ui_locales_supported: z.ZodOptional>; + claims_parameter_supported: z.ZodOptional; + request_parameter_supported: z.ZodOptional; + request_uri_parameter_supported: z.ZodOptional; + require_request_uri_registration: z.ZodOptional; + op_policy_uri: z.ZodOptional; + op_tos_uri: z.ZodOptional; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$loose>; +/** + * OpenID Connect Discovery metadata that may include OAuth 2.0 fields + * This schema represents the real-world scenario where OIDC providers + * return a mix of OpenID Connect and OAuth 2.0 metadata fields + */ +export declare const OpenIdProviderDiscoveryMetadataSchema: z.ZodObject<{ + code_challenge_methods_supported: z.ZodOptional>; + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + userinfo_endpoint: z.ZodOptional; + jwks_uri: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + acr_values_supported: z.ZodOptional>; + subject_types_supported: z.ZodArray; + id_token_signing_alg_values_supported: z.ZodArray; + id_token_encryption_alg_values_supported: z.ZodOptional>; + id_token_encryption_enc_values_supported: z.ZodOptional>; + userinfo_signing_alg_values_supported: z.ZodOptional>; + userinfo_encryption_alg_values_supported: z.ZodOptional>; + userinfo_encryption_enc_values_supported: z.ZodOptional>; + request_object_signing_alg_values_supported: z.ZodOptional>; + request_object_encryption_alg_values_supported: z.ZodOptional>; + request_object_encryption_enc_values_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + display_values_supported: z.ZodOptional>; + claim_types_supported: z.ZodOptional>; + claims_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + claims_locales_supported: z.ZodOptional>; + ui_locales_supported: z.ZodOptional>; + claims_parameter_supported: z.ZodOptional; + request_parameter_supported: z.ZodOptional; + request_uri_parameter_supported: z.ZodOptional; + require_request_uri_registration: z.ZodOptional; + op_policy_uri: z.ZodOptional; + op_tos_uri: z.ZodOptional; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$strip>; +/** + * OAuth 2.1 token response + */ +export declare const OAuthTokensSchema: z.ZodObject<{ + access_token: z.ZodString; + id_token: z.ZodOptional; + token_type: z.ZodString; + expires_in: z.ZodOptional>; + scope: z.ZodOptional; + refresh_token: z.ZodOptional; +}, z.core.$strip>; +/** + * OAuth 2.1 error response + */ +export declare const OAuthErrorResponseSchema: z.ZodObject<{ + error: z.ZodString; + error_description: z.ZodOptional; + error_uri: z.ZodOptional; +}, z.core.$strip>; +/** + * Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri + */ +export declare const OptionalSafeUrlSchema: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata + */ +export declare const OAuthClientMetadataSchema: z.ZodObject<{ + redirect_uris: z.ZodArray; + token_endpoint_auth_method: z.ZodOptional; + grant_types: z.ZodOptional>; + response_types: z.ZodOptional>; + client_name: z.ZodOptional; + client_uri: z.ZodOptional; + logo_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + scope: z.ZodOptional; + contacts: z.ZodOptional>; + tos_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + policy_uri: z.ZodOptional; + jwks_uri: z.ZodOptional; + jwks: z.ZodOptional; + software_id: z.ZodOptional; + software_version: z.ZodOptional; + software_statement: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration client information + */ +export declare const OAuthClientInformationSchema: z.ZodObject<{ + client_id: z.ZodString; + client_secret: z.ZodOptional; + client_id_issued_at: z.ZodOptional; + client_secret_expires_at: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata) + */ +export declare const OAuthClientInformationFullSchema: z.ZodObject<{ + redirect_uris: z.ZodArray; + token_endpoint_auth_method: z.ZodOptional; + grant_types: z.ZodOptional>; + response_types: z.ZodOptional>; + client_name: z.ZodOptional; + client_uri: z.ZodOptional; + logo_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + scope: z.ZodOptional; + contacts: z.ZodOptional>; + tos_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + policy_uri: z.ZodOptional; + jwks_uri: z.ZodOptional; + jwks: z.ZodOptional; + software_id: z.ZodOptional; + software_version: z.ZodOptional; + software_statement: z.ZodOptional; + client_id: z.ZodString; + client_secret: z.ZodOptional; + client_id_issued_at: z.ZodOptional; + client_secret_expires_at: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration error response + */ +export declare const OAuthClientRegistrationErrorSchema: z.ZodObject<{ + error: z.ZodString; + error_description: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7009 OAuth 2.0 Token Revocation request + */ +export declare const OAuthTokenRevocationRequestSchema: z.ZodObject<{ + token: z.ZodString; + token_type_hint: z.ZodOptional; +}, z.core.$strip>; +export type OAuthMetadata = z.infer; +export type OpenIdProviderMetadata = z.infer; +export type OpenIdProviderDiscoveryMetadata = z.infer; +export type OAuthTokens = z.infer; +export type OAuthErrorResponse = z.infer; +export type OAuthClientMetadata = z.infer; +export type OAuthClientInformation = z.infer; +export type OAuthClientInformationFull = z.infer; +export type OAuthClientInformationMixed = OAuthClientInformation | OAuthClientInformationFull; +export type OAuthClientRegistrationError = z.infer; +export type OAuthTokenRevocationRequest = z.infer; +export type OAuthProtectedResourceMetadata = z.infer; +export type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetadata; +//# sourceMappingURL=auth.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/auth.d.ts.map b/dist/cjs/shared/auth.d.ts.map new file mode 100644 index 000000000..031a88fb9 --- /dev/null +++ b/dist/cjs/shared/auth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/shared/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,aAAa,UAmBrB,CAAC;AAEN;;GAEG;AACH,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;iBAe/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;iBAoB9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCvC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAKhD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;iBASlB,CAAC;AAEb;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,mGAAwE,CAAC;AAE3G;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;iBAmB1B,CAAC;AAEb;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;;iBAO7B,CAAC;AAEb;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;iBAAgE,CAAC;AAE9G;;GAEG;AACH,eAAO,MAAM,kCAAkC;;;iBAKnC,CAAC;AAEb;;GAEG;AACH,eAAO,MAAM,iCAAiC;;;iBAKlC,CAAC;AAEb,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qCAAqC,CAAC,CAAC;AAEpG,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC5E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAC1F,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAAG,0BAA0B,CAAC;AAC9F,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAC9F,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAC5F,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oCAAoC,CAAC,CAAC;AAGlG,MAAM,MAAM,2BAA2B,GAAG,aAAa,GAAG,+BAA+B,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/auth.js b/dist/cjs/shared/auth.js new file mode 100644 index 000000000..97217c9c8 --- /dev/null +++ b/dist/cjs/shared/auth.js @@ -0,0 +1,224 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OAuthTokenRevocationRequestSchema = exports.OAuthClientRegistrationErrorSchema = exports.OAuthClientInformationFullSchema = exports.OAuthClientInformationSchema = exports.OAuthClientMetadataSchema = exports.OptionalSafeUrlSchema = exports.OAuthErrorResponseSchema = exports.OAuthTokensSchema = exports.OpenIdProviderDiscoveryMetadataSchema = exports.OpenIdProviderMetadataSchema = exports.OAuthMetadataSchema = exports.OAuthProtectedResourceMetadataSchema = exports.SafeUrlSchema = void 0; +const z = __importStar(require("zod/v4")); +/** + * Reusable URL validation that disallows javascript: scheme + */ +exports.SafeUrlSchema = z + .url() + .superRefine((val, ctx) => { + if (!URL.canParse(val)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'URL must be parseable', + fatal: true + }); + return z.NEVER; + } +}) + .refine(url => { + const u = new URL(url); + return u.protocol !== 'javascript:' && u.protocol !== 'data:' && u.protocol !== 'vbscript:'; +}, { message: 'URL cannot use javascript:, data:, or vbscript: scheme' }); +/** + * RFC 9728 OAuth Protected Resource Metadata + */ +exports.OAuthProtectedResourceMetadataSchema = z.looseObject({ + resource: z.string().url(), + authorization_servers: z.array(exports.SafeUrlSchema).optional(), + jwks_uri: z.string().url().optional(), + scopes_supported: z.array(z.string()).optional(), + bearer_methods_supported: z.array(z.string()).optional(), + resource_signing_alg_values_supported: z.array(z.string()).optional(), + resource_name: z.string().optional(), + resource_documentation: z.string().optional(), + resource_policy_uri: z.string().url().optional(), + resource_tos_uri: z.string().url().optional(), + tls_client_certificate_bound_access_tokens: z.boolean().optional(), + authorization_details_types_supported: z.array(z.string()).optional(), + dpop_signing_alg_values_supported: z.array(z.string()).optional(), + dpop_bound_access_tokens_required: z.boolean().optional() +}); +/** + * RFC 8414 OAuth 2.0 Authorization Server Metadata + */ +exports.OAuthMetadataSchema = z.looseObject({ + issuer: z.string(), + authorization_endpoint: exports.SafeUrlSchema, + token_endpoint: exports.SafeUrlSchema, + registration_endpoint: exports.SafeUrlSchema.optional(), + scopes_supported: z.array(z.string()).optional(), + response_types_supported: z.array(z.string()), + response_modes_supported: z.array(z.string()).optional(), + grant_types_supported: z.array(z.string()).optional(), + token_endpoint_auth_methods_supported: z.array(z.string()).optional(), + token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + service_documentation: exports.SafeUrlSchema.optional(), + revocation_endpoint: exports.SafeUrlSchema.optional(), + revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(), + revocation_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + introspection_endpoint: z.string().optional(), + introspection_endpoint_auth_methods_supported: z.array(z.string()).optional(), + introspection_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + code_challenge_methods_supported: z.array(z.string()).optional(), + client_id_metadata_document_supported: z.boolean().optional() +}); +/** + * OpenID Connect Discovery 1.0 Provider Metadata + * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata + */ +exports.OpenIdProviderMetadataSchema = z.looseObject({ + issuer: z.string(), + authorization_endpoint: exports.SafeUrlSchema, + token_endpoint: exports.SafeUrlSchema, + userinfo_endpoint: exports.SafeUrlSchema.optional(), + jwks_uri: exports.SafeUrlSchema, + registration_endpoint: exports.SafeUrlSchema.optional(), + scopes_supported: z.array(z.string()).optional(), + response_types_supported: z.array(z.string()), + response_modes_supported: z.array(z.string()).optional(), + grant_types_supported: z.array(z.string()).optional(), + acr_values_supported: z.array(z.string()).optional(), + subject_types_supported: z.array(z.string()), + id_token_signing_alg_values_supported: z.array(z.string()), + id_token_encryption_alg_values_supported: z.array(z.string()).optional(), + id_token_encryption_enc_values_supported: z.array(z.string()).optional(), + userinfo_signing_alg_values_supported: z.array(z.string()).optional(), + userinfo_encryption_alg_values_supported: z.array(z.string()).optional(), + userinfo_encryption_enc_values_supported: z.array(z.string()).optional(), + request_object_signing_alg_values_supported: z.array(z.string()).optional(), + request_object_encryption_alg_values_supported: z.array(z.string()).optional(), + request_object_encryption_enc_values_supported: z.array(z.string()).optional(), + token_endpoint_auth_methods_supported: z.array(z.string()).optional(), + token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + display_values_supported: z.array(z.string()).optional(), + claim_types_supported: z.array(z.string()).optional(), + claims_supported: z.array(z.string()).optional(), + service_documentation: z.string().optional(), + claims_locales_supported: z.array(z.string()).optional(), + ui_locales_supported: z.array(z.string()).optional(), + claims_parameter_supported: z.boolean().optional(), + request_parameter_supported: z.boolean().optional(), + request_uri_parameter_supported: z.boolean().optional(), + require_request_uri_registration: z.boolean().optional(), + op_policy_uri: exports.SafeUrlSchema.optional(), + op_tos_uri: exports.SafeUrlSchema.optional(), + client_id_metadata_document_supported: z.boolean().optional() +}); +/** + * OpenID Connect Discovery metadata that may include OAuth 2.0 fields + * This schema represents the real-world scenario where OIDC providers + * return a mix of OpenID Connect and OAuth 2.0 metadata fields + */ +exports.OpenIdProviderDiscoveryMetadataSchema = z.object({ + ...exports.OpenIdProviderMetadataSchema.shape, + ...exports.OAuthMetadataSchema.pick({ + code_challenge_methods_supported: true + }).shape +}); +/** + * OAuth 2.1 token response + */ +exports.OAuthTokensSchema = z + .object({ + access_token: z.string(), + id_token: z.string().optional(), // Optional for OAuth 2.1, but necessary in OpenID Connect + token_type: z.string(), + expires_in: z.coerce.number().optional(), + scope: z.string().optional(), + refresh_token: z.string().optional() +}) + .strip(); +/** + * OAuth 2.1 error response + */ +exports.OAuthErrorResponseSchema = z.object({ + error: z.string(), + error_description: z.string().optional(), + error_uri: z.string().optional() +}); +/** + * Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri + */ +exports.OptionalSafeUrlSchema = exports.SafeUrlSchema.optional().or(z.literal('').transform(() => undefined)); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata + */ +exports.OAuthClientMetadataSchema = z + .object({ + redirect_uris: z.array(exports.SafeUrlSchema), + token_endpoint_auth_method: z.string().optional(), + grant_types: z.array(z.string()).optional(), + response_types: z.array(z.string()).optional(), + client_name: z.string().optional(), + client_uri: exports.SafeUrlSchema.optional(), + logo_uri: exports.OptionalSafeUrlSchema, + scope: z.string().optional(), + contacts: z.array(z.string()).optional(), + tos_uri: exports.OptionalSafeUrlSchema, + policy_uri: z.string().optional(), + jwks_uri: exports.SafeUrlSchema.optional(), + jwks: z.any().optional(), + software_id: z.string().optional(), + software_version: z.string().optional(), + software_statement: z.string().optional() +}) + .strip(); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration client information + */ +exports.OAuthClientInformationSchema = z + .object({ + client_id: z.string(), + client_secret: z.string().optional(), + client_id_issued_at: z.number().optional(), + client_secret_expires_at: z.number().optional() +}) + .strip(); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata) + */ +exports.OAuthClientInformationFullSchema = exports.OAuthClientMetadataSchema.merge(exports.OAuthClientInformationSchema); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration error response + */ +exports.OAuthClientRegistrationErrorSchema = z + .object({ + error: z.string(), + error_description: z.string().optional() +}) + .strip(); +/** + * RFC 7009 OAuth 2.0 Token Revocation request + */ +exports.OAuthTokenRevocationRequestSchema = z + .object({ + token: z.string(), + token_type_hint: z.string().optional() +}) + .strip(); +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/dist/cjs/shared/auth.js.map b/dist/cjs/shared/auth.js.map new file mode 100644 index 000000000..310255ae1 --- /dev/null +++ b/dist/cjs/shared/auth.js.map @@ -0,0 +1 @@ +{"version":3,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1C,wBAAwB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClD,CAAC;KACD,KAAK,EAAE,CAAC;AAEb;;GAEG;AACU,QAAA,gCAAgC,GAAG,iCAAyB,CAAC,KAAK,CAAC,oCAA4B,CAAC,CAAC;AAE9G;;GAEG;AACU,QAAA,kCAAkC,GAAG,CAAC;KAC9C,MAAM,CAAC;IACJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC3C,CAAC;KACD,KAAK,EAAE,CAAC;AAEb;;GAEG;AACU,QAAA,iCAAiC,GAAG,CAAC;KAC7C,MAAM,CAAC;IACJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACzC,CAAC;KACD,KAAK,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/metadataUtils.d.ts b/dist/cjs/shared/metadataUtils.d.ts new file mode 100644 index 000000000..c0e738bab --- /dev/null +++ b/dist/cjs/shared/metadataUtils.d.ts @@ -0,0 +1,16 @@ +import { BaseMetadata } from '../types.js'; +/** + * Utilities for working with BaseMetadata objects. + */ +/** + * Gets the display name for an object with BaseMetadata. + * For tools, the precedence is: title → annotations.title → name + * For other objects: title → name + * This implements the spec requirement: "if no title is provided, name should be used for display purposes" + */ +export declare function getDisplayName(metadata: BaseMetadata & { + annotations?: { + title?: string; + }; +}): string; +//# sourceMappingURL=metadataUtils.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/metadataUtils.d.ts.map b/dist/cjs/shared/metadataUtils.d.ts.map new file mode 100644 index 000000000..596805eb3 --- /dev/null +++ b/dist/cjs/shared/metadataUtils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"metadataUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/metadataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG;IAAE,WAAW,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,CAapG"} \ No newline at end of file diff --git a/dist/cjs/shared/metadataUtils.js b/dist/cjs/shared/metadataUtils.js new file mode 100644 index 000000000..07e8ec4c4 --- /dev/null +++ b/dist/cjs/shared/metadataUtils.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getDisplayName = getDisplayName; +/** + * Utilities for working with BaseMetadata objects. + */ +/** + * Gets the display name for an object with BaseMetadata. + * For tools, the precedence is: title → annotations.title → name + * For other objects: title → name + * This implements the spec requirement: "if no title is provided, name should be used for display purposes" + */ +function getDisplayName(metadata) { + var _a; + // First check for title (not undefined and not empty string) + if (metadata.title !== undefined && metadata.title !== '') { + return metadata.title; + } + // Then check for annotations.title (only present in Tool objects) + if ((_a = metadata.annotations) === null || _a === void 0 ? void 0 : _a.title) { + return metadata.annotations.title; + } + // Finally fall back to name + return metadata.name; +} +//# sourceMappingURL=metadataUtils.js.map \ No newline at end of file diff --git a/dist/cjs/shared/metadataUtils.js.map b/dist/cjs/shared/metadataUtils.js.map new file mode 100644 index 000000000..e9e9cc69e --- /dev/null +++ b/dist/cjs/shared/metadataUtils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"metadataUtils.js","sourceRoot":"","sources":["../../../src/shared/metadataUtils.ts"],"names":[],"mappings":";;AAYA,wCAaC;AAvBD;;GAEG;AAEH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAA6D;;IACxF,6DAA6D;IAC7D,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;QACxD,OAAO,QAAQ,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,kEAAkE;IAClE,IAAI,MAAA,QAAQ,CAAC,WAAW,0CAAE,KAAK,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;IACtC,CAAC;IAED,4BAA4B;IAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/protocol.d.ts b/dist/cjs/shared/protocol.d.ts new file mode 100644 index 000000000..f55626baa --- /dev/null +++ b/dist/cjs/shared/protocol.d.ts @@ -0,0 +1,431 @@ +import { AnySchema, AnyObjectSchema, SchemaOutput } from '../server/zod-compat.js'; +import { ClientCapabilities, GetTaskRequest, GetTaskPayloadRequest, ListTasksResultSchema, CancelTaskResultSchema, JSONRPCRequest, Notification, Progress, Request, RequestId, Result, ServerCapabilities, RequestMeta, RequestInfo, GetTaskResult, TaskCreationParams, RelatedTaskMetadata, Task } from '../types.js'; +import { Transport, TransportSendOptions } from './transport.js'; +import { AuthInfo } from '../server/auth/types.js'; +import { TaskStore, TaskMessageQueue, CreateTaskOptions } from '../experimental/tasks/interfaces.js'; +import { ResponseMessage } from './responseMessage.js'; +/** + * Callback for progress notifications. + */ +export type ProgressCallback = (progress: Progress) => void; +/** + * Additional initialization options. + */ +export type ProtocolOptions = { + /** + * Whether to restrict emitted requests to only those that the remote side has indicated that they can handle, through their advertised capabilities. + * + * Note that this DOES NOT affect checking of _local_ side capabilities, as it is considered a logic error to mis-specify those. + * + * Currently this defaults to false, for backwards compatibility with SDK versions that did not advertise capabilities correctly. In future, this will default to true. + */ + enforceStrictCapabilities?: boolean; + /** + * An array of notification method names that should be automatically debounced. + * Any notifications with a method in this list will be coalesced if they + * occur in the same tick of the event loop. + * e.g., ['notifications/tools/list_changed'] + */ + debouncedNotificationMethods?: string[]; + /** + * Optional task storage implementation. If provided, enables task-related request handlers + * and provides task storage capabilities to request handlers. + */ + taskStore?: TaskStore; + /** + * Optional task message queue implementation for managing server-initiated messages + * that will be delivered through the tasks/result response stream. + */ + taskMessageQueue?: TaskMessageQueue; + /** + * Default polling interval (in milliseconds) for task status checks when no pollInterval + * is provided by the server. Defaults to 5000ms if not specified. + */ + defaultTaskPollInterval?: number; + /** + * Maximum number of messages that can be queued per task for side-channel delivery. + * If undefined, the queue size is unbounded. + * When the limit is exceeded, the TaskMessageQueue implementation's enqueue() method + * will throw an error. It's the implementation's responsibility to handle overflow + * appropriately (e.g., by failing the task, dropping messages, etc.). + */ + maxTaskQueueSize?: number; +}; +/** + * The default request timeout, in miliseconds. + */ +export declare const DEFAULT_REQUEST_TIMEOUT_MSEC = 60000; +/** + * Options that can be given per request. + */ +export type RequestOptions = { + /** + * If set, requests progress notifications from the remote end (if supported). When progress notifications are received, this callback will be invoked. + * + * For task-augmented requests: progress notifications continue after CreateTaskResult is returned and stop automatically when the task reaches a terminal status. + */ + onprogress?: ProgressCallback; + /** + * Can be used to cancel an in-flight request. This will cause an AbortError to be raised from request(). + */ + signal?: AbortSignal; + /** + * A timeout (in milliseconds) for this request. If exceeded, an McpError with code `RequestTimeout` will be raised from request(). + * + * If not specified, `DEFAULT_REQUEST_TIMEOUT_MSEC` will be used as the timeout. + */ + timeout?: number; + /** + * If true, receiving a progress notification will reset the request timeout. + * This is useful for long-running operations that send periodic progress updates. + * Default: false + */ + resetTimeoutOnProgress?: boolean; + /** + * Maximum total time (in milliseconds) to wait for a response. + * If exceeded, an McpError with code `RequestTimeout` will be raised, regardless of progress notifications. + * If not specified, there is no maximum total timeout. + */ + maxTotalTimeout?: number; + /** + * If provided, augments the request with task creation parameters to enable call-now, fetch-later execution patterns. + */ + task?: TaskCreationParams; + /** + * If provided, associates this request with a related task. + */ + relatedTask?: RelatedTaskMetadata; +} & TransportSendOptions; +/** + * Options that can be given per notification. + */ +export type NotificationOptions = { + /** + * May be used to indicate to the transport which incoming request to associate this outgoing notification with. + */ + relatedRequestId?: RequestId; + /** + * If provided, associates this notification with a related task. + */ + relatedTask?: RelatedTaskMetadata; +}; +/** + * Options that can be given per request. + */ +export type TaskRequestOptions = Omit; +/** + * Request-scoped TaskStore interface. + */ +export interface RequestTaskStore { + /** + * Creates a new task with the given creation parameters. + * The implementation generates a unique taskId and createdAt timestamp. + * + * @param taskParams - The task creation parameters from the request + * @returns The created task object + */ + createTask(taskParams: CreateTaskOptions): Promise; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @returns The task object + * @throws If the task does not exist + */ + getTask(taskId: string): Promise; + /** + * Stores the result of a task and sets its final status. + * + * @param taskId - The task identifier + * @param status - The final status: 'completed' for success, 'failed' for errors + * @param result - The result to store + */ + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result): Promise; + /** + * Retrieves the stored result of a task. + * + * @param taskId - The task identifier + * @returns The stored result + */ + getTaskResult(taskId: string): Promise; + /** + * Updates a task's status (e.g., to 'cancelled', 'failed', 'completed'). + * + * @param taskId - The task identifier + * @param status - The new status + * @param statusMessage - Optional diagnostic message for failed tasks or other status information + */ + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string): Promise; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @param cursor - Optional cursor for pagination + * @returns An object containing the tasks array and an optional nextCursor + */ + listTasks(cursor?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; +} +/** + * Extra data given to request handlers. + */ +export type RequestHandlerExtra = { + /** + * An abort signal used to communicate if the request was cancelled from the sender's side. + */ + signal: AbortSignal; + /** + * Information about a validated access token, provided to request handlers. + */ + authInfo?: AuthInfo; + /** + * The session ID from the transport, if available. + */ + sessionId?: string; + /** + * Metadata from the original request. + */ + _meta?: RequestMeta; + /** + * The JSON-RPC ID of the request being handled. + * This can be useful for tracking or logging purposes. + */ + requestId: RequestId; + taskId?: string; + taskStore?: RequestTaskStore; + taskRequestedTtl?: number | null; + /** + * The original HTTP request. + */ + requestInfo?: RequestInfo; + /** + * Sends a notification that relates to the current request being handled. + * + * This is used by certain transports to correctly associate related messages. + */ + sendNotification: (notification: SendNotificationT) => Promise; + /** + * Sends a request that relates to the current request being handled. + * + * This is used by certain transports to correctly associate related messages. + */ + sendRequest: (request: SendRequestT, resultSchema: U, options?: TaskRequestOptions) => Promise>; +}; +/** + * Implements MCP protocol framing on top of a pluggable transport, including + * features like request/response linking, notifications, and progress. + */ +export declare abstract class Protocol { + private _options?; + private _transport?; + private _requestMessageId; + private _requestHandlers; + private _requestHandlerAbortControllers; + private _notificationHandlers; + private _responseHandlers; + private _progressHandlers; + private _timeoutInfo; + private _pendingDebouncedNotifications; + private _taskProgressTokens; + private _taskStore?; + private _taskMessageQueue?; + private _requestResolvers; + /** + * Callback for when the connection is closed for any reason. + * + * This is invoked when close() is called as well. + */ + onclose?: () => void; + /** + * Callback for when an error occurs. + * + * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band. + */ + onerror?: (error: Error) => void; + /** + * A handler to invoke for any request types that do not have their own handler installed. + */ + fallbackRequestHandler?: (request: JSONRPCRequest, extra: RequestHandlerExtra) => Promise; + /** + * A handler to invoke for any notification types that do not have their own handler installed. + */ + fallbackNotificationHandler?: (notification: Notification) => Promise; + constructor(_options?: ProtocolOptions | undefined); + private _oncancel; + private _setupTimeout; + private _resetTimeout; + private _cleanupTimeout; + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + connect(transport: Transport): Promise; + private _onclose; + private _onerror; + private _onnotification; + private _onrequest; + private _onprogress; + private _onresponse; + get transport(): Transport | undefined; + /** + * Closes the connection. + */ + close(): Promise; + /** + * A method to check if a capability is supported by the remote side, for the given method to be called. + * + * This should be implemented by subclasses. + */ + protected abstract assertCapabilityForMethod(method: SendRequestT['method']): void; + /** + * A method to check if a notification is supported by the local side, for the given method to be sent. + * + * This should be implemented by subclasses. + */ + protected abstract assertNotificationCapability(method: SendNotificationT['method']): void; + /** + * A method to check if a request handler is supported by the local side, for the given method to be handled. + * + * This should be implemented by subclasses. + */ + protected abstract assertRequestHandlerCapability(method: string): void; + /** + * A method to check if task creation is supported for the given request method. + * + * This should be implemented by subclasses. + */ + protected abstract assertTaskCapability(method: string): void; + /** + * A method to check if task handler is supported by the local side, for the given method to be handled. + * + * This should be implemented by subclasses. + */ + protected abstract assertTaskHandlerCapability(method: string): void; + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * @example + * ```typescript + * const stream = protocol.requestStream(request, resultSchema, options); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Task created:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Task status:', message.task.status); + * break; + * case 'result': + * console.log('Final result:', message.result); + * break; + * case 'error': + * console.error('Error:', message.error); + * break; + * } + * } + * ``` + * + * @experimental Use `client.experimental.tasks.requestStream()` to access this method. + */ + protected requestStream(request: SendRequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Sends a request and waits for a response. + * + * Do not use this method to emit notifications! Use notification() instead. + */ + request(request: SendRequestT, resultSchema: T, options?: RequestOptions): Promise>; + /** + * Gets the current status of a task. + * + * @experimental Use `client.experimental.tasks.getTask()` to access this method. + */ + protected getTask(params: GetTaskRequest['params'], options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @experimental Use `client.experimental.tasks.getTaskResult()` to access this method. + */ + protected getTaskResult(params: GetTaskPayloadRequest['params'], resultSchema: T, options?: RequestOptions): Promise>; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @experimental Use `client.experimental.tasks.listTasks()` to access this method. + */ + protected listTasks(params?: { + cursor?: string; + }, options?: RequestOptions): Promise>; + /** + * Cancels a specific task. + * + * @experimental Use `client.experimental.tasks.cancelTask()` to access this method. + */ + protected cancelTask(params: { + taskId: string; + }, options?: RequestOptions): Promise>; + /** + * Emits a notification, which is a one-way message that does not expect a response. + */ + notification(notification: SendNotificationT, options?: NotificationOptions): Promise; + /** + * Registers a handler to invoke when this protocol object receives a request with the given method. + * + * Note that this will replace any previous request handler for the same method. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => SendResultT | Promise): void; + /** + * Removes the request handler for the given method. + */ + removeRequestHandler(method: string): void; + /** + * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed. + */ + assertCanSetRequestHandler(method: string): void; + /** + * Registers a handler to invoke when this protocol object receives a notification with the given method. + * + * Note that this will replace any previous notification handler for the same method. + */ + setNotificationHandler(notificationSchema: T, handler: (notification: SchemaOutput) => void | Promise): void; + /** + * Removes the notification handler for the given method. + */ + removeNotificationHandler(method: string): void; + /** + * Cleans up the progress handler associated with a task. + * This should be called when a task reaches a terminal status. + */ + private _cleanupTaskProgressHandler; + /** + * Enqueues a task-related message for side-channel delivery via tasks/result. + * @param taskId The task ID to associate the message with + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow) + * + * Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle + * the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer + * simply propagates the error. + */ + private _enqueueTaskMessage; + /** + * Clears the message queue for a task and rejects any pending request resolvers. + * @param taskId The task ID whose queue should be cleared + * @param sessionId Optional session ID for binding the operation to a specific session + */ + private _clearTaskQueue; + /** + * Waits for a task update (new messages or status change) with abort signal support. + * Uses polling to check for updates at the task's configured poll interval. + * @param taskId The task ID to wait for + * @param signal Abort signal to cancel the wait + * @returns Promise that resolves when an update occurs or rejects if aborted + */ + private _waitForTaskUpdate; + private requestTaskStore; +} +export declare function mergeCapabilities(base: ServerCapabilities, additional: Partial): ServerCapabilities; +export declare function mergeCapabilities(base: ClientCapabilities, additional: Partial): ClientCapabilities; +//# sourceMappingURL=protocol.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/protocol.d.ts.map b/dist/cjs/shared/protocol.d.ts.map new file mode 100644 index 000000000..ddfe311d0 --- /dev/null +++ b/dist/cjs/shared/protocol.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/shared/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAa,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EAEH,kBAAkB,EAGlB,cAAc,EAGd,qBAAqB,EAGrB,qBAAqB,EAErB,sBAAsB,EAOtB,cAAc,EAGd,YAAY,EAEZ,QAAQ,EAIR,OAAO,EACP,SAAS,EACT,MAAM,EACN,kBAAkB,EAClB,WAAW,EAEX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EAEnB,IAAI,EAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAc,SAAS,EAAE,gBAAgB,EAAiB,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAEhI,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B;;;;;;OAMG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;OAKG;IACH,4BAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;IACxC;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,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OAAO,CAAC,2BAA2B;IAQnC;;;;;;;;;;OAUG;YACW,mBAAmB;IAUjC;;;;OAIG;YACW,eAAe;IAqB7B;;;;;;OAMG;YACW,kBAAkB;IAiChC,OAAO,CAAC,gBAAgB;CAwF3B;AAMD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACzH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/protocol.js b/dist/cjs/shared/protocol.js new file mode 100644 index 000000000..df72cfdd5 --- /dev/null +++ b/dist/cjs/shared/protocol.js @@ -0,0 +1,1101 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Protocol = exports.DEFAULT_REQUEST_TIMEOUT_MSEC = void 0; +exports.mergeCapabilities = mergeCapabilities; +const zod_compat_js_1 = require("../server/zod-compat.js"); +const types_js_1 = require("../types.js"); +const interfaces_js_1 = require("../experimental/tasks/interfaces.js"); +const zod_json_schema_compat_js_1 = require("../server/zod-json-schema-compat.js"); +/** + * The default request timeout, in miliseconds. + */ +exports.DEFAULT_REQUEST_TIMEOUT_MSEC = 60000; +/** + * Implements MCP protocol framing on top of a pluggable transport, including + * features like request/response linking, notifications, and progress. + */ +class Protocol { + constructor(_options) { + this._options = _options; + this._requestMessageId = 0; + this._requestHandlers = new Map(); + this._requestHandlerAbortControllers = new Map(); + this._notificationHandlers = new Map(); + this._responseHandlers = new Map(); + this._progressHandlers = new Map(); + this._timeoutInfo = new Map(); + this._pendingDebouncedNotifications = new Set(); + // Maps task IDs to progress tokens to keep handlers alive after CreateTaskResult + this._taskProgressTokens = new Map(); + this._requestResolvers = new Map(); + this.setNotificationHandler(types_js_1.CancelledNotificationSchema, notification => { + this._oncancel(notification); + }); + this.setNotificationHandler(types_js_1.ProgressNotificationSchema, notification => { + this._onprogress(notification); + }); + this.setRequestHandler(types_js_1.PingRequestSchema, + // Automatic pong by default. + _request => ({})); + // Install task handlers if TaskStore is provided + this._taskStore = _options === null || _options === void 0 ? void 0 : _options.taskStore; + this._taskMessageQueue = _options === null || _options === void 0 ? void 0 : _options.taskMessageQueue; + if (this._taskStore) { + this.setRequestHandler(types_js_1.GetTaskRequestSchema, async (request, extra) => { + const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!task) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found'); + } + // Per spec: tasks/get responses SHALL NOT include related-task metadata + // as the taskId parameter is the source of truth + // @ts-expect-error SendResultT cannot contain GetTaskResult, but we include it in our derived types everywhere else + return { + ...task + }; + }); + this.setRequestHandler(types_js_1.GetTaskPayloadRequestSchema, async (request, extra) => { + const handleTaskResult = async () => { + var _a; + const taskId = request.params.taskId; + // Deliver queued messages + if (this._taskMessageQueue) { + let queuedMessage; + while ((queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId))) { + // Handle response and error messages by routing them to the appropriate resolver + if (queuedMessage.type === 'response' || queuedMessage.type === 'error') { + const message = queuedMessage.message; + const requestId = message.id; + // Lookup resolver in _requestResolvers map + const resolver = this._requestResolvers.get(requestId); + if (resolver) { + // Remove resolver from map after invocation + this._requestResolvers.delete(requestId); + // Invoke resolver with response or error + if (queuedMessage.type === 'response') { + resolver(message); + } + else { + // Convert JSONRPCError to McpError + const errorMessage = message; + const error = new types_js_1.McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data); + resolver(error); + } + } + else { + // Handle missing resolver gracefully with error logging + const messageType = queuedMessage.type === 'response' ? 'Response' : 'Error'; + this._onerror(new Error(`${messageType} handler missing for request ${requestId}`)); + } + // Continue to next message + continue; + } + // Send the message on the response stream by passing the relatedRequestId + // This tells the transport to write the message to the tasks/result response stream + await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.send(queuedMessage.message, { relatedRequestId: extra.requestId })); + } + } + // Now check task status + const task = await this._taskStore.getTask(taskId, extra.sessionId); + if (!task) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Task not found: ${taskId}`); + } + // Block if task is not terminal (we've already delivered all queued messages above) + if (!(0, interfaces_js_1.isTerminal)(task.status)) { + // Wait for status change or new messages + await this._waitForTaskUpdate(taskId, extra.signal); + // After waking up, recursively call to deliver any new messages or result + return await handleTaskResult(); + } + // If task is terminal, return the result + if ((0, interfaces_js_1.isTerminal)(task.status)) { + const result = await this._taskStore.getTaskResult(taskId, extra.sessionId); + this._clearTaskQueue(taskId); + return { + ...result, + _meta: { + ...result._meta, + [types_js_1.RELATED_TASK_META_KEY]: { + taskId: taskId + } + } + }; + } + return await handleTaskResult(); + }; + return await handleTaskResult(); + }); + this.setRequestHandler(types_js_1.ListTasksRequestSchema, async (request, extra) => { + var _a; + try { + const { tasks, nextCursor } = await this._taskStore.listTasks((_a = request.params) === null || _a === void 0 ? void 0 : _a.cursor, extra.sessionId); + // @ts-expect-error SendResultT cannot contain ListTasksResult, but we include it in our derived types everywhere else + return { + tasks, + nextCursor, + _meta: {} + }; + } + catch (error) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`); + } + }); + this.setRequestHandler(types_js_1.CancelTaskRequestSchema, async (request, extra) => { + try { + // Get the current task to check if it's in a terminal state, in case the implementation is not atomic + const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!task) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`); + } + // Reject cancellation of terminal tasks + if ((0, interfaces_js_1.isTerminal)(task.status)) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`); + } + await this._taskStore.updateTaskStatus(request.params.taskId, 'cancelled', 'Client cancelled task execution.', extra.sessionId); + this._clearTaskQueue(request.params.taskId); + const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!cancelledTask) { + // Task was deleted during cancellation (e.g., cleanup happened) + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`); + } + return { + _meta: {}, + ...cancelledTask + }; + } + catch (error) { + // Re-throw McpError as-is + if (error instanceof types_js_1.McpError) { + throw error; + } + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`); + } + }); + } + } + async _oncancel(notification) { + // Handle request cancellation + const controller = this._requestHandlerAbortControllers.get(notification.params.requestId); + controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason); + } + _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) { + this._timeoutInfo.set(messageId, { + timeoutId: setTimeout(onTimeout, timeout), + startTime: Date.now(), + timeout, + maxTotalTimeout, + resetTimeoutOnProgress, + onTimeout + }); + } + _resetTimeout(messageId) { + const info = this._timeoutInfo.get(messageId); + if (!info) + return false; + const totalElapsed = Date.now() - info.startTime; + if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) { + this._timeoutInfo.delete(messageId); + throw types_js_1.McpError.fromError(types_js_1.ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', { + maxTotalTimeout: info.maxTotalTimeout, + totalElapsed + }); + } + clearTimeout(info.timeoutId); + info.timeoutId = setTimeout(info.onTimeout, info.timeout); + return true; + } + _cleanupTimeout(messageId) { + const info = this._timeoutInfo.get(messageId); + if (info) { + clearTimeout(info.timeoutId); + this._timeoutInfo.delete(messageId); + } + } + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + async connect(transport) { + var _a, _b, _c; + this._transport = transport; + const _onclose = (_a = this.transport) === null || _a === void 0 ? void 0 : _a.onclose; + this._transport.onclose = () => { + _onclose === null || _onclose === void 0 ? void 0 : _onclose(); + this._onclose(); + }; + const _onerror = (_b = this.transport) === null || _b === void 0 ? void 0 : _b.onerror; + this._transport.onerror = (error) => { + _onerror === null || _onerror === void 0 ? void 0 : _onerror(error); + this._onerror(error); + }; + const _onmessage = (_c = this._transport) === null || _c === void 0 ? void 0 : _c.onmessage; + this._transport.onmessage = (message, extra) => { + _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra); + if ((0, types_js_1.isJSONRPCResponse)(message) || (0, types_js_1.isJSONRPCError)(message)) { + this._onresponse(message); + } + else if ((0, types_js_1.isJSONRPCRequest)(message)) { + this._onrequest(message, extra); + } + else if ((0, types_js_1.isJSONRPCNotification)(message)) { + this._onnotification(message); + } + else { + this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`)); + } + }; + await this._transport.start(); + } + _onclose() { + var _a; + const responseHandlers = this._responseHandlers; + this._responseHandlers = new Map(); + this._progressHandlers.clear(); + this._taskProgressTokens.clear(); + this._pendingDebouncedNotifications.clear(); + const error = types_js_1.McpError.fromError(types_js_1.ErrorCode.ConnectionClosed, 'Connection closed'); + this._transport = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + for (const handler of responseHandlers.values()) { + handler(error); + } + } + _onerror(error) { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + } + _onnotification(notification) { + var _a; + const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler; + // Ignore notifications not being subscribed to. + if (handler === undefined) { + return; + } + // Starting with Promise.resolve() puts any synchronous errors into the monad as well. + Promise.resolve() + .then(() => handler(notification)) + .catch(error => this._onerror(new Error(`Uncaught error in notification handler: ${error}`))); + } + _onrequest(request, extra) { + var _a, _b, _c, _d, _e, _f; + const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler; + // Capture the current transport at request time to ensure responses go to the correct client + const capturedTransport = this._transport; + // Extract taskId from request metadata if present (needed early for method not found case) + const relatedTaskId = (_d = (_c = (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta) === null || _c === void 0 ? void 0 : _c[types_js_1.RELATED_TASK_META_KEY]) === null || _d === void 0 ? void 0 : _d.taskId; + if (handler === undefined) { + const errorResponse = { + jsonrpc: '2.0', + id: request.id, + error: { + code: types_js_1.ErrorCode.MethodNotFound, + message: 'Method not found' + } + }; + // Queue or send the error response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + this._enqueueTaskMessage(relatedTaskId, { + type: 'error', + message: errorResponse, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId).catch(error => this._onerror(new Error(`Failed to enqueue error response: ${error}`))); + } + else { + capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse).catch(error => this._onerror(new Error(`Failed to send an error response: ${error}`))); + } + return; + } + const abortController = new AbortController(); + this._requestHandlerAbortControllers.set(request.id, abortController); + const taskCreationParams = (_e = request.params) === null || _e === void 0 ? void 0 : _e.task; + const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId) : undefined; + const fullExtra = { + signal: abortController.signal, + sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId, + _meta: (_f = request.params) === null || _f === void 0 ? void 0 : _f._meta, + sendNotification: async (notification) => { + // Include related-task metadata if this request is part of a task + const notificationOptions = { relatedRequestId: request.id }; + if (relatedTaskId) { + notificationOptions.relatedTask = { taskId: relatedTaskId }; + } + await this.notification(notification, notificationOptions); + }, + sendRequest: async (r, resultSchema, options) => { + var _a, _b; + // Include related-task metadata if this request is part of a task + const requestOptions = { ...options, relatedRequestId: request.id }; + if (relatedTaskId && !requestOptions.relatedTask) { + requestOptions.relatedTask = { taskId: relatedTaskId }; + } + // Set task status to input_required when sending a request within a task context + // Use the taskId from options (explicit) or fall back to relatedTaskId (inherited) + const effectiveTaskId = (_b = (_a = requestOptions.relatedTask) === null || _a === void 0 ? void 0 : _a.taskId) !== null && _b !== void 0 ? _b : relatedTaskId; + if (effectiveTaskId && taskStore) { + await taskStore.updateTaskStatus(effectiveTaskId, 'input_required'); + } + return await this.request(r, resultSchema, requestOptions); + }, + authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo, + requestId: request.id, + requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo, + taskId: relatedTaskId, + taskStore: taskStore, + taskRequestedTtl: taskCreationParams === null || taskCreationParams === void 0 ? void 0 : taskCreationParams.ttl + }; + // Starting with Promise.resolve() puts any synchronous errors into the monad as well. + Promise.resolve() + .then(() => { + // If this request asked for task creation, check capability first + if (taskCreationParams) { + // Check if the request method supports task creation + this.assertTaskHandlerCapability(request.method); + } + }) + .then(() => handler(request, fullExtra)) + .then(async (result) => { + if (abortController.signal.aborted) { + // Request was cancelled + return; + } + const response = { + result, + jsonrpc: '2.0', + id: request.id + }; + // Queue or send the response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + await this._enqueueTaskMessage(relatedTaskId, { + type: 'response', + message: response, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId); + } + else { + await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(response)); + } + }, async (error) => { + var _a; + if (abortController.signal.aborted) { + // Request was cancelled + return; + } + const errorResponse = { + jsonrpc: '2.0', + id: request.id, + error: { + code: Number.isSafeInteger(error['code']) ? error['code'] : types_js_1.ErrorCode.InternalError, + message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Internal error', + ...(error['data'] !== undefined && { data: error['data'] }) + } + }; + // Queue or send the error response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + await this._enqueueTaskMessage(relatedTaskId, { + type: 'error', + message: errorResponse, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId); + } + else { + await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse)); + } + }) + .catch(error => this._onerror(new Error(`Failed to send response: ${error}`))) + .finally(() => { + this._requestHandlerAbortControllers.delete(request.id); + }); + } + _onprogress(notification) { + const { progressToken, ...params } = notification.params; + const messageId = Number(progressToken); + const handler = this._progressHandlers.get(messageId); + if (!handler) { + this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`)); + return; + } + const responseHandler = this._responseHandlers.get(messageId); + const timeoutInfo = this._timeoutInfo.get(messageId); + if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) { + try { + this._resetTimeout(messageId); + } + catch (error) { + // Clean up if maxTotalTimeout was exceeded + this._responseHandlers.delete(messageId); + this._progressHandlers.delete(messageId); + this._cleanupTimeout(messageId); + responseHandler(error); + return; + } + } + handler(params); + } + _onresponse(response) { + const messageId = Number(response.id); + // Check if this is a response to a queued request + const resolver = this._requestResolvers.get(messageId); + if (resolver) { + this._requestResolvers.delete(messageId); + if ((0, types_js_1.isJSONRPCResponse)(response)) { + resolver(response); + } + else { + const error = new types_js_1.McpError(response.error.code, response.error.message, response.error.data); + resolver(error); + } + return; + } + const handler = this._responseHandlers.get(messageId); + if (handler === undefined) { + this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`)); + return; + } + this._responseHandlers.delete(messageId); + this._cleanupTimeout(messageId); + // Keep progress handler alive for CreateTaskResult responses + let isTaskResponse = false; + if ((0, types_js_1.isJSONRPCResponse)(response) && response.result && typeof response.result === 'object') { + const result = response.result; + if (result.task && typeof result.task === 'object') { + const task = result.task; + if (typeof task.taskId === 'string') { + isTaskResponse = true; + this._taskProgressTokens.set(task.taskId, messageId); + } + } + } + if (!isTaskResponse) { + this._progressHandlers.delete(messageId); + } + if ((0, types_js_1.isJSONRPCResponse)(response)) { + handler(response); + } + else { + const error = types_js_1.McpError.fromError(response.error.code, response.error.message, response.error.data); + handler(error); + } + } + get transport() { + return this._transport; + } + /** + * Closes the connection. + */ + async close() { + var _a; + await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close()); + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * @example + * ```typescript + * const stream = protocol.requestStream(request, resultSchema, options); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Task created:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Task status:', message.task.status); + * break; + * case 'result': + * console.log('Final result:', message.result); + * break; + * case 'error': + * console.error('Error:', message.error); + * break; + * } + * } + * ``` + * + * @experimental Use `client.experimental.tasks.requestStream()` to access this method. + */ + async *requestStream(request, resultSchema, options) { + var _a, _b, _c, _d; + const { task } = options !== null && options !== void 0 ? options : {}; + // For non-task requests, just yield the result + if (!task) { + try { + const result = await this.request(request, resultSchema, options); + yield { type: 'result', result }; + } + catch (error) { + yield { + type: 'error', + error: error instanceof types_js_1.McpError ? error : new types_js_1.McpError(types_js_1.ErrorCode.InternalError, String(error)) + }; + } + return; + } + // For task-augmented requests, we need to poll for status + // First, make the request to create the task + let taskId; + try { + // Send the request and get the CreateTaskResult + const createResult = await this.request(request, types_js_1.CreateTaskResultSchema, options); + // Extract taskId from the result + if (createResult.task) { + taskId = createResult.task.taskId; + yield { type: 'taskCreated', task: createResult.task }; + } + else { + throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, 'Task creation did not return a task'); + } + // Poll for task completion + while (true) { + // Get current task status + const task = await this.getTask({ taskId }, options); + yield { type: 'taskStatus', task }; + // Check if task is terminal + if ((0, interfaces_js_1.isTerminal)(task.status)) { + if (task.status === 'completed') { + // Get the final result + const result = await this.getTaskResult({ taskId }, resultSchema, options); + yield { type: 'result', result }; + } + else if (task.status === 'failed') { + yield { + type: 'error', + error: new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Task ${taskId} failed`) + }; + } + else if (task.status === 'cancelled') { + yield { + type: 'error', + error: new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Task ${taskId} was cancelled`) + }; + } + return; + } + // When input_required, call tasks/result to deliver queued messages + // (elicitation, sampling) via SSE and block until terminal + if (task.status === 'input_required') { + const result = await this.getTaskResult({ taskId }, resultSchema, options); + yield { type: 'result', result }; + return; + } + // Wait before polling again + const pollInterval = (_c = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : (_b = this._options) === null || _b === void 0 ? void 0 : _b.defaultTaskPollInterval) !== null && _c !== void 0 ? _c : 1000; + await new Promise(resolve => setTimeout(resolve, pollInterval)); + // Check if cancelled + (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted(); + } + } + catch (error) { + yield { + type: 'error', + error: error instanceof types_js_1.McpError ? error : new types_js_1.McpError(types_js_1.ErrorCode.InternalError, String(error)) + }; + } + } + /** + * Sends a request and waits for a response. + * + * Do not use this method to emit notifications! Use notification() instead. + */ + request(request, resultSchema, options) { + const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== void 0 ? options : {}; + // Send the request + return new Promise((resolve, reject) => { + var _a, _b, _c, _d, _e, _f, _g; + const earlyReject = (error) => { + reject(error); + }; + if (!this._transport) { + earlyReject(new Error('Not connected')); + return; + } + if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) { + try { + this.assertCapabilityForMethod(request.method); + // If task creation is requested, also check task capabilities + if (task) { + this.assertTaskCapability(request.method); + } + } + catch (e) { + earlyReject(e); + return; + } + } + (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted(); + const messageId = this._requestMessageId++; + const jsonrpcRequest = { + ...request, + jsonrpc: '2.0', + id: messageId + }; + if (options === null || options === void 0 ? void 0 : options.onprogress) { + this._progressHandlers.set(messageId, options.onprogress); + jsonrpcRequest.params = { + ...request.params, + _meta: { + ...(((_c = request.params) === null || _c === void 0 ? void 0 : _c._meta) || {}), + progressToken: messageId + } + }; + } + // Augment with task creation parameters if provided + if (task) { + jsonrpcRequest.params = { + ...jsonrpcRequest.params, + task: task + }; + } + // Augment with related task metadata if relatedTask is provided + if (relatedTask) { + jsonrpcRequest.params = { + ...jsonrpcRequest.params, + _meta: { + ...(((_d = jsonrpcRequest.params) === null || _d === void 0 ? void 0 : _d._meta) || {}), + [types_js_1.RELATED_TASK_META_KEY]: relatedTask + } + }; + } + const cancel = (reason) => { + var _a; + this._responseHandlers.delete(messageId); + this._progressHandlers.delete(messageId); + this._cleanupTimeout(messageId); + (_a = this._transport) === null || _a === void 0 ? void 0 : _a.send({ + jsonrpc: '2.0', + method: 'notifications/cancelled', + params: { + requestId: messageId, + reason: String(reason) + } + }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => this._onerror(new Error(`Failed to send cancellation: ${error}`))); + // Wrap the reason in an McpError if it isn't already + const error = reason instanceof types_js_1.McpError ? reason : new types_js_1.McpError(types_js_1.ErrorCode.RequestTimeout, String(reason)); + reject(error); + }; + this._responseHandlers.set(messageId, response => { + var _a; + if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) { + return; + } + if (response instanceof Error) { + return reject(response); + } + try { + const parseResult = (0, zod_compat_js_1.safeParse)(resultSchema, response.result); + if (!parseResult.success) { + // Type guard: if success is false, error is guaranteed to exist + reject(parseResult.error); + } + else { + resolve(parseResult.data); + } + } + catch (error) { + reject(error); + } + }); + (_e = options === null || options === void 0 ? void 0 : options.signal) === null || _e === void 0 ? void 0 : _e.addEventListener('abort', () => { + var _a; + cancel((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.reason); + }); + const timeout = (_f = options === null || options === void 0 ? void 0 : options.timeout) !== null && _f !== void 0 ? _f : exports.DEFAULT_REQUEST_TIMEOUT_MSEC; + const timeoutHandler = () => cancel(types_js_1.McpError.fromError(types_js_1.ErrorCode.RequestTimeout, 'Request timed out', { timeout })); + this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_g = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _g !== void 0 ? _g : false); + // Queue request if related to a task + const relatedTaskId = relatedTask === null || relatedTask === void 0 ? void 0 : relatedTask.taskId; + if (relatedTaskId) { + // Store the response resolver for this request so responses can be routed back + const responseResolver = (response) => { + const handler = this._responseHandlers.get(messageId); + if (handler) { + handler(response); + } + else { + // Log error when resolver is missing, but don't fail + this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`)); + } + }; + this._requestResolvers.set(messageId, responseResolver); + this._enqueueTaskMessage(relatedTaskId, { + type: 'request', + message: jsonrpcRequest, + timestamp: Date.now() + }).catch(error => { + this._cleanupTimeout(messageId); + reject(error); + }); + // Don't send through transport - queued messages are delivered via tasks/result only + // This prevents duplicate delivery for bidirectional transports + } + else { + // No related task - send through transport normally + this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => { + this._cleanupTimeout(messageId); + reject(error); + }); + } + }); + } + /** + * Gets the current status of a task. + * + * @experimental Use `client.experimental.tasks.getTask()` to access this method. + */ + async getTask(params, options) { + // @ts-expect-error SendRequestT cannot directly contain GetTaskRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/get', params }, types_js_1.GetTaskResultSchema, options); + } + /** + * Retrieves the result of a completed task. + * + * @experimental Use `client.experimental.tasks.getTaskResult()` to access this method. + */ + async getTaskResult(params, resultSchema, options) { + // @ts-expect-error SendRequestT cannot directly contain GetTaskPayloadRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/result', params }, resultSchema, options); + } + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @experimental Use `client.experimental.tasks.listTasks()` to access this method. + */ + async listTasks(params, options) { + // @ts-expect-error SendRequestT cannot directly contain ListTasksRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/list', params }, types_js_1.ListTasksResultSchema, options); + } + /** + * Cancels a specific task. + * + * @experimental Use `client.experimental.tasks.cancelTask()` to access this method. + */ + async cancelTask(params, options) { + // @ts-expect-error SendRequestT cannot directly contain CancelTaskRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/cancel', params }, types_js_1.CancelTaskResultSchema, options); + } + /** + * Emits a notification, which is a one-way message that does not expect a response. + */ + async notification(notification, options) { + var _a, _b, _c, _d, _e; + if (!this._transport) { + throw new Error('Not connected'); + } + this.assertNotificationCapability(notification.method); + // Queue notification if related to a task + const relatedTaskId = (_a = options === null || options === void 0 ? void 0 : options.relatedTask) === null || _a === void 0 ? void 0 : _a.taskId; + if (relatedTaskId) { + // Build the JSONRPC notification with metadata + const jsonrpcNotification = { + ...notification, + jsonrpc: '2.0', + params: { + ...notification.params, + _meta: { + ...(((_b = notification.params) === null || _b === void 0 ? void 0 : _b._meta) || {}), + [types_js_1.RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + await this._enqueueTaskMessage(relatedTaskId, { + type: 'notification', + message: jsonrpcNotification, + timestamp: Date.now() + }); + // Don't send through transport - queued messages are delivered via tasks/result only + // This prevents duplicate delivery for bidirectional transports + return; + } + const debouncedMethods = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.debouncedNotificationMethods) !== null && _d !== void 0 ? _d : []; + // A notification can only be debounced if it's in the list AND it's "simple" + // (i.e., has no parameters and no related request ID or related task that could be lost). + const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId) && !(options === null || options === void 0 ? void 0 : options.relatedTask); + if (canDebounce) { + // If a notification of this type is already scheduled, do nothing. + if (this._pendingDebouncedNotifications.has(notification.method)) { + return; + } + // Mark this notification type as pending. + this._pendingDebouncedNotifications.add(notification.method); + // Schedule the actual send to happen in the next microtask. + // This allows all synchronous calls in the current event loop tick to be coalesced. + Promise.resolve().then(() => { + var _a, _b; + // Un-mark the notification so the next one can be scheduled. + this._pendingDebouncedNotifications.delete(notification.method); + // SAFETY CHECK: If the connection was closed while this was pending, abort. + if (!this._transport) { + return; + } + let jsonrpcNotification = { + ...notification, + jsonrpc: '2.0' + }; + // Augment with related task metadata if relatedTask is provided + if (options === null || options === void 0 ? void 0 : options.relatedTask) { + jsonrpcNotification = { + ...jsonrpcNotification, + params: { + ...jsonrpcNotification.params, + _meta: { + ...(((_a = jsonrpcNotification.params) === null || _a === void 0 ? void 0 : _a._meta) || {}), + [types_js_1.RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + } + // Send the notification, but don't await it here to avoid blocking. + // Handle potential errors with a .catch(). + (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send(jsonrpcNotification, options).catch(error => this._onerror(error)); + }); + // Return immediately. + return; + } + let jsonrpcNotification = { + ...notification, + jsonrpc: '2.0' + }; + // Augment with related task metadata if relatedTask is provided + if (options === null || options === void 0 ? void 0 : options.relatedTask) { + jsonrpcNotification = { + ...jsonrpcNotification, + params: { + ...jsonrpcNotification.params, + _meta: { + ...(((_e = jsonrpcNotification.params) === null || _e === void 0 ? void 0 : _e._meta) || {}), + [types_js_1.RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + } + await this._transport.send(jsonrpcNotification, options); + } + /** + * Registers a handler to invoke when this protocol object receives a request with the given method. + * + * Note that this will replace any previous request handler for the same method. + */ + setRequestHandler(requestSchema, handler) { + const method = (0, zod_json_schema_compat_js_1.getMethodLiteral)(requestSchema); + this.assertRequestHandlerCapability(method); + this._requestHandlers.set(method, (request, extra) => { + const parsed = (0, zod_json_schema_compat_js_1.parseWithCompat)(requestSchema, request); + return Promise.resolve(handler(parsed, extra)); + }); + } + /** + * Removes the request handler for the given method. + */ + removeRequestHandler(method) { + this._requestHandlers.delete(method); + } + /** + * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed. + */ + assertCanSetRequestHandler(method) { + if (this._requestHandlers.has(method)) { + throw new Error(`A request handler for ${method} already exists, which would be overridden`); + } + } + /** + * Registers a handler to invoke when this protocol object receives a notification with the given method. + * + * Note that this will replace any previous notification handler for the same method. + */ + setNotificationHandler(notificationSchema, handler) { + const method = (0, zod_json_schema_compat_js_1.getMethodLiteral)(notificationSchema); + this._notificationHandlers.set(method, notification => { + const parsed = (0, zod_json_schema_compat_js_1.parseWithCompat)(notificationSchema, notification); + return Promise.resolve(handler(parsed)); + }); + } + /** + * Removes the notification handler for the given method. + */ + removeNotificationHandler(method) { + this._notificationHandlers.delete(method); + } + /** + * Cleans up the progress handler associated with a task. + * This should be called when a task reaches a terminal status. + */ + _cleanupTaskProgressHandler(taskId) { + const progressToken = this._taskProgressTokens.get(taskId); + if (progressToken !== undefined) { + this._progressHandlers.delete(progressToken); + this._taskProgressTokens.delete(taskId); + } + } + /** + * Enqueues a task-related message for side-channel delivery via tasks/result. + * @param taskId The task ID to associate the message with + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow) + * + * Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle + * the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer + * simply propagates the error. + */ + async _enqueueTaskMessage(taskId, message, sessionId) { + var _a; + // Task message queues are only used when taskStore is configured + if (!this._taskStore || !this._taskMessageQueue) { + throw new Error('Cannot enqueue task message: taskStore and taskMessageQueue are not configured'); + } + const maxQueueSize = (_a = this._options) === null || _a === void 0 ? void 0 : _a.maxTaskQueueSize; + await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize); + } + /** + * Clears the message queue for a task and rejects any pending request resolvers. + * @param taskId The task ID whose queue should be cleared + * @param sessionId Optional session ID for binding the operation to a specific session + */ + async _clearTaskQueue(taskId, sessionId) { + if (this._taskMessageQueue) { + // Reject any pending request resolvers + const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId); + for (const message of messages) { + if (message.type === 'request' && (0, types_js_1.isJSONRPCRequest)(message.message)) { + // Extract request ID from the message + const requestId = message.message.id; + const resolver = this._requestResolvers.get(requestId); + if (resolver) { + resolver(new types_js_1.McpError(types_js_1.ErrorCode.InternalError, 'Task cancelled or completed')); + this._requestResolvers.delete(requestId); + } + else { + // Log error when resolver is missing during cleanup for better observability + this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`)); + } + } + } + } + } + /** + * Waits for a task update (new messages or status change) with abort signal support. + * Uses polling to check for updates at the task's configured poll interval. + * @param taskId The task ID to wait for + * @param signal Abort signal to cancel the wait + * @returns Promise that resolves when an update occurs or rejects if aborted + */ + async _waitForTaskUpdate(taskId, signal) { + var _a, _b, _c; + // Get the task's poll interval, falling back to default + let interval = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.defaultTaskPollInterval) !== null && _b !== void 0 ? _b : 1000; + try { + const task = await ((_c = this._taskStore) === null || _c === void 0 ? void 0 : _c.getTask(taskId)); + if (task === null || task === void 0 ? void 0 : task.pollInterval) { + interval = task.pollInterval; + } + } + catch (_d) { + // Use default interval if task lookup fails + } + return new Promise((resolve, reject) => { + if (signal.aborted) { + reject(new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, 'Request cancelled')); + return; + } + // Wait for the poll interval, then resolve so caller can check for updates + const timeoutId = setTimeout(resolve, interval); + // Clean up timeout and reject if aborted + signal.addEventListener('abort', () => { + clearTimeout(timeoutId); + reject(new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, 'Request cancelled')); + }, { once: true }); + }); + } + requestTaskStore(request, sessionId) { + const taskStore = this._taskStore; + if (!taskStore) { + throw new Error('No task store configured'); + } + return { + createTask: async (taskParams) => { + if (!request) { + throw new Error('No request provided'); + } + return await taskStore.createTask(taskParams, request.id, { + method: request.method, + params: request.params + }, sessionId); + }, + getTask: async (taskId) => { + const task = await taskStore.getTask(taskId, sessionId); + if (!task) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found'); + } + return task; + }, + storeTaskResult: async (taskId, status, result) => { + await taskStore.storeTaskResult(taskId, status, result, sessionId); + // Get updated task state and send notification + const task = await taskStore.getTask(taskId, sessionId); + if (task) { + const notification = types_js_1.TaskStatusNotificationSchema.parse({ + method: 'notifications/tasks/status', + params: task + }); + await this.notification(notification); + if ((0, interfaces_js_1.isTerminal)(task.status)) { + this._cleanupTaskProgressHandler(taskId); + // Don't clear queue here - it will be cleared after delivery via tasks/result + } + } + }, + getTaskResult: taskId => { + return taskStore.getTaskResult(taskId, sessionId); + }, + updateTaskStatus: async (taskId, status, statusMessage) => { + // Check if task exists + const task = await taskStore.getTask(taskId, sessionId); + if (!task) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`); + } + // Don't allow transitions from terminal states + if ((0, interfaces_js_1.isTerminal)(task.status)) { + throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`); + } + await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId); + // Get updated task state and send notification + const updatedTask = await taskStore.getTask(taskId, sessionId); + if (updatedTask) { + const notification = types_js_1.TaskStatusNotificationSchema.parse({ + method: 'notifications/tasks/status', + params: updatedTask + }); + await this.notification(notification); + if ((0, interfaces_js_1.isTerminal)(updatedTask.status)) { + this._cleanupTaskProgressHandler(taskId); + // Don't clear queue here - it will be cleared after delivery via tasks/result + } + } + }, + listTasks: cursor => { + return taskStore.listTasks(cursor, sessionId); + } + }; + } +} +exports.Protocol = Protocol; +function isPlainObject(value) { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} +function mergeCapabilities(base, additional) { + const result = { ...base }; + for (const key in additional) { + const k = key; + const addValue = additional[k]; + if (addValue === undefined) + continue; + const baseValue = result[k]; + if (isPlainObject(baseValue) && isPlainObject(addValue)) { + result[k] = { ...baseValue, ...addValue }; + } + else { + result[k] = addValue; + } + } + return result; +} +//# sourceMappingURL=protocol.js.map \ No newline at end of file diff --git a/dist/cjs/shared/protocol.js.map b/dist/cjs/shared/protocol.js.map new file mode 100644 index 000000000..23dade3bb --- /dev/null +++ b/dist/cjs/shared/protocol.js.map @@ -0,0 +1 @@ +{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/shared/protocol.ts"],"names":[],"mappings":";;;AAqlDA,8CAcC;AAnmDD,2DAA8F;AAC9F,0CA2CqB;AAGrB,uEAAgI;AAChI,mFAAwF;AAoDxF;;GAEG;AACU,QAAA,4BAA4B,GAAG,KAAK,CAAC;AAoMlD;;;GAGG;AACH,MAAsB,QAAQ;IA8C1B,YAAoB,QAA0B;QAA1B,aAAQ,GAAR,QAAQ,CAAkB;QA5CtC,sBAAiB,GAAG,CAAC,CAAC;QACtB,qBAAgB,GAGpB,IAAI,GAAG,EAAE,CAAC;QACN,oCAA+B,GAAoC,IAAI,GAAG,EAAE,CAAC;QAC7E,0BAAqB,GAAsE,IAAI,GAAG,EAAE,CAAC;QACrG,sBAAiB,GAA6D,IAAI,GAAG,EAAE,CAAC;QACxF,sBAAiB,GAAkC,IAAI,GAAG,EAAE,CAAC;QAC7D,iBAAY,GAA6B,IAAI,GAAG,EAAE,CAAC;QACnD,mCAA8B,GAAG,IAAI,GAAG,EAAU,CAAC;QAE3D,iFAAiF;QACzE,wBAAmB,GAAwB,IAAI,GAAG,EAAE,CAAC;QAKrD,sBAAiB,GAAgE,IAAI,GAAG,EAAE,CAAC;QA2B/F,IAAI,CAAC,sBAAsB,CAAC,sCAA2B,EAAE,YAAY,CAAC,EAAE;YACpE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,sBAAsB,CAAC,qCAA0B,EAAE,YAAY,CAAC,EAAE;YACnE,IAAI,CAAC,WAAW,CAAC,YAA+C,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,iBAAiB,CAClB,4BAAiB;QACjB,6BAA6B;QAC7B,QAAQ,CAAC,EAAE,CAAC,CAAC,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AI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAID,SAAgB,iBAAiB,CAAoD,IAAO,EAAE,UAAsB;IAChH,MAAM,MAAM,GAAM,EAAE,GAAG,IAAI,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,GAAc,CAAC;QACzB,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAS;QACrC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,GAAI,SAAqC,EAAE,GAAI,QAAoC,EAAiB,CAAC;QACvH,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,CAAC,CAAC,GAAG,QAAuB,CAAC;QACxC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/responseMessage.d.ts b/dist/cjs/shared/responseMessage.d.ts new file mode 100644 index 000000000..84354bdb7 --- /dev/null +++ b/dist/cjs/shared/responseMessage.d.ts @@ -0,0 +1,45 @@ +import { Result, Task, McpError } from '../types.js'; +/** + * Base message type + */ +export interface BaseResponseMessage { + type: string; +} +/** + * Task status update message + */ +export interface TaskStatusMessage extends BaseResponseMessage { + type: 'taskStatus'; + task: Task; +} +/** + * Task created message (first message for task-augmented requests) + */ +export interface TaskCreatedMessage extends BaseResponseMessage { + type: 'taskCreated'; + task: Task; +} +/** + * Final result message (terminal) + */ +export interface ResultMessage extends BaseResponseMessage { + type: 'result'; + result: T; +} +/** + * Error message (terminal) + */ +export interface ErrorMessage extends BaseResponseMessage { + type: 'error'; + error: McpError; +} +/** + * Union type representing all possible messages that can be yielded during request processing. + * Note: Progress notifications are handled through the existing onprogress callback mechanism. + * Side-channeled messages (server requests/notifications) are handled through registered handlers. + */ +export type ResponseMessage = TaskStatusMessage | TaskCreatedMessage | ResultMessage | ErrorMessage; +export type AsyncGeneratorValue = T extends AsyncGenerator ? U : never; +export declare function toArrayAsync>(it: T): Promise[]>; +export declare function takeResult>>(it: U): Promise; +//# sourceMappingURL=responseMessage.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/responseMessage.d.ts.map b/dist/cjs/shared/responseMessage.d.ts.map new file mode 100644 index 000000000..65d93bb50 --- /dev/null +++ b/dist/cjs/shared/responseMessage.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"responseMessage.d.ts","sourceRoot":"","sources":["../../../src/shared/responseMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC1D,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC3D,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,mBAAmB;IACxE,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACrD,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG,kBAAkB,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;AAEzH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF,wBAAsB,YAAY,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAO9G;AAED,wBAAsB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAUlH"} \ No newline at end of file diff --git a/dist/cjs/shared/responseMessage.js b/dist/cjs/shared/responseMessage.js new file mode 100644 index 000000000..6c223fcbc --- /dev/null +++ b/dist/cjs/shared/responseMessage.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toArrayAsync = toArrayAsync; +exports.takeResult = takeResult; +async function toArrayAsync(it) { + const arr = []; + for await (const o of it) { + arr.push(o); + } + return arr; +} +async function takeResult(it) { + for await (const o of it) { + if (o.type === 'result') { + return o.result; + } + else if (o.type === 'error') { + throw o.error; + } + } + throw new Error('No result in stream.'); +} +//# sourceMappingURL=responseMessage.js.map \ No newline at end of file diff --git a/dist/cjs/shared/responseMessage.js.map b/dist/cjs/shared/responseMessage.js.map new file mode 100644 index 000000000..18bd904ed --- /dev/null +++ b/dist/cjs/shared/responseMessage.js.map @@ -0,0 +1 @@ +{"version":3,"file":"responseMessage.js","sourceRoot":"","sources":["../../../src/shared/responseMessage.ts"],"names":[],"mappings":";;AAkDA,oCAOC;AAED,gCAUC;AAnBM,KAAK,UAAU,YAAY,CAAoC,EAAK;IACvE,MAAM,GAAG,GAA6B,EAAE,CAAC;IACzC,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,GAAG,CAAC,IAAI,CAAC,CAA2B,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAEM,KAAK,UAAU,UAAU,CAAiE,EAAK;IAClG,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC,MAAM,CAAC;QACpB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,CAAC,KAAK,CAAC;QAClB,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC5C,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/stdio.d.ts b/dist/cjs/shared/stdio.d.ts new file mode 100644 index 000000000..0830a48bc --- /dev/null +++ b/dist/cjs/shared/stdio.d.ts @@ -0,0 +1,13 @@ +import { JSONRPCMessage } from '../types.js'; +/** + * Buffers a continuous stdio stream into discrete JSON-RPC messages. + */ +export declare class ReadBuffer { + private _buffer?; + append(chunk: Buffer): void; + readMessage(): JSONRPCMessage | null; + clear(): void; +} +export declare function deserializeMessage(line: string): JSONRPCMessage; +export declare function serializeMessage(message: JSONRPCMessage): string; +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/stdio.d.ts.map b/dist/cjs/shared/stdio.d.ts.map new file mode 100644 index 000000000..8f97f2ab1 --- /dev/null +++ b/dist/cjs/shared/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/shared/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,WAAW,IAAI,cAAc,GAAG,IAAI;IAepC,KAAK,IAAI,IAAI;CAGhB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAE/D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAEhE"} \ No newline at end of file diff --git a/dist/cjs/shared/stdio.js b/dist/cjs/shared/stdio.js new file mode 100644 index 000000000..540ee5682 --- /dev/null +++ b/dist/cjs/shared/stdio.js @@ -0,0 +1,37 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ReadBuffer = void 0; +exports.deserializeMessage = deserializeMessage; +exports.serializeMessage = serializeMessage; +const types_js_1 = require("../types.js"); +/** + * Buffers a continuous stdio stream into discrete JSON-RPC messages. + */ +class ReadBuffer { + append(chunk) { + this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk; + } + readMessage() { + if (!this._buffer) { + return null; + } + const index = this._buffer.indexOf('\n'); + if (index === -1) { + return null; + } + const line = this._buffer.toString('utf8', 0, index).replace(/\r$/, ''); + this._buffer = this._buffer.subarray(index + 1); + return deserializeMessage(line); + } + clear() { + this._buffer = undefined; + } +} +exports.ReadBuffer = ReadBuffer; +function deserializeMessage(line) { + return types_js_1.JSONRPCMessageSchema.parse(JSON.parse(line)); +} +function serializeMessage(message) { + return JSON.stringify(message) + '\n'; +} +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/cjs/shared/stdio.js.map b/dist/cjs/shared/stdio.js.map new file mode 100644 index 000000000..89fbc1a66 --- /dev/null +++ b/dist/cjs/shared/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/shared/stdio.ts"],"names":[],"mappings":";;;AAgCA,gDAEC;AAED,4CAEC;AAtCD,0CAAmE;AAEnE;;GAEG;AACH,MAAa,UAAU;IAGnB,MAAM,CAAC,KAAa;QAChB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/E,CAAC;IAED,WAAW;QACP,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAChD,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC7B,CAAC;CACJ;AAzBD,gCAyBC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC3C,OAAO,+BAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAAuB;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAC1C,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/toolNameValidation.d.ts b/dist/cjs/shared/toolNameValidation.d.ts new file mode 100644 index 000000000..3cf94bf78 --- /dev/null +++ b/dist/cjs/shared/toolNameValidation.d.ts @@ -0,0 +1,31 @@ +/** + * Tool name validation utilities according to SEP: Specify Format for Tool Names + * + * Tool names SHOULD be between 1 and 128 characters in length (inclusive). + * Tool names are case-sensitive. + * Allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits + * (0-9), underscore (_), dash (-), and dot (.). + * Tool names SHOULD NOT contain spaces, commas, or other special characters. + */ +/** + * Validates a tool name according to the SEP specification + * @param name - The tool name to validate + * @returns An object containing validation result and any warnings + */ +export declare function validateToolName(name: string): { + isValid: boolean; + warnings: string[]; +}; +/** + * Issues warnings for non-conforming tool names + * @param name - The tool name that triggered the warnings + * @param warnings - Array of warning messages + */ +export declare function issueToolNameWarning(name: string, warnings: string[]): void; +/** + * Validates a tool name and issues warnings for non-conforming names + * @param name - The tool name to validate + * @returns true if the name is valid, false otherwise + */ +export declare function validateAndWarnToolName(name: string): boolean; +//# sourceMappingURL=toolNameValidation.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/toolNameValidation.d.ts.map b/dist/cjs/shared/toolNameValidation.d.ts.map new file mode 100644 index 000000000..d81f0156e --- /dev/null +++ b/dist/cjs/shared/toolNameValidation.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"toolNameValidation.d.ts","sourceRoot":"","sources":["../../../src/shared/toolNameValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB,CA0DA;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAY3E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO7D"} \ No newline at end of file diff --git a/dist/cjs/shared/toolNameValidation.js b/dist/cjs/shared/toolNameValidation.js new file mode 100644 index 000000000..cd9d93078 --- /dev/null +++ b/dist/cjs/shared/toolNameValidation.js @@ -0,0 +1,97 @@ +"use strict"; +/** + * Tool name validation utilities according to SEP: Specify Format for Tool Names + * + * Tool names SHOULD be between 1 and 128 characters in length (inclusive). + * Tool names are case-sensitive. + * Allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits + * (0-9), underscore (_), dash (-), and dot (.). + * Tool names SHOULD NOT contain spaces, commas, or other special characters. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.validateToolName = validateToolName; +exports.issueToolNameWarning = issueToolNameWarning; +exports.validateAndWarnToolName = validateAndWarnToolName; +/** + * Regular expression for valid tool names according to SEP-986 specification + */ +const TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/; +/** + * Validates a tool name according to the SEP specification + * @param name - The tool name to validate + * @returns An object containing validation result and any warnings + */ +function validateToolName(name) { + const warnings = []; + // Check length + if (name.length === 0) { + return { + isValid: false, + warnings: ['Tool name cannot be empty'] + }; + } + if (name.length > 128) { + return { + isValid: false, + warnings: [`Tool name exceeds maximum length of 128 characters (current: ${name.length})`] + }; + } + // Check for specific problematic patterns (these are warnings, not validation failures) + if (name.includes(' ')) { + warnings.push('Tool name contains spaces, which may cause parsing issues'); + } + if (name.includes(',')) { + warnings.push('Tool name contains commas, which may cause parsing issues'); + } + // Check for potentially confusing patterns (leading/trailing dashes, dots, slashes) + if (name.startsWith('-') || name.endsWith('-')) { + warnings.push('Tool name starts or ends with a dash, which may cause parsing issues in some contexts'); + } + if (name.startsWith('.') || name.endsWith('.')) { + warnings.push('Tool name starts or ends with a dot, which may cause parsing issues in some contexts'); + } + // Check for invalid characters + if (!TOOL_NAME_REGEX.test(name)) { + const invalidChars = name + .split('') + .filter(char => !/[A-Za-z0-9._-]/.test(char)) + .filter((char, index, arr) => arr.indexOf(char) === index); // Remove duplicates + warnings.push(`Tool name contains invalid characters: ${invalidChars.map(c => `"${c}"`).join(', ')}`, 'Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)'); + return { + isValid: false, + warnings + }; + } + return { + isValid: true, + warnings + }; +} +/** + * Issues warnings for non-conforming tool names + * @param name - The tool name that triggered the warnings + * @param warnings - Array of warning messages + */ +function issueToolNameWarning(name, warnings) { + if (warnings.length > 0) { + console.warn(`Tool name validation warning for "${name}":`); + for (const warning of warnings) { + console.warn(` - ${warning}`); + } + console.warn('Tool registration will proceed, but this may cause compatibility issues.'); + console.warn('Consider updating the tool name to conform to the MCP tool naming standard.'); + console.warn('See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.'); + } +} +/** + * Validates a tool name and issues warnings for non-conforming names + * @param name - The tool name to validate + * @returns true if the name is valid, false otherwise + */ +function validateAndWarnToolName(name) { + const result = validateToolName(name); + // Always issue warnings for any validation issues (both invalid names and warnings) + issueToolNameWarning(name, result.warnings); + return result.isValid; +} +//# sourceMappingURL=toolNameValidation.js.map \ No newline at end of file diff --git a/dist/cjs/shared/toolNameValidation.js.map b/dist/cjs/shared/toolNameValidation.js.map new file mode 100644 index 000000000..ad136cc30 --- /dev/null +++ b/dist/cjs/shared/toolNameValidation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"toolNameValidation.js","sourceRoot":"","sources":["../../../src/shared/toolNameValidation.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAYH,4CA6DC;AAOD,oDAYC;AAOD,0DAOC;AAxGD;;GAEG;AACH,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAElD;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAIzC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,eAAe;IACf,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO;YACH,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,CAAC,2BAA2B,CAAC;SAC1C,CAAC;IACN,CAAC;IAED,IAA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,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EACtF,8EAA8E,CACjF,CAAC;QAEF,OAAO;YACH,OAAO,EAAE,KAAK;YACd,QAAQ;SACX,CAAC;IACN,CAAC;IAED,OAAO;QACH,OAAO,EAAE,IAAI;QACb,QAAQ;KACX,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAAY,EAAE,QAAkB;IACjE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,IAAI,CAAC,CAAC;QAC5D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;QACzF,OAAO,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAC;QAC5F,OAAO,CAAC,IAAI,CACR,oIAAoI,CACvI,CAAC;IACN,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAEtC,oFAAoF;IACpF,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC,OAAO,CAAC;AAC1B,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/transport.d.ts b/dist/cjs/shared/transport.d.ts new file mode 100644 index 000000000..7fb5efab7 --- /dev/null +++ b/dist/cjs/shared/transport.d.ts @@ -0,0 +1,89 @@ +import { JSONRPCMessage, MessageExtraInfo, RequestId } from '../types.js'; +export type FetchLike = (url: string | URL, init?: RequestInit) => Promise; +/** + * Normalizes HeadersInit to a plain Record for manipulation. + * Handles Headers objects, arrays of tuples, and plain objects. + */ +export declare function normalizeHeaders(headers: HeadersInit | undefined): Record; +/** + * Creates a fetch function that includes base RequestInit options. + * This ensures requests inherit settings like credentials, mode, headers, etc. from the base init. + * + * @param baseFetch - The base fetch function to wrap (defaults to global fetch) + * @param baseInit - The base RequestInit to merge with each request + * @returns A wrapped fetch function that merges base options with call-specific options + */ +export declare function createFetchWithInit(baseFetch?: FetchLike, baseInit?: RequestInit): FetchLike; +/** + * Options for sending a JSON-RPC message. + */ +export type TransportSendOptions = { + /** + * If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with. + */ + relatedRequestId?: RequestId; + /** + * The resumption token used to continue long-running requests that were interrupted. + * + * This allows clients to reconnect and continue from where they left off, if supported by the transport. + */ + resumptionToken?: string; + /** + * A callback that is invoked when the resumption token changes, if supported by the transport. + * + * This allows clients to persist the latest token for potential reconnection. + */ + onresumptiontoken?: (token: string) => void; +}; +/** + * Describes the minimal contract for a MCP transport that a client or server can communicate over. + */ +export interface Transport { + /** + * Starts processing messages on the transport, including any connection steps that might need to be taken. + * + * This method should only be called after callbacks are installed, or else messages may be lost. + * + * NOTE: This method should not be called explicitly when using Client, Server, or Protocol classes, as they will implicitly call start(). + */ + start(): Promise; + /** + * Sends a JSON-RPC message (request or response). + * + * If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with. + */ + send(message: JSONRPCMessage, options?: TransportSendOptions): Promise; + /** + * Closes the connection. + */ + close(): Promise; + /** + * Callback for when the connection is closed for any reason. + * + * This should be invoked when close() is called as well. + */ + onclose?: () => void; + /** + * Callback for when an error occurs. + * + * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band. + */ + onerror?: (error: Error) => void; + /** + * Callback for when a message (request or response) is received over the connection. + * + * Includes the requestInfo and authInfo if the transport is authenticated. + * + * The requestInfo can be used to get the original request information (headers, etc.) + */ + onmessage?: (message: T, extra?: MessageExtraInfo) => void; + /** + * The session ID generated for this connection. + */ + sessionId?: string; + /** + * Sets the protocol version used for the connection (called when the initialize response is received). + */ + setProtocolVersion?: (version: string) => void; +} +//# sourceMappingURL=transport.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/transport.d.ts.map b/dist/cjs/shared/transport.d.ts.map new file mode 100644 index 000000000..7a3d837df --- /dev/null +++ b/dist/cjs/shared/transport.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/shared/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE1E,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAErF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYzF;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,SAAiB,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,SAAS,CAenG;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B;;OAEG;IACH,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAE7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AACF;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB;;;;;;OAMG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7E;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAErF;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD"} \ No newline at end of file diff --git a/dist/cjs/shared/transport.js b/dist/cjs/shared/transport.js new file mode 100644 index 000000000..9618d067c --- /dev/null +++ b/dist/cjs/shared/transport.js @@ -0,0 +1,43 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.normalizeHeaders = normalizeHeaders; +exports.createFetchWithInit = createFetchWithInit; +/** + * Normalizes HeadersInit to a plain Record for manipulation. + * Handles Headers objects, arrays of tuples, and plain objects. + */ +function normalizeHeaders(headers) { + if (!headers) + return {}; + if (headers instanceof Headers) { + return Object.fromEntries(headers.entries()); + } + if (Array.isArray(headers)) { + return Object.fromEntries(headers); + } + return { ...headers }; +} +/** + * Creates a fetch function that includes base RequestInit options. + * This ensures requests inherit settings like credentials, mode, headers, etc. from the base init. + * + * @param baseFetch - The base fetch function to wrap (defaults to global fetch) + * @param baseInit - The base RequestInit to merge with each request + * @returns A wrapped fetch function that merges base options with call-specific options + */ +function createFetchWithInit(baseFetch = fetch, baseInit) { + if (!baseInit) { + return baseFetch; + } + // Return a wrapped fetch that merges base RequestInit with call-specific init + return async (url, init) => { + const mergedInit = { + ...baseInit, + ...init, + // Headers need special handling - merge instead of replace + headers: (init === null || init === void 0 ? void 0 : init.headers) ? { ...normalizeHeaders(baseInit.headers), ...normalizeHeaders(init.headers) } : baseInit.headers + }; + return baseFetch(url, mergedInit); + }; +} +//# sourceMappingURL=transport.js.map \ No newline at end of file diff --git a/dist/cjs/shared/transport.js.map b/dist/cjs/shared/transport.js.map new file mode 100644 index 000000000..3c8cb5f83 --- /dev/null +++ b/dist/cjs/shared/transport.js.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/shared/transport.ts"],"names":[],"mappings":";;AAQA,4CAYC;AAUD,kDAeC;AAzCD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,OAAgC;IAC7D,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,GAAI,OAAkC,EAAE,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,YAAuB,KAAK,EAAE,QAAsB;IACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,8EAA8E;IAC9E,OAAO,KAAK,EAAE,GAAiB,EAAE,IAAkB,EAAqB,EAAE;QACtE,MAAM,UAAU,GAAgB;YAC5B,GAAG,QAAQ;YACX,GAAG,IAAI;YACP,2DAA2D;YAC3D,OAAO,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO;SAC3H,CAAC;QACF,OAAO,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/uriTemplate.d.ts b/dist/cjs/shared/uriTemplate.d.ts new file mode 100644 index 000000000..175e329b6 --- /dev/null +++ b/dist/cjs/shared/uriTemplate.d.ts @@ -0,0 +1,25 @@ +export type Variables = Record; +export declare class UriTemplate { + /** + * Returns true if the given string contains any URI template expressions. + * A template expression is a sequence of characters enclosed in curly braces, + * like {foo} or {?bar}. + */ + static isTemplate(str: string): boolean; + private static validateLength; + private readonly template; + private readonly parts; + get variableNames(): string[]; + constructor(template: string); + toString(): string; + private parse; + private getOperator; + private getNames; + private encodeValue; + private expandPart; + expand(variables: Variables): string; + private escapeRegExp; + private partToRegExp; + match(uri: string): Variables | null; +} +//# sourceMappingURL=uriTemplate.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/uriTemplate.d.ts.map b/dist/cjs/shared/uriTemplate.d.ts.map new file mode 100644 index 000000000..052e91851 --- /dev/null +++ b/dist/cjs/shared/uriTemplate.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"uriTemplate.d.ts","sourceRoot":"","sources":["../../../src/shared/uriTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAO1D,qBAAa,WAAW;IACpB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAMvC,OAAO,CAAC,MAAM,CAAC,cAAc;IAK7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyF;IAE/G,IAAI,aAAa,IAAI,MAAM,EAAE,CAE5B;gBAEW,QAAQ,EAAE,MAAM;IAM5B,QAAQ,IAAI,MAAM;IAIlB,OAAO,CAAC,KAAK;IA8Cb,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,UAAU;IAsDlB,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM;IA4BpC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;IAkDpB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAuCvC"} \ No newline at end of file diff --git a/dist/cjs/shared/uriTemplate.js b/dist/cjs/shared/uriTemplate.js new file mode 100644 index 000000000..baad5d974 --- /dev/null +++ b/dist/cjs/shared/uriTemplate.js @@ -0,0 +1,243 @@ +"use strict"; +// Claude-authored implementation of RFC 6570 URI Templates +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UriTemplate = void 0; +const MAX_TEMPLATE_LENGTH = 1000000; // 1MB +const MAX_VARIABLE_LENGTH = 1000000; // 1MB +const MAX_TEMPLATE_EXPRESSIONS = 10000; +const MAX_REGEX_LENGTH = 1000000; // 1MB +class UriTemplate { + /** + * Returns true if the given string contains any URI template expressions. + * A template expression is a sequence of characters enclosed in curly braces, + * like {foo} or {?bar}. + */ + static isTemplate(str) { + // Look for any sequence of characters between curly braces + // that isn't just whitespace + return /\{[^}\s]+\}/.test(str); + } + static validateLength(str, max, context) { + if (str.length > max) { + throw new Error(`${context} exceeds maximum length of ${max} characters (got ${str.length})`); + } + } + get variableNames() { + return this.parts.flatMap(part => (typeof part === 'string' ? [] : part.names)); + } + constructor(template) { + UriTemplate.validateLength(template, MAX_TEMPLATE_LENGTH, 'Template'); + this.template = template; + this.parts = this.parse(template); + } + toString() { + return this.template; + } + parse(template) { + const parts = []; + let currentText = ''; + let i = 0; + let expressionCount = 0; + while (i < template.length) { + if (template[i] === '{') { + if (currentText) { + parts.push(currentText); + currentText = ''; + } + const end = template.indexOf('}', i); + if (end === -1) + throw new Error('Unclosed template expression'); + expressionCount++; + if (expressionCount > MAX_TEMPLATE_EXPRESSIONS) { + throw new Error(`Template contains too many expressions (max ${MAX_TEMPLATE_EXPRESSIONS})`); + } + const expr = template.slice(i + 1, end); + const operator = this.getOperator(expr); + const exploded = expr.includes('*'); + const names = this.getNames(expr); + const name = names[0]; + // Validate variable name length + for (const name of names) { + UriTemplate.validateLength(name, MAX_VARIABLE_LENGTH, 'Variable name'); + } + parts.push({ name, operator, names, exploded }); + i = end + 1; + } + else { + currentText += template[i]; + i++; + } + } + if (currentText) { + parts.push(currentText); + } + return parts; + } + getOperator(expr) { + const operators = ['+', '#', '.', '/', '?', '&']; + return operators.find(op => expr.startsWith(op)) || ''; + } + getNames(expr) { + const operator = this.getOperator(expr); + return expr + .slice(operator.length) + .split(',') + .map(name => name.replace('*', '').trim()) + .filter(name => name.length > 0); + } + encodeValue(value, operator) { + UriTemplate.validateLength(value, MAX_VARIABLE_LENGTH, 'Variable value'); + if (operator === '+' || operator === '#') { + return encodeURI(value); + } + return encodeURIComponent(value); + } + expandPart(part, variables) { + if (part.operator === '?' || part.operator === '&') { + const pairs = part.names + .map(name => { + const value = variables[name]; + if (value === undefined) + return ''; + const encoded = Array.isArray(value) + ? value.map(v => this.encodeValue(v, part.operator)).join(',') + : this.encodeValue(value.toString(), part.operator); + return `${name}=${encoded}`; + }) + .filter(pair => pair.length > 0); + if (pairs.length === 0) + return ''; + const separator = part.operator === '?' ? '?' : '&'; + return separator + pairs.join('&'); + } + if (part.names.length > 1) { + const values = part.names.map(name => variables[name]).filter(v => v !== undefined); + if (values.length === 0) + return ''; + return values.map(v => (Array.isArray(v) ? v[0] : v)).join(','); + } + const value = variables[part.name]; + if (value === undefined) + return ''; + const values = Array.isArray(value) ? value : [value]; + const encoded = values.map(v => this.encodeValue(v, part.operator)); + switch (part.operator) { + case '': + return encoded.join(','); + case '+': + return encoded.join(','); + case '#': + return '#' + encoded.join(','); + case '.': + return '.' + encoded.join('.'); + case '/': + return '/' + encoded.join('/'); + default: + return encoded.join(','); + } + } + expand(variables) { + let result = ''; + let hasQueryParam = false; + for (const part of this.parts) { + if (typeof part === 'string') { + result += part; + continue; + } + const expanded = this.expandPart(part, variables); + if (!expanded) + continue; + // Convert ? to & if we already have a query parameter + if ((part.operator === '?' || part.operator === '&') && hasQueryParam) { + result += expanded.replace('?', '&'); + } + else { + result += expanded; + } + if (part.operator === '?' || part.operator === '&') { + hasQueryParam = true; + } + } + return result; + } + escapeRegExp(str) { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + partToRegExp(part) { + const patterns = []; + // Validate variable name length for matching + for (const name of part.names) { + UriTemplate.validateLength(name, MAX_VARIABLE_LENGTH, 'Variable name'); + } + if (part.operator === '?' || part.operator === '&') { + for (let i = 0; i < part.names.length; i++) { + const name = part.names[i]; + const prefix = i === 0 ? '\\' + part.operator : '&'; + patterns.push({ + pattern: prefix + this.escapeRegExp(name) + '=([^&]+)', + name + }); + } + return patterns; + } + let pattern; + const name = part.name; + switch (part.operator) { + case '': + pattern = part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)'; + break; + case '+': + case '#': + pattern = '(.+)'; + break; + case '.': + pattern = '\\.([^/,]+)'; + break; + case '/': + pattern = '/' + (part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)'); + break; + default: + pattern = '([^/]+)'; + } + patterns.push({ pattern, name }); + return patterns; + } + match(uri) { + UriTemplate.validateLength(uri, MAX_TEMPLATE_LENGTH, 'URI'); + let pattern = '^'; + const names = []; + for (const part of this.parts) { + if (typeof part === 'string') { + pattern += this.escapeRegExp(part); + } + else { + const patterns = this.partToRegExp(part); + for (const { pattern: partPattern, name } of patterns) { + pattern += partPattern; + names.push({ name, exploded: part.exploded }); + } + } + } + pattern += '$'; + UriTemplate.validateLength(pattern, MAX_REGEX_LENGTH, 'Generated regex pattern'); + const regex = new RegExp(pattern); + const match = uri.match(regex); + if (!match) + return null; + const result = {}; + for (let i = 0; i < names.length; i++) { + const { name, exploded } = names[i]; + const value = match[i + 1]; + const cleanName = name.replace('*', ''); + if (exploded && value.includes(',')) { + result[cleanName] = value.split(','); + } + else { + result[cleanName] = value; + } + } + return result; + } +} +exports.UriTemplate = UriTemplate; +//# sourceMappingURL=uriTemplate.js.map \ No newline at end of file diff --git a/dist/cjs/shared/uriTemplate.js.map b/dist/cjs/shared/uriTemplate.js.map new file mode 100644 index 000000000..75c5c50e2 --- /dev/null +++ b/dist/cjs/shared/uriTemplate.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uriTemplate.js","sourceRoot":"","sources":["../../../src/shared/uriTemplate.ts"],"names":[],"mappings":";AAAA,2DAA2D;;;AAI3D,MAAM,mBAAmB,GAAG,OAAO,CAAC,CAAC,MAAM;AAC3C,MAAM,mBAAmB,GAAG,OAAO,CAAC,CAAC,MAAM;AAC3C,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM;AAExC,MAAa,WAAW;IACpB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAW;QACzB,2DAA2D;QAC3D,6BAA6B;QAC7B,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,GAAW,EAAE,GAAW,EAAE,OAAe;QACnE,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,8BAA8B,GAAG,oBAAoB,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QAClG,CAAC;IACL,CAAC;IAID,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,YAAY,QAAgB;QACxB,WAAW,CAAC,cAAc,CAAC,QA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G,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE/B,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAExC,IAAI,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClC,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AArRD,kCAqRC"} \ No newline at end of file diff --git a/dist/cjs/shared/zodTestMatrix.d.ts b/dist/cjs/shared/zodTestMatrix.d.ts new file mode 100644 index 000000000..7dafd4ce9 --- /dev/null +++ b/dist/cjs/shared/zodTestMatrix.d.ts @@ -0,0 +1,16 @@ +import * as z3 from 'zod/v3'; +import * as z4 from 'zod/v4'; +export type ZNamespace = typeof z3 & typeof z4; +export declare const zodTestMatrix: readonly [{ + readonly zodVersionLabel: "Zod v3"; + readonly z: ZNamespace; + readonly isV3: true; + readonly isV4: false; +}, { + readonly zodVersionLabel: "Zod v4"; + readonly z: ZNamespace; + readonly isV3: false; + readonly isV4: true; +}]; +export type ZodMatrixEntry = (typeof zodTestMatrix)[number]; +//# sourceMappingURL=zodTestMatrix.d.ts.map \ No newline at end of file diff --git a/dist/cjs/shared/zodTestMatrix.d.ts.map b/dist/cjs/shared/zodTestMatrix.d.ts.map new file mode 100644 index 000000000..3842fb1c3 --- /dev/null +++ b/dist/cjs/shared/zodTestMatrix.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"zodTestMatrix.d.ts","sourceRoot":"","sources":["../../../src/shared/zodTestMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG7B,MAAM,MAAM,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AAE/C,eAAO,MAAM,aAAa;;gBAGT,UAAU;;;;;gBAMV,UAAU;;;EAIjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/shared/zodTestMatrix.js b/dist/cjs/shared/zodTestMatrix.js new file mode 100644 index 000000000..92627ab24 --- /dev/null +++ b/dist/cjs/shared/zodTestMatrix.js @@ -0,0 +1,43 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.zodTestMatrix = void 0; +const z3 = __importStar(require("zod/v3")); +const z4 = __importStar(require("zod/v4")); +exports.zodTestMatrix = [ + { + zodVersionLabel: 'Zod v3', + z: z3, + isV3: true, + isV4: false + }, + { + zodVersionLabel: 'Zod v4', + z: z4, + isV3: false, + isV4: true + } +]; +//# sourceMappingURL=zodTestMatrix.js.map \ No newline at end of file diff --git a/dist/cjs/shared/zodTestMatrix.js.map b/dist/cjs/shared/zodTestMatrix.js.map new file mode 100644 index 000000000..55cc0b0ac --- /dev/null +++ b/dist/cjs/shared/zodTestMatrix.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zodTestMatrix.js","sourceRoot":"","sources":["../../../src/shared/zodTestMatrix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,2CAA6B;AAKhB,QAAA,aAAa,GAAG;IACzB;QACI,eAAe,EAAE,QAAQ;QACzB,CAAC,EAAE,EAAgB;QACnB,IAAI,EAAE,IAAa;QACnB,IAAI,EAAE,KAAc;KACvB;IACD;QACI,eAAe,EAAE,QAAQ;QACzB,CAAC,EAAE,EAAgB;QACnB,IAAI,EAAE,KAAc;QACpB,IAAI,EAAE,IAAa;KACtB;CACK,CAAC"} \ No newline at end of file diff --git a/dist/cjs/spec.types.d.ts b/dist/cjs/spec.types.d.ts new file mode 100644 index 000000000..86dd720a9 --- /dev/null +++ b/dist/cjs/spec.types.d.ts @@ -0,0 +1,2010 @@ +/** + * This file is automatically generated from the Model Context Protocol specification. + * + * Source: https://github.com/modelcontextprotocol/modelcontextprotocol + * Pulled from: https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/draft/schema.ts + * Last updated from commit: 7dcdd69262bd488ddec071bf4eefedabf1742023 + * + * DO NOT EDIT THIS FILE MANUALLY. Changes will be overwritten by automated updates. + * To update this file, run: npm run fetch:spec-types + */ +/** + * Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent. + * + * @category JSON-RPC + */ +export type JSONRPCMessage = JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError; +/** @internal */ +export declare const LATEST_PROTOCOL_VERSION = "DRAFT-2025-v3"; +/** @internal */ +export declare const JSONRPC_VERSION = "2.0"; +/** + * A progress token, used to associate progress notifications with the original request. + * + * @category Common Types + */ +export type ProgressToken = string | number; +/** + * An opaque token used to represent a cursor for pagination. + * + * @category Common Types + */ +export type Cursor = string; +/** + * Common params for any request. + * + * @internal + */ +export interface RequestParams { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken?: ProgressToken; + [key: string]: unknown; + }; +} +/** @internal */ +export interface Request { + method: string; + params?: { + [key: string]: any; + }; +} +/** @internal */ +export interface NotificationParams { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** @internal */ +export interface Notification { + method: string; + params?: { + [key: string]: any; + }; +} +/** + * @category Common Types + */ +export interface Result { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; + [key: string]: unknown; +} +/** + * @category Common Types + */ +export interface Error { + /** + * The error type that occurred. + */ + code: number; + /** + * A short description of the error. The message SHOULD be limited to a concise single sentence. + */ + message: string; + /** + * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). + */ + data?: unknown; +} +/** + * A uniquely identifying ID for a request in JSON-RPC. + * + * @category Common Types + */ +export type RequestId = string | number; +/** + * A request that expects a response. + * + * @category JSON-RPC + */ +export interface JSONRPCRequest extends Request { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; +} +/** + * A notification which does not expect a response. + * + * @category JSON-RPC + */ +export interface JSONRPCNotification extends Notification { + jsonrpc: typeof JSONRPC_VERSION; +} +/** + * A successful (non-error) response to a request. + * + * @category JSON-RPC + */ +export interface JSONRPCResponse { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; + result: Result; +} +export declare const PARSE_ERROR = -32700; +export declare const INVALID_REQUEST = -32600; +export declare const METHOD_NOT_FOUND = -32601; +export declare const INVALID_PARAMS = -32602; +export declare const INTERNAL_ERROR = -32603; +/** @internal */ +export declare const URL_ELICITATION_REQUIRED = -32042; +/** + * A response to a request that indicates an error occurred. + * + * @category JSON-RPC + */ +export interface JSONRPCError { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; + error: Error; +} +/** + * An error response that indicates that the server requires the client to provide additional information via an elicitation request. + * + * @internal + */ +export interface URLElicitationRequiredError extends Omit { + error: Error & { + code: typeof URL_ELICITATION_REQUIRED; + data: { + elicitations: ElicitRequestURLParams[]; + [key: string]: unknown; + }; + }; +} +/** + * A response that indicates success but carries no data. + * + * @category Common Types + */ +export type EmptyResult = Result; +/** + * Parameters for a `notifications/cancelled` notification. + * + * @category `notifications/cancelled` + */ +export interface CancelledNotificationParams extends NotificationParams { + /** + * The ID of the request to cancel. + * + * This MUST correspond to the ID of a request previously issued in the same direction. + */ + requestId: RequestId; + /** + * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. + */ + reason?: string; +} +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + * + * @category `notifications/cancelled` + */ +export interface CancelledNotification extends JSONRPCNotification { + method: "notifications/cancelled"; + params: CancelledNotificationParams; +} +/** + * Parameters for an `initialize` request. + * + * @category `initialize` + */ +export interface InitializeRequestParams extends RequestParams { + /** + * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. + */ + protocolVersion: string; + capabilities: ClientCapabilities; + clientInfo: Implementation; +} +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + * + * @category `initialize` + */ +export interface InitializeRequest extends JSONRPCRequest { + method: "initialize"; + params: InitializeRequestParams; +} +/** + * After receiving an initialize request from the client, the server sends this response. + * + * @category `initialize` + */ +export interface InitializeResult extends Result { + /** + * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. + */ + protocolVersion: string; + capabilities: ServerCapabilities; + serverInfo: Implementation; + /** + * Instructions describing how to use the server and its features. + * + * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. + */ + instructions?: string; +} +/** + * This notification is sent from the client to the server after initialization has finished. + * + * @category `notifications/initialized` + */ +export interface InitializedNotification extends JSONRPCNotification { + method: "notifications/initialized"; + params?: NotificationParams; +} +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + * + * @category `initialize` + */ +export interface ClientCapabilities { + /** + * Experimental, non-standard capabilities that the client supports. + */ + experimental?: { + [key: string]: object; + }; + /** + * Present if the client supports listing roots. + */ + roots?: { + /** + * Whether the client supports notifications for changes to the roots list. + */ + listChanged?: boolean; + }; + /** + * Present if the client supports sampling from an LLM. + */ + sampling?: { + /** + * Whether the client supports context inclusion via includeContext parameter. + * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it). + */ + context?: object; + /** + * Whether the client supports tool use via tools and toolChoice parameters. + */ + tools?: object; + }; + /** + * Present if the client supports elicitation from the server. + */ + elicitation?: { + form?: object; + url?: object; + }; +} +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + * + * @category `initialize` + */ +export interface ServerCapabilities { + /** + * Experimental, non-standard capabilities that the server supports. + */ + experimental?: { + [key: string]: object; + }; + /** + * Present if the server supports sending log messages to the client. + */ + logging?: object; + /** + * Present if the server supports argument autocompletion suggestions. + */ + completions?: object; + /** + * Present if the server offers any prompt templates. + */ + prompts?: { + /** + * Whether this server supports notifications for changes to the prompt list. + */ + listChanged?: boolean; + }; + /** + * Present if the server offers any resources to read. + */ + resources?: { + /** + * Whether this server supports subscribing to resource updates. + */ + subscribe?: boolean; + /** + * Whether this server supports notifications for changes to the resource list. + */ + listChanged?: boolean; + }; + /** + * Present if the server offers any tools to call. + */ + tools?: { + /** + * Whether this server supports notifications for changes to the tool list. + */ + listChanged?: boolean; + }; +} +/** + * An optionally-sized icon that can be displayed in a user interface. + * + * @category Common Types + */ +export interface Icon { + /** + * A standard URI pointing to an icon resource. May be an HTTP/HTTPS URL or a + * `data:` URI with Base64-encoded image data. + * + * Consumers SHOULD takes steps to ensure URLs serving icons are from the + * same domain as the client/server or a trusted domain. + * + * Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain + * executable JavaScript. + * + * @format uri + */ + src: string; + /** + * Optional MIME type override if the source MIME type is missing or generic. + * For example: `"image/png"`, `"image/jpeg"`, or `"image/svg+xml"`. + */ + mimeType?: string; + /** + * Optional array of strings that specify sizes at which the icon can be used. + * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. + * + * If not provided, the client should assume that the icon can be used at any size. + */ + sizes?: string[]; + /** + * Optional specifier for the theme this icon is designed for. `light` indicates + * the icon is designed to be used with a light background, and `dark` indicates + * the icon is designed to be used with a dark background. + * + * If not provided, the client should assume the icon can be used with any theme. + */ + theme?: "light" | "dark"; +} +/** + * Base interface to add `icons` property. + * + * @internal + */ +export interface Icons { + /** + * Optional set of sized icons that the client can display in a user interface. + * + * Clients that support rendering icons MUST support at least the following MIME types: + * - `image/png` - PNG images (safe, universal compatibility) + * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) + * + * Clients that support rendering icons SHOULD also support: + * - `image/svg+xml` - SVG images (scalable but requires security precautions) + * - `image/webp` - WebP images (modern, efficient format) + */ + icons?: Icon[]; +} +/** + * Base interface for metadata with name (identifier) and title (display name) properties. + * + * @internal + */ +export interface BaseMetadata { + /** + * Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn't present). + */ + name: string; + /** + * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, + * even by those unfamiliar with domain-specific terminology. + * + * If not provided, the name should be used for display (except for Tool, + * where `annotations.title` should be given precedence over using `name`, + * if present). + */ + title?: string; +} +/** + * Describes the MCP implementation. + * + * @category `initialize` + */ +export interface Implementation extends BaseMetadata, Icons { + version: string; + /** + * An optional human-readable description of what this implementation does. + * + * This can be used by clients or servers to provide context about their purpose + * and capabilities. For example, a server might describe the types of resources + * or tools it provides, while a client might describe its intended use case. + */ + description?: string; + /** + * An optional URL of the website for this implementation. + * + * @format uri + */ + websiteUrl?: string; +} +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + * + * @category `ping` + */ +export interface PingRequest extends JSONRPCRequest { + method: "ping"; + params?: RequestParams; +} +/** + * Parameters for a `notifications/progress` notification. + * + * @category `notifications/progress` + */ +export interface ProgressNotificationParams extends NotificationParams { + /** + * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding. + */ + progressToken: ProgressToken; + /** + * The progress thus far. This should increase every time progress is made, even if the total is unknown. + * + * @TJS-type number + */ + progress: number; + /** + * Total number of items to process (or total progress required), if known. + * + * @TJS-type number + */ + total?: number; + /** + * An optional message describing the current progress. + */ + message?: string; +} +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category `notifications/progress` + */ +export interface ProgressNotification extends JSONRPCNotification { + method: "notifications/progress"; + params: ProgressNotificationParams; +} +/** + * Common parameters for paginated requests. + * + * @internal + */ +export interface PaginatedRequestParams extends RequestParams { + /** + * An opaque token representing the current pagination position. + * If provided, the server should return results starting after this cursor. + */ + cursor?: Cursor; +} +/** @internal */ +export interface PaginatedRequest extends JSONRPCRequest { + params?: PaginatedRequestParams; +} +/** @internal */ +export interface PaginatedResult extends Result { + /** + * An opaque token representing the pagination position after the last returned result. + * If present, there may be more results available. + */ + nextCursor?: Cursor; +} +/** + * Sent from the client to request a list of resources the server has. + * + * @category `resources/list` + */ +export interface ListResourcesRequest extends PaginatedRequest { + method: "resources/list"; +} +/** + * The server's response to a resources/list request from the client. + * + * @category `resources/list` + */ +export interface ListResourcesResult extends PaginatedResult { + resources: Resource[]; +} +/** + * Sent from the client to request a list of resource templates the server has. + * + * @category `resources/templates/list` + */ +export interface ListResourceTemplatesRequest extends PaginatedRequest { + method: "resources/templates/list"; +} +/** + * The server's response to a resources/templates/list request from the client. + * + * @category `resources/templates/list` + */ +export interface ListResourceTemplatesResult extends PaginatedResult { + resourceTemplates: ResourceTemplate[]; +} +/** + * Common parameters when working with resources. + * + * @internal + */ +export interface ResourceRequestParams extends RequestParams { + /** + * The URI of the resource. The URI can use any protocol; it is up to the server how to interpret it. + * + * @format uri + */ + uri: string; +} +/** + * Parameters for a `resources/read` request. + * + * @category `resources/read` + */ +export interface ReadResourceRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to the server, to read a specific resource URI. + * + * @category `resources/read` + */ +export interface ReadResourceRequest extends JSONRPCRequest { + method: "resources/read"; + params: ReadResourceRequestParams; +} +/** + * The server's response to a resources/read request from the client. + * + * @category `resources/read` + */ +export interface ReadResourceResult extends Result { + contents: (TextResourceContents | BlobResourceContents)[]; +} +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/resources/list_changed` + */ +export interface ResourceListChangedNotification extends JSONRPCNotification { + method: "notifications/resources/list_changed"; + params?: NotificationParams; +} +/** + * Parameters for a `resources/subscribe` request. + * + * @category `resources/subscribe` + */ +export interface SubscribeRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + * + * @category `resources/subscribe` + */ +export interface SubscribeRequest extends JSONRPCRequest { + method: "resources/subscribe"; + params: SubscribeRequestParams; +} +/** + * Parameters for a `resources/unsubscribe` request. + * + * @category `resources/unsubscribe` + */ +export interface UnsubscribeRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + * + * @category `resources/unsubscribe` + */ +export interface UnsubscribeRequest extends JSONRPCRequest { + method: "resources/unsubscribe"; + params: UnsubscribeRequestParams; +} +/** + * Parameters for a `notifications/resources/updated` notification. + * + * @category `notifications/resources/updated` + */ +export interface ResourceUpdatedNotificationParams extends NotificationParams { + /** + * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. + * + * @format uri + */ + uri: string; +} +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + * + * @category `notifications/resources/updated` + */ +export interface ResourceUpdatedNotification extends JSONRPCNotification { + method: "notifications/resources/updated"; + params: ResourceUpdatedNotificationParams; +} +/** + * A known resource that the server is capable of reading. + * + * @category `resources/list` + */ +export interface Resource extends BaseMetadata, Icons { + /** + * The URI of this resource. + * + * @format uri + */ + uri: string; + /** + * A description of what this resource represents. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * The MIME type of this resource, if known. + */ + mimeType?: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known. + * + * This can be used by Hosts to display file sizes and estimate context window usage. + */ + size?: number; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A template description for resources available on the server. + * + * @category `resources/templates/list` + */ +export interface ResourceTemplate extends BaseMetadata, Icons { + /** + * A URI template (according to RFC 6570) that can be used to construct resource URIs. + * + * @format uri-template + */ + uriTemplate: string; + /** + * A description of what this template is for. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type. + */ + mimeType?: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The contents of a specific resource or sub-resource. + * + * @internal + */ +export interface ResourceContents { + /** + * The URI of this resource. + * + * @format uri + */ + uri: string; + /** + * The MIME type of this resource, if known. + */ + mimeType?: string; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * @category Content + */ +export interface TextResourceContents extends ResourceContents { + /** + * The text of the item. This must only be set if the item can actually be represented as text (not binary data). + */ + text: string; +} +/** + * @category Content + */ +export interface BlobResourceContents extends ResourceContents { + /** + * A base64-encoded string representing the binary data of the item. + * + * @format byte + */ + blob: string; +} +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + * + * @category `prompts/list` + */ +export interface ListPromptsRequest extends PaginatedRequest { + method: "prompts/list"; +} +/** + * The server's response to a prompts/list request from the client. + * + * @category `prompts/list` + */ +export interface ListPromptsResult extends PaginatedResult { + prompts: Prompt[]; +} +/** + * Parameters for a `prompts/get` request. + * + * @category `prompts/get` + */ +export interface GetPromptRequestParams extends RequestParams { + /** + * The name of the prompt or prompt template. + */ + name: string; + /** + * Arguments to use for templating the prompt. + */ + arguments?: { + [key: string]: string; + }; +} +/** + * Used by the client to get a prompt provided by the server. + * + * @category `prompts/get` + */ +export interface GetPromptRequest extends JSONRPCRequest { + method: "prompts/get"; + params: GetPromptRequestParams; +} +/** + * The server's response to a prompts/get request from the client. + * + * @category `prompts/get` + */ +export interface GetPromptResult extends Result { + /** + * An optional description for the prompt. + */ + description?: string; + messages: PromptMessage[]; +} +/** + * A prompt or prompt template that the server offers. + * + * @category `prompts/list` + */ +export interface Prompt extends BaseMetadata, Icons { + /** + * An optional description of what this prompt provides + */ + description?: string; + /** + * A list of arguments to use for templating the prompt. + */ + arguments?: PromptArgument[]; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Describes an argument that a prompt can accept. + * + * @category `prompts/list` + */ +export interface PromptArgument extends BaseMetadata { + /** + * A human-readable description of the argument. + */ + description?: string; + /** + * Whether this argument must be provided. + */ + required?: boolean; +} +/** + * The sender or recipient of messages and data in a conversation. + * + * @category Common Types + */ +export type Role = "user" | "assistant"; +/** + * Describes a message returned as part of a prompt. + * + * This is similar to `SamplingMessage`, but also supports the embedding of + * resources from the MCP server. + * + * @category `prompts/get` + */ +export interface PromptMessage { + role: Role; + content: ContentBlock; +} +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + * + * @category Content + */ +export interface ResourceLink extends Resource { + type: "resource_link"; +} +/** + * The contents of a resource, embedded into a prompt or tool call result. + * + * It is up to the client how best to render embedded resources for the benefit + * of the LLM and/or the user. + * + * @category Content + */ +export interface EmbeddedResource { + type: "resource"; + resource: TextResourceContents | BlobResourceContents; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/prompts/list_changed` + */ +export interface PromptListChangedNotification extends JSONRPCNotification { + method: "notifications/prompts/list_changed"; + params?: NotificationParams; +} +/** + * Sent from the client to request a list of tools the server has. + * + * @category `tools/list` + */ +export interface ListToolsRequest extends PaginatedRequest { + method: "tools/list"; +} +/** + * The server's response to a tools/list request from the client. + * + * @category `tools/list` + */ +export interface ListToolsResult extends PaginatedResult { + tools: Tool[]; +} +/** + * The server's response to a tool call. + * + * @category `tools/call` + */ +export interface CallToolResult extends Result { + /** + * A list of content objects that represent the unstructured result of the tool call. + */ + content: ContentBlock[]; + /** + * An optional JSON object that represents the structured result of the tool call. + */ + structuredContent?: { + [key: string]: unknown; + }; + /** + * Whether the tool call ended in an error. + * + * If not set, this is assumed to be false (the call was successful). + * + * Any errors that originate from the tool SHOULD be reported inside the result + * object, with `isError` set to true, _not_ as an MCP protocol-level error + * response. Otherwise, the LLM would not be able to see that an error occurred + * and self-correct. + * + * However, any errors in _finding_ the tool, an error indicating that the + * server does not support tool calls, or any other exceptional conditions, + * should be reported as an MCP error response. + */ + isError?: boolean; +} +/** + * Parameters for a `tools/call` request. + * + * @category `tools/call` + */ +export interface CallToolRequestParams extends RequestParams { + /** + * The name of the tool. + */ + name: string; + /** + * Arguments to use for the tool call. + */ + arguments?: { + [key: string]: unknown; + }; +} +/** + * Used by the client to invoke a tool provided by the server. + * + * @category `tools/call` + */ +export interface CallToolRequest extends JSONRPCRequest { + method: "tools/call"; + params: CallToolRequestParams; +} +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/tools/list_changed` + */ +export interface ToolListChangedNotification extends JSONRPCNotification { + method: "notifications/tools/list_changed"; + params?: NotificationParams; +} +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + * + * @category `tools/list` + */ +export interface ToolAnnotations { + /** + * A human-readable title for the tool. + */ + title?: string; + /** + * If true, the tool does not modify its environment. + * + * Default: false + */ + readOnlyHint?: boolean; + /** + * If true, the tool may perform destructive updates to its environment. + * If false, the tool performs only additive updates. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: true + */ + destructiveHint?: boolean; + /** + * If true, calling the tool repeatedly with the same arguments + * will have no additional effect on its environment. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: false + */ + idempotentHint?: boolean; + /** + * If true, this tool may interact with an "open world" of external + * entities. If false, the tool's domain of interaction is closed. + * For example, the world of a web search tool is open, whereas that + * of a memory tool is not. + * + * Default: true + */ + openWorldHint?: boolean; +} +/** + * Definition for a tool the client can call. + * + * @category `tools/list` + */ +export interface Tool extends BaseMetadata, Icons { + /** + * A human-readable description of the tool. + * + * This can be used by clients to improve the LLM's understanding of available tools. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * A JSON Schema object defining the expected parameters for the tool. + */ + inputSchema: { + type: "object"; + properties?: { + [key: string]: object; + }; + required?: string[]; + }; + /** + * An optional JSON Schema object defining the structure of the tool's output returned in + * the structuredContent field of a CallToolResult. + */ + outputSchema?: { + type: "object"; + properties?: { + [key: string]: object; + }; + required?: string[]; + }; + /** + * Optional additional tool information. + * + * Display name precedence order is: title, annotations.title, then name. + */ + annotations?: ToolAnnotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Parameters for a `logging/setLevel` request. + * + * @category `logging/setLevel` + */ +export interface SetLevelRequestParams extends RequestParams { + /** + * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message. + */ + level: LoggingLevel; +} +/** + * A request from the client to the server, to enable or adjust logging. + * + * @category `logging/setLevel` + */ +export interface SetLevelRequest extends JSONRPCRequest { + method: "logging/setLevel"; + params: SetLevelRequestParams; +} +/** + * Parameters for a `notifications/message` notification. + * + * @category `notifications/message` + */ +export interface LoggingMessageNotificationParams extends NotificationParams { + /** + * The severity of this log message. + */ + level: LoggingLevel; + /** + * An optional name of the logger issuing this message. + */ + logger?: string; + /** + * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. + */ + data: unknown; +} +/** + * JSONRPCNotification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + * + * @category `notifications/message` + */ +export interface LoggingMessageNotification extends JSONRPCNotification { + method: "notifications/message"; + params: LoggingMessageNotificationParams; +} +/** + * The severity of a log message. + * + * These map to syslog message severities, as specified in RFC-5424: + * https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1 + * + * @category Common Types + */ +export type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"; +/** + * Parameters for a `sampling/createMessage` request. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageRequestParams extends RequestParams { + messages: SamplingMessage[]; + /** + * The server's preferences for which model to select. The client MAY ignore these preferences. + */ + modelPreferences?: ModelPreferences; + /** + * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt. + */ + systemPrompt?: string; + /** + * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. + * The client MAY ignore this request. + * + * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client + * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases. + */ + includeContext?: "none" | "thisServer" | "allServers"; + /** + * @TJS-type number + */ + temperature?: number; + /** + * The requested maximum number of tokens to sample (to prevent runaway completions). + * + * The client MAY choose to sample fewer tokens than the requested maximum. + */ + maxTokens: number; + stopSequences?: string[]; + /** + * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific. + */ + metadata?: object; + /** + * Tools that the model may use during generation. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + */ + tools?: Tool[]; + /** + * Controls how the model uses tools. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + * Default is `{ mode: "auto" }`. + */ + toolChoice?: ToolChoice; +} +/** + * Controls tool selection behavior for sampling requests. + * + * @category `sampling/createMessage` + */ +export interface ToolChoice { + /** + * Controls the tool use ability of the model: + * - "auto": Model decides whether to use tools (default) + * - "required": Model MUST use at least one tool before completing + * - "none": Model MUST NOT use any tools + */ + mode?: "auto" | "required" | "none"; +} +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageRequest extends JSONRPCRequest { + method: "sampling/createMessage"; + params: CreateMessageRequestParams; +} +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageResult extends Result, SamplingMessage { + /** + * The name of the model that generated the message. + */ + model: string; + /** + * The reason why sampling stopped, if known. + * + * Standard values: + * - "endTurn": Natural end of the assistant's turn + * - "stopSequence": A stop sequence was encountered + * - "maxTokens": Maximum token limit was reached + * - "toolUse": The model wants to use one or more tools + * + * This field is an open string to allow for provider-specific stop reasons. + */ + stopReason?: "endTurn" | "stopSequence" | "maxTokens" | "toolUse" | string; +} +/** + * Describes a message issued to or received from an LLM API. + * + * @category `sampling/createMessage` + */ +export interface SamplingMessage { + role: Role; + content: SamplingMessageContentBlock | SamplingMessageContentBlock[]; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +export type SamplingMessageContentBlock = TextContent | ImageContent | AudioContent | ToolUseContent | ToolResultContent; +/** + * Optional annotations for the client. The client can use annotations to inform how objects are used or displayed + * + * @category Common Types + */ +export interface Annotations { + /** + * Describes who the intended audience of this object or data is. + * + * It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`). + */ + audience?: Role[]; + /** + * Describes how important this data is for operating the server. + * + * A value of 1 means "most important," and indicates that the data is + * effectively required, while 0 means "least important," and indicates that + * the data is entirely optional. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + priority?: number; + /** + * The moment the resource was last modified, as an ISO 8601 formatted string. + * + * Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z"). + * + * Examples: last activity timestamp in an open file, timestamp when the resource + * was attached, etc. + */ + lastModified?: string; +} +/** + * @category Content + */ +export type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource; +/** + * Text provided to or from an LLM. + * + * @category Content + */ +export interface TextContent { + type: "text"; + /** + * The text content of the message. + */ + text: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * An image provided to or from an LLM. + * + * @category Content + */ +export interface ImageContent { + type: "image"; + /** + * The base64-encoded image data. + * + * @format byte + */ + data: string; + /** + * The MIME type of the image. Different providers may support different image types. + */ + mimeType: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Audio provided to or from an LLM. + * + * @category Content + */ +export interface AudioContent { + type: "audio"; + /** + * The base64-encoded audio data. + * + * @format byte + */ + data: string; + /** + * The MIME type of the audio. Different providers may support different audio types. + */ + mimeType: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A request from the assistant to call a tool. + * + * @category `sampling/createMessage` + */ +export interface ToolUseContent { + type: "tool_use"; + /** + * A unique identifier for this tool use. + * + * This ID is used to match tool results to their corresponding tool uses. + */ + id: string; + /** + * The name of the tool to call. + */ + name: string; + /** + * The arguments to pass to the tool, conforming to the tool's input schema. + */ + input: { + [key: string]: unknown; + }; + /** + * Optional metadata about the tool use. Clients SHOULD preserve this field when + * including tool uses in subsequent sampling requests to enable caching optimizations. + * + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The result of a tool use, provided by the user back to the assistant. + * + * @category `sampling/createMessage` + */ +export interface ToolResultContent { + type: "tool_result"; + /** + * The ID of the tool use this result corresponds to. + * + * This MUST match the ID from a previous ToolUseContent. + */ + toolUseId: string; + /** + * The unstructured result content of the tool use. + * + * This has the same format as CallToolResult.content and can include text, images, + * audio, resource links, and embedded resources. + */ + content: ContentBlock[]; + /** + * An optional structured result object. + * + * If the tool defined an outputSchema, this SHOULD conform to that schema. + */ + structuredContent?: { + [key: string]: unknown; + }; + /** + * Whether the tool use resulted in an error. + * + * If true, the content typically describes the error that occurred. + * Default: false + */ + isError?: boolean; + /** + * Optional metadata about the tool result. Clients SHOULD preserve this field when + * including tool results in subsequent sampling requests to enable caching optimizations. + * + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The server's preferences for model selection, requested of the client during sampling. + * + * Because LLMs can vary along multiple dimensions, choosing the "best" model is + * rarely straightforward. Different models excel in different areas—some are + * faster but less capable, others are more capable but more expensive, and so + * on. This interface allows servers to express their priorities across multiple + * dimensions to help clients make an appropriate selection for their use case. + * + * These preferences are always advisory. The client MAY ignore them. It is also + * up to the client to decide how to interpret these preferences and how to + * balance them against other considerations. + * + * @category `sampling/createMessage` + */ +export interface ModelPreferences { + /** + * Optional hints to use for model selection. + * + * If multiple hints are specified, the client MUST evaluate them in order + * (such that the first match is taken). + * + * The client SHOULD prioritize these hints over the numeric priorities, but + * MAY still use the priorities to select from ambiguous matches. + */ + hints?: ModelHint[]; + /** + * How much to prioritize cost when selecting a model. A value of 0 means cost + * is not important, while a value of 1 means cost is the most important + * factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + costPriority?: number; + /** + * How much to prioritize sampling speed (latency) when selecting a model. A + * value of 0 means speed is not important, while a value of 1 means speed is + * the most important factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + speedPriority?: number; + /** + * How much to prioritize intelligence and capabilities when selecting a + * model. A value of 0 means intelligence is not important, while a value of 1 + * means intelligence is the most important factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + intelligencePriority?: number; +} +/** + * Hints to use for model selection. + * + * Keys not declared here are currently left unspecified by the spec and are up + * to the client to interpret. + * + * @category `sampling/createMessage` + */ +export interface ModelHint { + /** + * A hint for a model name. + * + * The client SHOULD treat this as a substring of a model name; for example: + * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` + * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. + * - `claude` should match any Claude model + * + * The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: + * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` + */ + name?: string; +} +/** + * Parameters for a `completion/complete` request. + * + * @category `completion/complete` + */ +export interface CompleteRequestParams extends RequestParams { + ref: PromptReference | ResourceTemplateReference; + /** + * The argument's information + */ + argument: { + /** + * The name of the argument + */ + name: string; + /** + * The value of the argument to use for completion matching. + */ + value: string; + }; + /** + * Additional, optional context for completions + */ + context?: { + /** + * Previously-resolved variables in a URI template or prompt. + */ + arguments?: { + [key: string]: string; + }; + }; +} +/** + * A request from the client to the server, to ask for completion options. + * + * @category `completion/complete` + */ +export interface CompleteRequest extends JSONRPCRequest { + method: "completion/complete"; + params: CompleteRequestParams; +} +/** + * The server's response to a completion/complete request + * + * @category `completion/complete` + */ +export interface CompleteResult extends Result { + completion: { + /** + * An array of completion values. Must not exceed 100 items. + */ + values: string[]; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total?: number; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore?: boolean; + }; +} +/** + * A reference to a resource or resource template definition. + * + * @category `completion/complete` + */ +export interface ResourceTemplateReference { + type: "ref/resource"; + /** + * The URI or URI template of the resource. + * + * @format uri-template + */ + uri: string; +} +/** + * Identifies a prompt. + * + * @category `completion/complete` + */ +export interface PromptReference extends BaseMetadata { + type: "ref/prompt"; +} +/** + * Sent from the server to request a list of root URIs from the client. Roots allow + * servers to ask for specific directories or files to operate on. A common example + * for roots is providing a set of repositories or directories a server should operate + * on. + * + * This request is typically used when the server needs to understand the file system + * structure or access specific locations that the client has permission to read from. + * + * @category `roots/list` + */ +export interface ListRootsRequest extends JSONRPCRequest { + method: "roots/list"; + params?: RequestParams; +} +/** + * The client's response to a roots/list request from the server. + * This result contains an array of Root objects, each representing a root directory + * or file that the server can operate on. + * + * @category `roots/list` + */ +export interface ListRootsResult extends Result { + roots: Root[]; +} +/** + * Represents a root directory or file that the server can operate on. + * + * @category `roots/list` + */ +export interface Root { + /** + * The URI identifying the root. This *must* start with file:// for now. + * This restriction may be relaxed in future versions of the protocol to allow + * other URI schemes. + * + * @format uri + */ + uri: string; + /** + * An optional name for the root. This can be used to provide a human-readable + * identifier for the root, which may be useful for display purposes or for + * referencing the root in other parts of the application. + */ + name?: string; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A notification from the client to the server, informing it that the list of roots has changed. + * This notification should be sent whenever the client adds, removes, or modifies any root. + * The server should then request an updated list of roots using the ListRootsRequest. + * + * @category `notifications/roots/list_changed` + */ +export interface RootsListChangedNotification extends JSONRPCNotification { + method: "notifications/roots/list_changed"; + params?: NotificationParams; +} +/** + * The parameters for a request to elicit non-sensitive information from the user via a form in the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequestFormParams extends RequestParams { + /** + * The elicitation mode. + */ + mode?: "form"; + /** + * The message to present to the user describing what information is being requested. + */ + message: string; + /** + * A restricted subset of JSON Schema. + * Only top-level properties are allowed, without nesting. + */ + requestedSchema: { + $schema?: string; + type: "object"; + properties: { + [key: string]: PrimitiveSchemaDefinition; + }; + required?: string[]; + }; +} +/** + * The parameters for a request to elicit information from the user via a URL in the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequestURLParams extends RequestParams { + /** + * The elicitation mode. + */ + mode: "url"; + /** + * The message to present to the user explaining why the interaction is needed. + */ + message: string; + /** + * The ID of the elicitation, which must be unique within the context of the server. + * The client MUST treat this ID as an opaque value. + */ + elicitationId: string; + /** + * The URL that the user should navigate to. + * + * @format uri + */ + url: string; +} +/** + * The parameters for a request to elicit additional information from the user via the client. + * + * @category `elicitation/create` + */ +export type ElicitRequestParams = ElicitRequestFormParams | ElicitRequestURLParams; +/** + * A request from the server to elicit additional information from the user via the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequest extends JSONRPCRequest { + method: "elicitation/create"; + params: ElicitRequestParams; +} +/** + * Restricted schema definitions that only allow primitive types + * without nested objects or arrays. + * + * @category `elicitation/create` + */ +export type PrimitiveSchemaDefinition = StringSchema | NumberSchema | BooleanSchema | EnumSchema; +/** + * @category `elicitation/create` + */ +export interface StringSchema { + type: "string"; + title?: string; + description?: string; + minLength?: number; + maxLength?: number; + format?: "email" | "uri" | "date" | "date-time"; + default?: string; +} +/** + * @category `elicitation/create` + */ +export interface NumberSchema { + type: "number" | "integer"; + title?: string; + description?: string; + minimum?: number; + maximum?: number; + default?: number; +} +/** + * @category `elicitation/create` + */ +export interface BooleanSchema { + type: "boolean"; + title?: string; + description?: string; + default?: boolean; +} +/** + * Schema for single-selection enumeration without display titles for options. + * + * @category `elicitation/create` + */ +export interface UntitledSingleSelectEnumSchema { + type: "string"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Array of enum values to choose from. + */ + enum: string[]; + /** + * Optional default value. + */ + default?: string; +} +/** + * Schema for single-selection enumeration with display titles for each option. + * + * @category `elicitation/create` + */ +export interface TitledSingleSelectEnumSchema { + type: "string"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Array of enum options with values and display labels. + */ + oneOf: Array<{ + /** + * The enum value. + */ + const: string; + /** + * Display label for this option. + */ + title: string; + }>; + /** + * Optional default value. + */ + default?: string; +} +/** + * @category `elicitation/create` + */ +export type SingleSelectEnumSchema = UntitledSingleSelectEnumSchema | TitledSingleSelectEnumSchema; +/** + * Schema for multiple-selection enumeration without display titles for options. + * + * @category `elicitation/create` + */ +export interface UntitledMultiSelectEnumSchema { + type: "array"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Minimum number of items to select. + */ + minItems?: number; + /** + * Maximum number of items to select. + */ + maxItems?: number; + /** + * Schema for the array items. + */ + items: { + type: "string"; + /** + * Array of enum values to choose from. + */ + enum: string[]; + }; + /** + * Optional default value. + */ + default?: string[]; +} +/** + * Schema for multiple-selection enumeration with display titles for each option. + * + * @category `elicitation/create` + */ +export interface TitledMultiSelectEnumSchema { + type: "array"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Minimum number of items to select. + */ + minItems?: number; + /** + * Maximum number of items to select. + */ + maxItems?: number; + /** + * Schema for array items with enum options and display labels. + */ + items: { + /** + * Array of enum options with values and display labels. + */ + anyOf: Array<{ + /** + * The constant enum value. + */ + const: string; + /** + * Display title for this option. + */ + title: string; + }>; + }; + /** + * Optional default value. + */ + default?: string[]; +} +/** + * @category `elicitation/create` + */ +export type MultiSelectEnumSchema = UntitledMultiSelectEnumSchema | TitledMultiSelectEnumSchema; +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + * + * @category `elicitation/create` + */ +export interface LegacyTitledEnumSchema { + type: "string"; + title?: string; + description?: string; + enum: string[]; + /** + * (Legacy) Display names for enum values. + * Non-standard according to JSON schema 2020-12. + */ + enumNames?: string[]; + default?: string; +} +/** + * @category `elicitation/create` + */ +export type EnumSchema = SingleSelectEnumSchema | MultiSelectEnumSchema | LegacyTitledEnumSchema; +/** + * The client's response to an elicitation request. + * + * @category `elicitation/create` + */ +export interface ElicitResult extends Result { + /** + * The user action in response to the elicitation. + * - "accept": User submitted the form/confirmed the action + * - "decline": User explicitly decline the action + * - "cancel": User dismissed without making an explicit choice + */ + action: "accept" | "decline" | "cancel"; + /** + * The submitted form data, only present when action is "accept" and mode was "form". + * Contains values matching the requested schema. + * Omitted for out-of-band mode responses. + */ + content?: { + [key: string]: string | number | boolean | string[]; + }; +} +/** + * An optional notification from the server to the client, informing it of a completion of a out-of-band elicitation request. + * + * @category `notifications/elicitation/complete` + */ +export interface ElicitationCompleteNotification extends JSONRPCNotification { + method: "notifications/elicitation/complete"; + params: { + /** + * The ID of the elicitation that completed. + */ + elicitationId: string; + }; +} +/** @internal */ +export type ClientRequest = PingRequest | InitializeRequest | CompleteRequest | SetLevelRequest | GetPromptRequest | ListPromptsRequest | ListResourcesRequest | ListResourceTemplatesRequest | ReadResourceRequest | SubscribeRequest | UnsubscribeRequest | CallToolRequest | ListToolsRequest; +/** @internal */ +export type ClientNotification = CancelledNotification | ProgressNotification | InitializedNotification | RootsListChangedNotification; +/** @internal */ +export type ClientResult = EmptyResult | CreateMessageResult | ListRootsResult | ElicitResult; +/** @internal */ +export type ServerRequest = PingRequest | CreateMessageRequest | ListRootsRequest | ElicitRequest; +/** @internal */ +export type ServerNotification = CancelledNotification | ProgressNotification | LoggingMessageNotification | ResourceUpdatedNotification | ResourceListChangedNotification | ToolListChangedNotification | PromptListChangedNotification | ElicitationCompleteNotification; +/** @internal */ +export type ServerResult = EmptyResult | InitializeResult | CompleteResult | GetPromptResult | ListPromptsResult | ListResourceTemplatesResult | ListResourcesResult | ReadResourceResult | CallToolResult | ListToolsResult; +//# sourceMappingURL=spec.types.d.ts.map \ No newline at end of file diff --git a/dist/cjs/spec.types.d.ts.map b/dist/cjs/spec.types.d.ts.map new file mode 100644 index 000000000..9ba480f8b --- /dev/null +++ b/dist/cjs/spec.types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"spec.types.d.ts","sourceRoot":"","sources":["../../src/spec.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,mBAAmB,GACnB,eAAe,GACf,YAAY,CAAC;AAEjB,gBAAgB;AAChB,eAAO,MAAM,uBAAuB,kBAAkB,CAAC;AACvD,gB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AE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;CACnE;AAED;;;;GAIG;AACH,MAAM,WAAW,+BAAgC,SAAQ,mBAAmB;IAC1E,MAAM,EAAE,oCAAoC,CAAC;IAC7C,MAAM,EAAE;QACN;;WAEG;QACH,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAGD,gBAAgB;AAChB,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,4BAA4B,GAC5B,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,CAAC;AAErB,gBAAgB;AAChB,MAAM,MAAM,kBAAkB,GAC1B,qBAAqB,GACrB,oBAAoB,GACpB,uBAAuB,GACvB,4BAA4B,CAAC;AAEjC,gBAAgB;AAChB,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,mBAAmB,GACnB,eAAe,GACf,YAAY,CAAC;AAGjB,gBAAgB;AAChB,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,oBAAoB,GACpB,gBAAgB,GAChB,aAAa,CAAC;AAElB,gBAAgB;AAChB,MAAM,MAAM,kBAAkB,GAC1B,qBAAqB,GACrB,oBAAoB,GACpB,0BAA0B,GAC1B,2BAA2B,GAC3B,+BAA+B,GAC/B,2BAA2B,GAC3B,6BAA6B,GAC7B,+BAA+B,CAAC;AAEpC,gBAAgB;AAChB,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,iBAAiB,GACjB,2BAA2B,GAC3B,mBAAmB,GACnB,kBAAkB,GAClB,cAAc,GACd,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/cjs/spec.types.js b/dist/cjs/spec.types.js new file mode 100644 index 000000000..60f4fbcf4 --- /dev/null +++ b/dist/cjs/spec.types.js @@ -0,0 +1,27 @@ +"use strict"; +/** + * This file is automatically generated from the Model Context Protocol specification. + * + * Source: https://github.com/modelcontextprotocol/modelcontextprotocol + * Pulled from: https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/draft/schema.ts + * Last updated from commit: 7dcdd69262bd488ddec071bf4eefedabf1742023 + * + * DO NOT EDIT THIS FILE MANUALLY. Changes will be overwritten by automated updates. + * To update this file, run: npm run fetch:spec-types + */ /* JSON-RPC types */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.URL_ELICITATION_REQUIRED = exports.INTERNAL_ERROR = exports.INVALID_PARAMS = exports.METHOD_NOT_FOUND = exports.INVALID_REQUEST = exports.PARSE_ERROR = exports.JSONRPC_VERSION = exports.LATEST_PROTOCOL_VERSION = void 0; +/** @internal */ +exports.LATEST_PROTOCOL_VERSION = "DRAFT-2025-v3"; +/** @internal */ +exports.JSONRPC_VERSION = "2.0"; +// Standard JSON-RPC error codes +exports.PARSE_ERROR = -32700; +exports.INVALID_REQUEST = -32600; +exports.METHOD_NOT_FOUND = -32601; +exports.INVALID_PARAMS = -32602; +exports.INTERNAL_ERROR = -32603; +// Implementation-specific JSON-RPC error codes [-32000, -32099] +/** @internal */ +exports.URL_ELICITATION_REQUIRED = -32042; +//# sourceMappingURL=spec.types.js.map \ No newline at end of file diff --git a/dist/cjs/spec.types.js.map b/dist/cjs/spec.types.js.map new file mode 100644 index 000000000..0a09728c5 --- /dev/null +++ b/dist/cjs/spec.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"spec.types.js","sourceRoot":"","sources":["../../src/spec.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG,CAAA,oBAAoB;;;AAavB,gBAAgB;AACH,QAAA,uBAAuB,GAAG,eAAe,CAAC;AACvD,gBAAgB;AACH,QAAA,eAAe,GAAG,KAAK,CAAC;AA4HrC,gCAAgC;AACnB,QAAA,WAAW,GAAG,CAAC,KAAK,CAAC;AACrB,QAAA,eAAe,GAAG,CAAC,KAAK,CAAC;AACzB,QAAA,gBAAgB,GAAG,CAAC,KAAK,CAAC;AAC1B,QAAA,cAAc,GAAG,CAAC,KAAK,CAAC;AACxB,QAAA,cAAc,GAAG,CAAC,KAAK,CAAC;AAErC,gEAAgE;AAChE,gBAAgB;AACH,QAAA,wBAAwB,GAAG,CAAC,KAAK,CAAC"} \ No newline at end of file diff --git a/dist/cjs/types.d.ts b/dist/cjs/types.d.ts new file mode 100644 index 000000000..0d539e3f2 --- /dev/null +++ b/dist/cjs/types.d.ts @@ -0,0 +1,6508 @@ +import * as z from 'zod/v4'; +import { AuthInfo } from './server/auth/types.js'; +export declare const LATEST_PROTOCOL_VERSION = "2025-06-18"; +export declare const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26"; +export declare const SUPPORTED_PROTOCOL_VERSIONS: string[]; +export declare const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task"; +export declare const JSONRPC_VERSION = "2.0"; +/** + * Utility types + */ +type ExpandRecursively = T extends object ? (T extends infer O ? { + [K in keyof O]: ExpandRecursively; +} : never) : T; +/** + * A progress token, used to associate progress notifications with the original request. + */ +export declare const ProgressTokenSchema: z.ZodUnion; +/** + * An opaque token used to represent a cursor for pagination. + */ +export declare const CursorSchema: z.ZodString; +/** + * Task creation parameters, used to ask that the server create a task to represent a request. + */ +export declare const TaskCreationParamsSchema: z.ZodObject<{ + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; +}, z.core.$loose>; +/** + * Task association metadata, used to signal which task a message originated from. + */ +export declare const RelatedTaskMetadataSchema: z.ZodObject<{ + taskId: z.ZodString; +}, z.core.$loose>; +declare const RequestMetaSchema: z.ZodObject<{ + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; +}, z.core.$loose>; +/** + * Common params for any request. + */ +declare const BaseRequestParamsSchema: z.ZodObject<{ + /** + * If specified, the caller is requesting that the receiver create a task to represent the request. + * Task creation parameters are now at the top level instead of in _meta. + */ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +export declare const RequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +declare const NotificationsParamsSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +export declare const NotificationSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const ResultSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * A uniquely identifying ID for a request in JSON-RPC. + */ +export declare const RequestIdSchema: z.ZodUnion; +/** + * A request that expects a response. + */ +export declare const JSONRPCRequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; +}, z.core.$strict>; +export declare const isJSONRPCRequest: (value: unknown) => value is JSONRPCRequest; +/** + * A notification which does not expect a response. + */ +export declare const JSONRPCNotificationSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; +}, z.core.$strict>; +export declare const isJSONRPCNotification: (value: unknown) => value is JSONRPCNotification; +/** + * A successful (non-error) response to a request. + */ +export declare const JSONRPCResponseSchema: z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + result: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>; +}, z.core.$strict>; +export declare const isJSONRPCResponse: (value: unknown) => value is JSONRPCResponse; +/** + * Error codes defined by the JSON-RPC specification. + */ +export declare enum ErrorCode { + ConnectionClosed = -32000, + RequestTimeout = -32001, + ParseError = -32700, + InvalidRequest = -32600, + MethodNotFound = -32601, + InvalidParams = -32602, + InternalError = -32603, + UrlElicitationRequired = -32042 +} +/** + * A response to a request that indicates an error occurred. + */ +export declare const JSONRPCErrorSchema: z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + error: z.ZodObject<{ + code: z.ZodNumber; + message: z.ZodString; + data: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strict>; +export declare const isJSONRPCError: (value: unknown) => value is JSONRPCError; +export declare const JSONRPCMessageSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; +}, z.core.$strict>, z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; +}, z.core.$strict>, z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + result: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>; +}, z.core.$strict>, z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + error: z.ZodObject<{ + code: z.ZodNumber; + message: z.ZodString; + data: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strict>]>; +/** + * A response that indicates success but carries no data. + */ +export declare const EmptyResultSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$strict>; +export declare const CancelledNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; +}, z.core.$loose>; +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + */ +export declare const CancelledNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/cancelled">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Icon schema for use in tools, prompts, resources, and implementations. + */ +export declare const IconSchema: z.ZodObject<{ + src: z.ZodString; + mimeType: z.ZodOptional; + sizes: z.ZodOptional>; +}, z.core.$strip>; +/** + * Base schema to add `icons` property. + * + */ +export declare const IconsSchema: z.ZodObject<{ + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; +}, z.core.$strip>; +/** + * Base metadata interface for common properties across resources, tools, prompts, and implementations. + */ +export declare const BaseMetadataSchema: z.ZodObject<{ + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Describes the name and version of an MCP implementation. + */ +export declare const ImplementationSchema: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Task capabilities for clients, indicating which request types support task creation. + */ +export declare const ClientTasksCapabilitySchema: z.ZodObject<{ + list: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * Task capabilities for servers, indicating which request types support task creation. + */ +export declare const ServerTasksCapabilitySchema: z.ZodObject<{ + list: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + */ +export declare const ClientCapabilitiesSchema: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const InitializeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + */ +export declare const InitializeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"initialize">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + }, z.core.$loose>; +}, z.core.$strip>; +export declare const isInitializeRequest: (value: unknown) => value is InitializeRequest; +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + */ +export declare const ServerCapabilitiesSchema: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * After receiving an initialize request from the client, the server sends this response. + */ +export declare const InitializeResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>; + serverInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + instructions: z.ZodOptional; +}, z.core.$loose>; +/** + * This notification is sent from the client to the server after initialization has finished. + */ +export declare const InitializedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/initialized">; +}, z.core.$strip>; +export declare const isInitializedNotification: (value: unknown) => value is InitializedNotification; +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + */ +export declare const PingRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>; +export declare const ProgressSchema: z.ZodObject<{ + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; +}, z.core.$strip>; +export declare const ProgressNotificationParamsSchema: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$strip>; +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category notifications/progress + */ +export declare const ProgressNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>; +export declare const PaginatedRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; +}, z.core.$loose>; +export declare const PaginatedRequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const PaginatedResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; +}, z.core.$loose>; +/** + * A pollable state object associated with a request. + */ +export declare const TaskSchema: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * Result returned when a task is created, containing the task data wrapped in a task field. + */ +export declare const CreateTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * Parameters for task status notification. + */ +export declare const TaskStatusNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * A notification sent when a task's status changes. + */ +export declare const TaskStatusNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>; +/** + * A request to get the state of a specific task. + */ +export declare const GetTaskRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The response to a tasks/get request. + */ +export declare const GetTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * A request to get the result of a specific task. + */ +export declare const GetTaskPayloadRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * A request to list tasks. + */ +export declare const ListTasksRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>; +/** + * The response to a tasks/list request. + */ +export declare const ListTasksResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request to cancel a specific task. + */ +export declare const CancelTaskRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/cancel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The response to a tasks/cancel request. + */ +export declare const CancelTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * The contents of a specific resource or sub-resource. + */ +export declare const ResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$strip>; +export declare const TextResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + text: z.ZodString; +}, z.core.$strip>; +export declare const BlobResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; +}, z.core.$strip>; +/** + * A known resource that the server is capable of reading. + */ +export declare const ResourceSchema: z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * A template description for resources available on the server. + */ +export declare const ResourceTemplateSchema: z.ZodObject<{ + uriTemplate: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of resources the server has. + */ +export declare const ListResourcesRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/list">; +}, z.core.$strip>; +/** + * The server's response to a resources/list request from the client. + */ +export declare const ListResourcesResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resources: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * Sent from the client to request a list of resource templates the server has. + */ +export declare const ListResourceTemplatesRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/templates/list">; +}, z.core.$strip>; +/** + * The server's response to a resources/templates/list request from the client. + */ +export declare const ListResourceTemplatesResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resourceTemplates: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +export declare const ResourceRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Parameters for a `resources/read` request. + */ +export declare const ReadResourceRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to the server, to read a specific resource URI. + */ +export declare const ReadResourceRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/read">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The server's response to a resources/read request from the client. + */ +export declare const ReadResourceResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + contents: z.ZodArray; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>>; +}, z.core.$loose>; +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const ResourceListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/resources/list_changed">; +}, z.core.$strip>; +export declare const SubscribeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + */ +export declare const SubscribeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/subscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +export declare const UnsubscribeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + */ +export declare const UnsubscribeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/unsubscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/resources/updated` notification. + */ +export declare const ResourceUpdatedNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + */ +export declare const ResourceUpdatedNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/resources/updated">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Describes an argument that a prompt can accept. + */ +export declare const PromptArgumentSchema: z.ZodObject<{ + name: z.ZodString; + description: z.ZodOptional; + required: z.ZodOptional; +}, z.core.$strip>; +/** + * A prompt or prompt template that the server offers. + */ +export declare const PromptSchema: z.ZodObject<{ + description: z.ZodOptional; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + */ +export declare const ListPromptsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"prompts/list">; +}, z.core.$strip>; +/** + * The server's response to a prompts/list request from the client. + */ +export declare const ListPromptsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + prompts: z.ZodArray; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * Parameters for a `prompts/get` request. + */ +export declare const GetPromptRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; +}, z.core.$loose>; +/** + * Used by the client to get a prompt provided by the server. + */ +export declare const GetPromptRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"prompts/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Text provided to or from an LLM. + */ +export declare const TextContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"text">; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * An image provided to or from an LLM. + */ +export declare const ImageContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * An Audio provided to or from an LLM. + */ +export declare const AudioContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * A tool call request from an assistant (LLM). + * Represents the assistant's request to use a tool. + */ +export declare const ToolUseContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * The contents of a resource, embedded into a prompt or tool call result. + */ +export declare const EmbeddedResourceSchema: z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + */ +export declare const ResourceLinkSchema: z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; +}, z.core.$strip>; +/** + * A content block that can be used in prompts and tool results. + */ +export declare const ContentBlockSchema: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; +}, z.core.$strip>]>; +/** + * Describes a message returned as part of a prompt. + */ +export declare const PromptMessageSchema: z.ZodObject<{ + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; +}, z.core.$strip>; +/** + * The server's response to a prompts/get request from the client. + */ +export declare const GetPromptResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + description: z.ZodOptional; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const PromptListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/prompts/list_changed">; +}, z.core.$strip>; +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + */ +export declare const ToolAnnotationsSchema: z.ZodObject<{ + title: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; +}, z.core.$strip>; +/** + * Execution-related properties for a tool. + */ +export declare const ToolExecutionSchema: z.ZodObject<{ + taskSupport: z.ZodOptional>; +}, z.core.$strip>; +/** + * Definition for a tool the client can call. + */ +export declare const ToolSchema: z.ZodObject<{ + description: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of tools the server has. + */ +export declare const ListToolsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tools/list">; +}, z.core.$strip>; +/** + * The server's response to a tools/list request from the client. + */ +export declare const ListToolsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tools: z.ZodArray; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * The server's response to a tool call. + */ +export declare const CallToolResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>; +/** + * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. + */ +export declare const CompatibilityCallToolResultSchema: z.ZodUnion<[z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + toolResult: z.ZodUnknown; +}, z.core.$loose>]>; +/** + * Parameters for a `tools/call` request. + */ +export declare const CallToolRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; +}, z.core.$loose>; +/** + * Used by the client to invoke a tool provided by the server. + */ +export declare const CallToolRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tools/call">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const ToolListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/tools/list_changed">; +}, z.core.$strip>; +/** + * The severity of a log message. + */ +export declare const LoggingLevelSchema: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; +}>; +/** + * Parameters for a `logging/setLevel` request. + */ +export declare const SetLevelRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; +}, z.core.$loose>; +/** + * A request from the client to the server, to enable or adjust logging. + */ +export declare const SetLevelRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"logging/setLevel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/message` notification. + */ +export declare const LoggingMessageNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; +}, z.core.$loose>; +/** + * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + */ +export declare const LoggingMessageNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/message">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Hints to use for model selection. + */ +export declare const ModelHintSchema: z.ZodObject<{ + name: z.ZodOptional; +}, z.core.$strip>; +/** + * The server's preferences for model selection, requested of the client during sampling. + */ +export declare const ModelPreferencesSchema: z.ZodObject<{ + hints: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; +}, z.core.$strip>; +/** + * Controls tool usage behavior in sampling requests. + */ +export declare const ToolChoiceSchema: z.ZodObject<{ + mode: z.ZodOptional>; +}, z.core.$strip>; +/** + * The result of a tool execution, provided by the user (server). + * Represents the outcome of invoking a tool requested via ToolUseContent. + */ +export declare const ToolResultContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * Content block types allowed in sampling messages. + * This includes text, image, audio, tool use requests, and tool results. + */ +export declare const SamplingMessageContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ + type: z.ZodLiteral<"text">; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; +}, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$loose>]>; +/** + * Describes a message issued to or received from an LLM API. + */ +export declare const SamplingMessageSchema: z.ZodObject<{ + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * Parameters for a `sampling/createMessage` request. + */ +export declare const CreateMessageRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + */ +export declare const CreateMessageRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"sampling/createMessage">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + */ +export declare const CreateMessageResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + model: z.ZodString; + stopReason: z.ZodOptional, z.ZodString]>>; + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; +}, z.core.$loose>; +/** + * Primitive schema definition for boolean fields. + */ +export declare const BooleanSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Primitive schema definition for string fields. + */ +export declare const StringSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Primitive schema definition for number fields. + */ +export declare const NumberSchemaSchema: z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Schema for single-selection enumeration without display titles for options. + */ +export declare const UntitledSingleSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Schema for single-selection enumeration with display titles for each option. + */ +export declare const TitledSingleSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + */ +export declare const LegacyTitledEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>; +export declare const SingleSelectEnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>; +/** + * Schema for multiple-selection enumeration without display titles for options. + */ +export declare const UntitledMultiSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>; +/** + * Schema for multiple-selection enumeration with display titles for each option. + */ +export declare const TitledMultiSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>; +/** + * Combined schema for multiple-selection enumeration + */ +export declare const MultiSelectEnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>; +/** + * Primitive schema definition for enum fields. + */ +export declare const EnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>]>; +/** + * Union of all primitive schema definitions. + */ +export declare const PrimitiveSchemaDefinitionSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>]>; +/** + * Parameters for an `elicitation/create` request for form-based elicitation. + */ +export declare const ElicitRequestFormParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * Parameters for an `elicitation/create` request for URL-based elicitation. + */ +export declare const ElicitRequestURLParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; +}, z.core.$loose>; +/** + * The parameters for a request to elicit additional information from the user via the client. + */ +export declare const ElicitRequestParamsSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; +}, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; +}, z.core.$loose>]>; +/** + * A request from the server to elicit user input via the client. + * The client should present the message and form fields to the user (form mode) + * or navigate to a URL (URL mode). + */ +export declare const ElicitRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"elicitation/create">; + params: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; + }, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; + }, z.core.$loose>]>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/elicitation/complete` notification. + * + * @category notifications/elicitation/complete + */ +export declare const ElicitationCompleteNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; +}, z.core.$loose>; +/** + * A notification from the server to the client, informing it of a completion of an out-of-band elicitation request. + * + * @category notifications/elicitation/complete + */ +export declare const ElicitationCompleteNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/elicitation/complete">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The client's response to an elicitation/create request from the server. + */ +export declare const ElicitResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + action: z.ZodEnum<{ + cancel: "cancel"; + accept: "accept"; + decline: "decline"; + }>; + content: z.ZodOptional]>>>; +}, z.core.$loose>; +/** + * A reference to a resource or resource template definition. + */ +export declare const ResourceTemplateReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; +}, z.core.$strip>; +/** + * @deprecated Use ResourceTemplateReferenceSchema instead + */ +export declare const ResourceReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; +}, z.core.$strip>; +/** + * Identifies a prompt. + */ +export declare const PromptReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/prompt">; + name: z.ZodString; +}, z.core.$strip>; +/** + * Parameters for a `completion/complete` request. + */ +export declare const CompleteRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request from the client to the server, to ask for completion options. + */ +export declare const CompleteRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"completion/complete">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>; +export declare function assertCompleteRequestPrompt(request: CompleteRequest): asserts request is CompleteRequestPrompt; +export declare function assertCompleteRequestResourceTemplate(request: CompleteRequest): asserts request is CompleteRequestResourceTemplate; +/** + * The server's response to a completion/complete request + */ +export declare const CompleteResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + completion: z.ZodObject<{ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.ZodArray; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.ZodOptional; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$loose>; +/** + * Represents a root directory or file that the server can operate on. + */ +export declare const RootSchema: z.ZodObject<{ + uri: z.ZodString; + name: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * Sent from the server to request a list of root URIs from the client. + */ +export declare const ListRootsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"roots/list">; +}, z.core.$strip>; +/** + * The client's response to a roots/list request from the server. + */ +export declare const ListRootsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + roots: z.ZodArray; + _meta: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A notification from the client to the server, informing it that the list of roots has changed. + */ +export declare const RootsListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/roots/list_changed">; +}, z.core.$strip>; +export declare const ClientRequestSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"initialize">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"completion/complete">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"logging/setLevel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"prompts/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"prompts/list">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/list">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/templates/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/read">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/subscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/unsubscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tools/call">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tools/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>]>; +export declare const ClientNotificationSchema: z.ZodUnion; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/initialized">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/roots/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>]>; +export declare const ClientResultSchema: z.ZodUnion>; + }, z.core.$loose>>; +}, z.core.$strict>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + model: z.ZodString; + stopReason: z.ZodOptional, z.ZodString]>>; + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + action: z.ZodEnum<{ + cancel: "cancel"; + accept: "accept"; + decline: "decline"; + }>; + content: z.ZodOptional]>>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + roots: z.ZodArray; + _meta: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>]>; +export declare const ServerRequestSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"sampling/createMessage">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"elicitation/create">; + params: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; + }, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; + }, z.core.$loose>]>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"roots/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>]>; +export declare const ServerNotificationSchema: z.ZodUnion; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/message">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/resources/updated">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/resources/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/tools/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/prompts/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/elicitation/complete">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>]>; +export declare const ServerResultSchema: z.ZodUnion>; + }, z.core.$loose>>; +}, z.core.$strict>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>; + serverInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + instructions: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + completion: z.ZodObject<{ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.ZodArray; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.ZodOptional; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + description: z.ZodOptional; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + prompts: z.ZodArray; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resources: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resourceTemplates: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + contents: z.ZodArray; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tools: z.ZodArray; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>]>; +export declare class McpError extends Error { + readonly code: number; + readonly data?: unknown; + constructor(code: number, message: string, data?: unknown); + /** + * Factory method to create the appropriate error type based on the error code and data + */ + static fromError(code: number, message: string, data?: unknown): McpError; +} +/** + * Specialized error type when a tool requires a URL mode elicitation. + * This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against. + */ +export declare class UrlElicitationRequiredError extends McpError { + constructor(elicitations: ElicitRequestURLParams[], message?: string); + get elicitations(): ElicitRequestURLParams[]; +} +type Primitive = string | number | boolean | bigint | null | undefined; +type Flatten = T extends Primitive ? T : T extends Array ? Array> : T extends Set ? Set> : T extends Map ? Map, Flatten> : T extends object ? { + [K in keyof T]: Flatten; +} : T; +type Infer = Flatten>; +/** + * Headers that are compatible with both Node.js and the browser. + */ +export type IsomorphicHeaders = Record; +/** + * Information about the incoming request. + */ +export interface RequestInfo { + /** + * The headers of the request. + */ + headers: IsomorphicHeaders; +} +/** + * Extra information about a message. + */ +export interface MessageExtraInfo { + /** + * The request information. + */ + requestInfo?: RequestInfo; + /** + * The authentication information. + */ + authInfo?: AuthInfo; +} +export type ProgressToken = Infer; +export type Cursor = Infer; +export type Request = Infer; +export type RequestMeta = Infer; +export type Notification = Infer; +export type Result = Infer; +export type RequestId = Infer; +export type JSONRPCRequest = Infer; +export type JSONRPCNotification = Infer; +export type JSONRPCResponse = Infer; +export type JSONRPCError = Infer; +export type JSONRPCMessage = Infer; +export type RequestParams = Infer; +export type NotificationParams = Infer; +export type EmptyResult = Infer; +export type CancelledNotificationParams = Infer; +export type CancelledNotification = Infer; +export type Icon = Infer; +export type Icons = Infer; +export type BaseMetadata = Infer; +export type Implementation = Infer; +export type ClientCapabilities = Infer; +export type InitializeRequestParams = Infer; +export type InitializeRequest = Infer; +export type ServerCapabilities = Infer; +export type InitializeResult = Infer; +export type InitializedNotification = Infer; +export type PingRequest = Infer; +export type Progress = Infer; +export type ProgressNotificationParams = Infer; +export type ProgressNotification = Infer; +export type Task = Infer; +export type TaskCreationParams = Infer; +export type RelatedTaskMetadata = Infer; +export type CreateTaskResult = Infer; +export type TaskStatusNotificationParams = Infer; +export type TaskStatusNotification = Infer; +export type GetTaskRequest = Infer; +export type GetTaskResult = Infer; +export type GetTaskPayloadRequest = Infer; +export type ListTasksRequest = Infer; +export type ListTasksResult = Infer; +export type CancelTaskRequest = Infer; +export type CancelTaskResult = Infer; +export type PaginatedRequestParams = Infer; +export type PaginatedRequest = Infer; +export type PaginatedResult = Infer; +export type ResourceContents = Infer; +export type TextResourceContents = Infer; +export type BlobResourceContents = Infer; +export type Resource = Infer; +export type ResourceTemplate = Infer; +export type ListResourcesRequest = Infer; +export type ListResourcesResult = Infer; +export type ListResourceTemplatesRequest = Infer; +export type ListResourceTemplatesResult = Infer; +export type ResourceRequestParams = Infer; +export type ReadResourceRequestParams = Infer; +export type ReadResourceRequest = Infer; +export type ReadResourceResult = Infer; +export type ResourceListChangedNotification = Infer; +export type SubscribeRequestParams = Infer; +export type SubscribeRequest = Infer; +export type UnsubscribeRequestParams = Infer; +export type UnsubscribeRequest = Infer; +export type ResourceUpdatedNotificationParams = Infer; +export type ResourceUpdatedNotification = Infer; +export type PromptArgument = Infer; +export type Prompt = Infer; +export type ListPromptsRequest = Infer; +export type ListPromptsResult = Infer; +export type GetPromptRequestParams = Infer; +export type GetPromptRequest = Infer; +export type TextContent = Infer; +export type ImageContent = Infer; +export type AudioContent = Infer; +export type ToolUseContent = Infer; +export type ToolResultContent = Infer; +export type EmbeddedResource = Infer; +export type ResourceLink = Infer; +export type ContentBlock = Infer; +export type PromptMessage = Infer; +export type GetPromptResult = Infer; +export type PromptListChangedNotification = Infer; +export type ToolAnnotations = Infer; +export type ToolExecution = Infer; +export type Tool = Infer; +export type ListToolsRequest = Infer; +export type ListToolsResult = Infer; +export type CallToolRequestParams = Infer; +export type CallToolResult = Infer; +export type CompatibilityCallToolResult = Infer; +export type CallToolRequest = Infer; +export type ToolListChangedNotification = Infer; +export type LoggingLevel = Infer; +export type SetLevelRequestParams = Infer; +export type SetLevelRequest = Infer; +export type LoggingMessageNotificationParams = Infer; +export type LoggingMessageNotification = Infer; +export type ToolChoice = Infer; +export type ModelHint = Infer; +export type ModelPreferences = Infer; +export type SamplingMessageContentBlock = Infer; +export type SamplingMessage = Infer; +export type CreateMessageRequestParams = Infer; +export type CreateMessageRequest = Infer; +export type CreateMessageResult = Infer; +export type BooleanSchema = Infer; +export type StringSchema = Infer; +export type NumberSchema = Infer; +export type EnumSchema = Infer; +export type UntitledSingleSelectEnumSchema = Infer; +export type TitledSingleSelectEnumSchema = Infer; +export type LegacyTitledEnumSchema = Infer; +export type UntitledMultiSelectEnumSchema = Infer; +export type TitledMultiSelectEnumSchema = Infer; +export type SingleSelectEnumSchema = Infer; +export type MultiSelectEnumSchema = Infer; +export type PrimitiveSchemaDefinition = Infer; +export type ElicitRequestParams = Infer; +export type ElicitRequestFormParams = Infer; +export type ElicitRequestURLParams = Infer; +export type ElicitRequest = Infer; +export type ElicitationCompleteNotificationParams = Infer; +export type ElicitationCompleteNotification = Infer; +export type ElicitResult = Infer; +export type ResourceTemplateReference = Infer; +/** + * @deprecated Use ResourceTemplateReference instead + */ +export type ResourceReference = ResourceTemplateReference; +export type PromptReference = Infer; +export type CompleteRequestParams = Infer; +export type CompleteRequest = Infer; +export type CompleteRequestResourceTemplate = ExpandRecursively; +export type CompleteRequestPrompt = ExpandRecursively; +export type CompleteResult = Infer; +export type Root = Infer; +export type ListRootsRequest = Infer; +export type ListRootsResult = Infer; +export type RootsListChangedNotification = Infer; +export type ClientRequest = Infer; +export type ClientNotification = Infer; +export type ClientResult = Infer; +export type ServerRequest = Infer; +export type ServerNotification = Infer; +export type ServerResult = Infer; +export {}; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/cjs/types.d.ts.map b/dist/cjs/types.d.ts.map new file mode 100644 index 000000000..9ddeea1d0 --- /dev/null +++ b/dist/cjs/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,eAAO,MAAM,uBAAuB,eAAe,CAAC;AACpD,eAAO,MAAM,mCAAmC,eAAe,CAAC;AAChE,eAAO,MAAM,2BAA2B,UAAsE,CAAC;AAE/G,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAG5E,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC;;GAEG;AACH,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE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,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,eAAe,GAAG;IAAE,MAAM,EAAE,qBAAqB,GAAG;QAAE,GAAG,EAAE,eAAe,CAAA;KAAE,CAAA;CAAE,CAAC,CAAC;AACtI,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAGhE,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAC5C,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClE,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAG5F,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAG5D,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/types.js b/dist/cjs/types.js new file mode 100644 index 000000000..d47858965 --- /dev/null +++ b/dist/cjs/types.js @@ -0,0 +1,1924 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TaskStatusNotificationParamsSchema = exports.CreateTaskResultSchema = exports.TaskSchema = exports.PaginatedResultSchema = exports.PaginatedRequestSchema = exports.PaginatedRequestParamsSchema = exports.ProgressNotificationSchema = exports.ProgressNotificationParamsSchema = exports.ProgressSchema = exports.PingRequestSchema = exports.isInitializedNotification = exports.InitializedNotificationSchema = exports.InitializeResultSchema = exports.ServerCapabilitiesSchema = exports.isInitializeRequest = exports.InitializeRequestSchema = exports.InitializeRequestParamsSchema = exports.ClientCapabilitiesSchema = exports.ServerTasksCapabilitySchema = exports.ClientTasksCapabilitySchema = exports.ImplementationSchema = exports.BaseMetadataSchema = exports.IconsSchema = exports.IconSchema = exports.CancelledNotificationSchema = exports.CancelledNotificationParamsSchema = exports.EmptyResultSchema = exports.JSONRPCMessageSchema = exports.isJSONRPCError = exports.JSONRPCErrorSchema = exports.ErrorCode = exports.isJSONRPCResponse = exports.JSONRPCResponseSchema = exports.isJSONRPCNotification = exports.JSONRPCNotificationSchema = exports.isJSONRPCRequest = exports.JSONRPCRequestSchema = exports.RequestIdSchema = exports.ResultSchema = exports.NotificationSchema = exports.RequestSchema = exports.RelatedTaskMetadataSchema = exports.TaskCreationParamsSchema = exports.CursorSchema = exports.ProgressTokenSchema = exports.JSONRPC_VERSION = exports.RELATED_TASK_META_KEY = exports.SUPPORTED_PROTOCOL_VERSIONS = exports.DEFAULT_NEGOTIATED_PROTOCOL_VERSION = exports.LATEST_PROTOCOL_VERSION = void 0; +exports.CallToolResultSchema = exports.ListToolsResultSchema = exports.ListToolsRequestSchema = exports.ToolSchema = exports.ToolExecutionSchema = exports.ToolAnnotationsSchema = exports.PromptListChangedNotificationSchema = exports.GetPromptResultSchema = exports.PromptMessageSchema = exports.ContentBlockSchema = exports.ResourceLinkSchema = exports.EmbeddedResourceSchema = exports.ToolUseContentSchema = exports.AudioContentSchema = exports.ImageContentSchema = exports.TextContentSchema = exports.GetPromptRequestSchema = exports.GetPromptRequestParamsSchema = exports.ListPromptsResultSchema = exports.ListPromptsRequestSchema = exports.PromptSchema = exports.PromptArgumentSchema = exports.ResourceUpdatedNotificationSchema = exports.ResourceUpdatedNotificationParamsSchema = exports.UnsubscribeRequestSchema = exports.UnsubscribeRequestParamsSchema = exports.SubscribeRequestSchema = exports.SubscribeRequestParamsSchema = exports.ResourceListChangedNotificationSchema = exports.ReadResourceResultSchema = exports.ReadResourceRequestSchema = exports.ReadResourceRequestParamsSchema = exports.ResourceRequestParamsSchema = exports.ListResourceTemplatesResultSchema = exports.ListResourceTemplatesRequestSchema = exports.ListResourcesResultSchema = exports.ListResourcesRequestSchema = exports.ResourceTemplateSchema = exports.ResourceSchema = exports.BlobResourceContentsSchema = exports.TextResourceContentsSchema = exports.ResourceContentsSchema = exports.CancelTaskResultSchema = exports.CancelTaskRequestSchema = exports.ListTasksResultSchema = exports.ListTasksRequestSchema = exports.GetTaskPayloadRequestSchema = exports.GetTaskResultSchema = exports.GetTaskRequestSchema = exports.TaskStatusNotificationSchema = void 0; +exports.ClientResultSchema = exports.ClientNotificationSchema = exports.ClientRequestSchema = exports.RootsListChangedNotificationSchema = exports.ListRootsResultSchema = exports.ListRootsRequestSchema = exports.RootSchema = exports.CompleteResultSchema = exports.CompleteRequestSchema = exports.CompleteRequestParamsSchema = exports.PromptReferenceSchema = exports.ResourceReferenceSchema = exports.ResourceTemplateReferenceSchema = exports.ElicitResultSchema = exports.ElicitationCompleteNotificationSchema = exports.ElicitationCompleteNotificationParamsSchema = exports.ElicitRequestSchema = exports.ElicitRequestParamsSchema = exports.ElicitRequestURLParamsSchema = exports.ElicitRequestFormParamsSchema = exports.PrimitiveSchemaDefinitionSchema = exports.EnumSchemaSchema = exports.MultiSelectEnumSchemaSchema = exports.TitledMultiSelectEnumSchemaSchema = exports.UntitledMultiSelectEnumSchemaSchema = exports.SingleSelectEnumSchemaSchema = exports.LegacyTitledEnumSchemaSchema = exports.TitledSingleSelectEnumSchemaSchema = exports.UntitledSingleSelectEnumSchemaSchema = exports.NumberSchemaSchema = exports.StringSchemaSchema = exports.BooleanSchemaSchema = exports.CreateMessageResultSchema = exports.CreateMessageRequestSchema = exports.CreateMessageRequestParamsSchema = exports.SamplingMessageSchema = exports.SamplingMessageContentBlockSchema = exports.ToolResultContentSchema = exports.ToolChoiceSchema = exports.ModelPreferencesSchema = exports.ModelHintSchema = exports.LoggingMessageNotificationSchema = exports.LoggingMessageNotificationParamsSchema = exports.SetLevelRequestSchema = exports.SetLevelRequestParamsSchema = exports.LoggingLevelSchema = exports.ToolListChangedNotificationSchema = exports.CallToolRequestSchema = exports.CallToolRequestParamsSchema = exports.CompatibilityCallToolResultSchema = void 0; +exports.UrlElicitationRequiredError = exports.McpError = exports.ServerResultSchema = exports.ServerNotificationSchema = exports.ServerRequestSchema = void 0; +exports.assertCompleteRequestPrompt = assertCompleteRequestPrompt; +exports.assertCompleteRequestResourceTemplate = assertCompleteRequestResourceTemplate; +const z = __importStar(require("zod/v4")); +exports.LATEST_PROTOCOL_VERSION = '2025-06-18'; +exports.DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26'; +exports.SUPPORTED_PROTOCOL_VERSIONS = [exports.LATEST_PROTOCOL_VERSION, '2025-03-26', '2024-11-05', '2024-10-07']; +exports.RELATED_TASK_META_KEY = 'io.modelcontextprotocol/related-task'; +/* JSON-RPC types */ +exports.JSONRPC_VERSION = '2.0'; +/** + * Assert 'object' type schema. + * + * @internal + */ +const AssertObjectSchema = z.custom((v) => v !== null && (typeof v === 'object' || typeof v === 'function')); +/** + * A progress token, used to associate progress notifications with the original request. + */ +exports.ProgressTokenSchema = z.union([z.string(), z.number().int()]); +/** + * An opaque token used to represent a cursor for pagination. + */ +exports.CursorSchema = z.string(); +/** + * Task creation parameters, used to ask that the server create a task to represent a request. + */ +exports.TaskCreationParamsSchema = z.looseObject({ + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.union([z.number(), z.null()]).optional(), + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.number().optional() +}); +/** + * Task association metadata, used to signal which task a message originated from. + */ +exports.RelatedTaskMetadataSchema = z.looseObject({ + taskId: z.string() +}); +const RequestMetaSchema = z.looseObject({ + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken: exports.ProgressTokenSchema.optional(), + /** + * If specified, this request is related to the provided task. + */ + [exports.RELATED_TASK_META_KEY]: exports.RelatedTaskMetadataSchema.optional() +}); +/** + * Common params for any request. + */ +const BaseRequestParamsSchema = z.looseObject({ + /** + * If specified, the caller is requesting that the receiver create a task to represent the request. + * Task creation parameters are now at the top level instead of in _meta. + */ + task: exports.TaskCreationParamsSchema.optional(), + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: RequestMetaSchema.optional() +}); +exports.RequestSchema = z.object({ + method: z.string(), + params: BaseRequestParamsSchema.optional() +}); +const NotificationsParamsSchema = z.looseObject({ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z + .object({ + /** + * If specified, this notification is related to the provided task. + */ + [exports.RELATED_TASK_META_KEY]: z.optional(exports.RelatedTaskMetadataSchema) + }) + .passthrough() + .optional() +}); +exports.NotificationSchema = z.object({ + method: z.string(), + params: NotificationsParamsSchema.optional() +}); +exports.ResultSchema = z.looseObject({ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z + .looseObject({ + /** + * If specified, this result is related to the provided task. + */ + [exports.RELATED_TASK_META_KEY]: exports.RelatedTaskMetadataSchema.optional() + }) + .optional() +}); +/** + * A uniquely identifying ID for a request in JSON-RPC. + */ +exports.RequestIdSchema = z.union([z.string(), z.number().int()]); +/** + * A request that expects a response. + */ +exports.JSONRPCRequestSchema = z + .object({ + jsonrpc: z.literal(exports.JSONRPC_VERSION), + id: exports.RequestIdSchema, + ...exports.RequestSchema.shape +}) + .strict(); +const isJSONRPCRequest = (value) => exports.JSONRPCRequestSchema.safeParse(value).success; +exports.isJSONRPCRequest = isJSONRPCRequest; +/** + * A notification which does not expect a response. + */ +exports.JSONRPCNotificationSchema = z + .object({ + jsonrpc: z.literal(exports.JSONRPC_VERSION), + ...exports.NotificationSchema.shape +}) + .strict(); +const isJSONRPCNotification = (value) => exports.JSONRPCNotificationSchema.safeParse(value).success; +exports.isJSONRPCNotification = isJSONRPCNotification; +/** + * A successful (non-error) response to a request. + */ +exports.JSONRPCResponseSchema = z + .object({ + jsonrpc: z.literal(exports.JSONRPC_VERSION), + id: exports.RequestIdSchema, + result: exports.ResultSchema +}) + .strict(); +const isJSONRPCResponse = (value) => exports.JSONRPCResponseSchema.safeParse(value).success; +exports.isJSONRPCResponse = isJSONRPCResponse; +/** + * Error codes defined by the JSON-RPC specification. + */ +var ErrorCode; +(function (ErrorCode) { + // SDK error codes + ErrorCode[ErrorCode["ConnectionClosed"] = -32000] = "ConnectionClosed"; + ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout"; + // Standard JSON-RPC error codes + ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError"; + ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest"; + ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound"; + ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams"; + ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError"; + // MCP-specific error codes + ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired"; +})(ErrorCode || (exports.ErrorCode = ErrorCode = {})); +/** + * A response to a request that indicates an error occurred. + */ +exports.JSONRPCErrorSchema = z + .object({ + jsonrpc: z.literal(exports.JSONRPC_VERSION), + id: exports.RequestIdSchema, + error: z.object({ + /** + * The error type that occurred. + */ + code: z.number().int(), + /** + * A short description of the error. The message SHOULD be limited to a concise single sentence. + */ + message: z.string(), + /** + * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). + */ + data: z.optional(z.unknown()) + }) +}) + .strict(); +const isJSONRPCError = (value) => exports.JSONRPCErrorSchema.safeParse(value).success; +exports.isJSONRPCError = isJSONRPCError; +exports.JSONRPCMessageSchema = z.union([exports.JSONRPCRequestSchema, exports.JSONRPCNotificationSchema, exports.JSONRPCResponseSchema, exports.JSONRPCErrorSchema]); +/* Empty result */ +/** + * A response that indicates success but carries no data. + */ +exports.EmptyResultSchema = exports.ResultSchema.strict(); +exports.CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The ID of the request to cancel. + * + * This MUST correspond to the ID of a request previously issued in the same direction. + */ + requestId: exports.RequestIdSchema, + /** + * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. + */ + reason: z.string().optional() +}); +/* Cancellation */ +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + */ +exports.CancelledNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/cancelled'), + params: exports.CancelledNotificationParamsSchema +}); +/* Base Metadata */ +/** + * Icon schema for use in tools, prompts, resources, and implementations. + */ +exports.IconSchema = z.object({ + /** + * URL or data URI for the icon. + */ + src: z.string(), + /** + * Optional MIME type for the icon. + */ + mimeType: z.string().optional(), + /** + * Optional array of strings that specify sizes at which the icon can be used. + * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. + * + * If not provided, the client should assume that the icon can be used at any size. + */ + sizes: z.array(z.string()).optional() +}); +/** + * Base schema to add `icons` property. + * + */ +exports.IconsSchema = z.object({ + /** + * Optional set of sized icons that the client can display in a user interface. + * + * Clients that support rendering icons MUST support at least the following MIME types: + * - `image/png` - PNG images (safe, universal compatibility) + * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) + * + * Clients that support rendering icons SHOULD also support: + * - `image/svg+xml` - SVG images (scalable but requires security precautions) + * - `image/webp` - WebP images (modern, efficient format) + */ + icons: z.array(exports.IconSchema).optional() +}); +/** + * Base metadata interface for common properties across resources, tools, prompts, and implementations. + */ +exports.BaseMetadataSchema = z.object({ + /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ + name: z.string(), + /** + * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, + * even by those unfamiliar with domain-specific terminology. + * + * If not provided, the name should be used for display (except for Tool, + * where `annotations.title` should be given precedence over using `name`, + * if present). + */ + title: z.string().optional() +}); +/* Initialization */ +/** + * Describes the name and version of an MCP implementation. + */ +exports.ImplementationSchema = exports.BaseMetadataSchema.extend({ + ...exports.BaseMetadataSchema.shape, + ...exports.IconsSchema.shape, + version: z.string(), + /** + * An optional URL of the website for this implementation. + */ + websiteUrl: z.string().optional() +}); +const FormElicitationCapabilitySchema = z.intersection(z.object({ + applyDefaults: z.boolean().optional() +}), z.record(z.string(), z.unknown())); +const ElicitationCapabilitySchema = z.preprocess(value => { + if (value && typeof value === 'object' && !Array.isArray(value)) { + if (Object.keys(value).length === 0) { + return { form: {} }; + } + } + return value; +}, z.intersection(z.object({ + form: FormElicitationCapabilitySchema.optional(), + url: AssertObjectSchema.optional() +}), z.record(z.string(), z.unknown()).optional())); +/** + * Task capabilities for clients, indicating which request types support task creation. + */ +exports.ClientTasksCapabilitySchema = z + .object({ + /** + * Present if the client supports listing tasks. + */ + list: z.optional(z.object({}).passthrough()), + /** + * Present if the client supports cancelling tasks. + */ + cancel: z.optional(z.object({}).passthrough()), + /** + * Capabilities for task creation on specific request types. + */ + requests: z.optional(z + .object({ + /** + * Task support for sampling requests. + */ + sampling: z.optional(z + .object({ + createMessage: z.optional(z.object({}).passthrough()) + }) + .passthrough()), + /** + * Task support for elicitation requests. + */ + elicitation: z.optional(z + .object({ + create: z.optional(z.object({}).passthrough()) + }) + .passthrough()) + }) + .passthrough()) +}) + .passthrough(); +/** + * Task capabilities for servers, indicating which request types support task creation. + */ +exports.ServerTasksCapabilitySchema = z + .object({ + /** + * Present if the server supports listing tasks. + */ + list: z.optional(z.object({}).passthrough()), + /** + * Present if the server supports cancelling tasks. + */ + cancel: z.optional(z.object({}).passthrough()), + /** + * Capabilities for task creation on specific request types. + */ + requests: z.optional(z + .object({ + /** + * Task support for tool requests. + */ + tools: z.optional(z + .object({ + call: z.optional(z.object({}).passthrough()) + }) + .passthrough()) + }) + .passthrough()) +}) + .passthrough(); +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + */ +exports.ClientCapabilitiesSchema = z.object({ + /** + * Experimental, non-standard capabilities that the client supports. + */ + experimental: z.record(z.string(), AssertObjectSchema).optional(), + /** + * Present if the client supports sampling from an LLM. + */ + sampling: z + .object({ + /** + * Present if the client supports context inclusion via includeContext parameter. + * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it). + */ + context: AssertObjectSchema.optional(), + /** + * Present if the client supports tool use via tools and toolChoice parameters. + */ + tools: AssertObjectSchema.optional() + }) + .optional(), + /** + * Present if the client supports eliciting user input. + */ + elicitation: ElicitationCapabilitySchema.optional(), + /** + * Present if the client supports listing roots. + */ + roots: z + .object({ + /** + * Whether the client supports issuing notifications for changes to the roots list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the client supports task creation. + */ + tasks: z.optional(exports.ClientTasksCapabilitySchema) +}); +exports.InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. + */ + protocolVersion: z.string(), + capabilities: exports.ClientCapabilitiesSchema, + clientInfo: exports.ImplementationSchema +}); +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + */ +exports.InitializeRequestSchema = exports.RequestSchema.extend({ + method: z.literal('initialize'), + params: exports.InitializeRequestParamsSchema +}); +const isInitializeRequest = (value) => exports.InitializeRequestSchema.safeParse(value).success; +exports.isInitializeRequest = isInitializeRequest; +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + */ +exports.ServerCapabilitiesSchema = z + .object({ + /** + * Experimental, non-standard capabilities that the server supports. + */ + experimental: z.record(z.string(), AssertObjectSchema).optional(), + /** + * Present if the server supports sending log messages to the client. + */ + logging: AssertObjectSchema.optional(), + /** + * Present if the server supports sending completions to the client. + */ + completions: AssertObjectSchema.optional(), + /** + * Present if the server offers any prompt templates. + */ + prompts: z.optional(z.object({ + /** + * Whether this server supports issuing notifications for changes to the prompt list. + */ + listChanged: z.optional(z.boolean()) + })), + /** + * Present if the server offers any resources to read. + */ + resources: z + .object({ + /** + * Whether this server supports clients subscribing to resource updates. + */ + subscribe: z.boolean().optional(), + /** + * Whether this server supports issuing notifications for changes to the resource list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the server offers any tools to call. + */ + tools: z + .object({ + /** + * Whether this server supports issuing notifications for changes to the tool list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the server supports task creation. + */ + tasks: z.optional(exports.ServerTasksCapabilitySchema) +}) + .passthrough(); +/** + * After receiving an initialize request from the client, the server sends this response. + */ +exports.InitializeResultSchema = exports.ResultSchema.extend({ + /** + * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. + */ + protocolVersion: z.string(), + capabilities: exports.ServerCapabilitiesSchema, + serverInfo: exports.ImplementationSchema, + /** + * Instructions describing how to use the server and its features. + * + * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. + */ + instructions: z.string().optional() +}); +/** + * This notification is sent from the client to the server after initialization has finished. + */ +exports.InitializedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/initialized') +}); +const isInitializedNotification = (value) => exports.InitializedNotificationSchema.safeParse(value).success; +exports.isInitializedNotification = isInitializedNotification; +/* Ping */ +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + */ +exports.PingRequestSchema = exports.RequestSchema.extend({ + method: z.literal('ping') +}); +/* Progress notifications */ +exports.ProgressSchema = z.object({ + /** + * The progress thus far. This should increase every time progress is made, even if the total is unknown. + */ + progress: z.number(), + /** + * Total number of items to process (or total progress required), if known. + */ + total: z.optional(z.number()), + /** + * An optional message describing the current progress. + */ + message: z.optional(z.string()) +}); +exports.ProgressNotificationParamsSchema = z.object({ + ...NotificationsParamsSchema.shape, + ...exports.ProgressSchema.shape, + /** + * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding. + */ + progressToken: exports.ProgressTokenSchema +}); +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category notifications/progress + */ +exports.ProgressNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/progress'), + params: exports.ProgressNotificationParamsSchema +}); +exports.PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * An opaque token representing the current pagination position. + * If provided, the server should return results starting after this cursor. + */ + cursor: exports.CursorSchema.optional() +}); +/* Pagination */ +exports.PaginatedRequestSchema = exports.RequestSchema.extend({ + params: exports.PaginatedRequestParamsSchema.optional() +}); +exports.PaginatedResultSchema = exports.ResultSchema.extend({ + /** + * An opaque token representing the pagination position after the last returned result. + * If present, there may be more results available. + */ + nextCursor: z.optional(exports.CursorSchema) +}); +/* Tasks */ +/** + * A pollable state object associated with a request. + */ +exports.TaskSchema = z.object({ + taskId: z.string(), + status: z.enum(['working', 'input_required', 'completed', 'failed', 'cancelled']), + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.union([z.number(), z.null()]), + /** + * ISO 8601 timestamp when the task was created. + */ + createdAt: z.string(), + /** + * ISO 8601 timestamp when the task was last updated. + */ + lastUpdatedAt: z.string(), + pollInterval: z.optional(z.number()), + /** + * Optional diagnostic message for failed tasks or other status information. + */ + statusMessage: z.optional(z.string()) +}); +/** + * Result returned when a task is created, containing the task data wrapped in a task field. + */ +exports.CreateTaskResultSchema = exports.ResultSchema.extend({ + task: exports.TaskSchema +}); +/** + * Parameters for task status notification. + */ +exports.TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(exports.TaskSchema); +/** + * A notification sent when a task's status changes. + */ +exports.TaskStatusNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/tasks/status'), + params: exports.TaskStatusNotificationParamsSchema +}); +/** + * A request to get the state of a specific task. + */ +exports.GetTaskRequestSchema = exports.RequestSchema.extend({ + method: z.literal('tasks/get'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * The response to a tasks/get request. + */ +exports.GetTaskResultSchema = exports.ResultSchema.merge(exports.TaskSchema); +/** + * A request to get the result of a specific task. + */ +exports.GetTaskPayloadRequestSchema = exports.RequestSchema.extend({ + method: z.literal('tasks/result'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * A request to list tasks. + */ +exports.ListTasksRequestSchema = exports.PaginatedRequestSchema.extend({ + method: z.literal('tasks/list') +}); +/** + * The response to a tasks/list request. + */ +exports.ListTasksResultSchema = exports.PaginatedResultSchema.extend({ + tasks: z.array(exports.TaskSchema) +}); +/** + * A request to cancel a specific task. + */ +exports.CancelTaskRequestSchema = exports.RequestSchema.extend({ + method: z.literal('tasks/cancel'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * The response to a tasks/cancel request. + */ +exports.CancelTaskResultSchema = exports.ResultSchema.merge(exports.TaskSchema); +/* Resources */ +/** + * The contents of a specific resource or sub-resource. + */ +exports.ResourceContentsSchema = z.object({ + /** + * The URI of this resource. + */ + uri: z.string(), + /** + * The MIME type of this resource, if known. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +exports.TextResourceContentsSchema = exports.ResourceContentsSchema.extend({ + /** + * The text of the item. This must only be set if the item can actually be represented as text (not binary data). + */ + text: z.string() +}); +/** + * A Zod schema for validating Base64 strings that is more performant and + * robust for very large inputs than the default regex-based check. It avoids + * stack overflows by using the native `atob` function for validation. + */ +const Base64Schema = z.string().refine(val => { + try { + // atob throws a DOMException if the string contains characters + // that are not part of the Base64 character set. + atob(val); + return true; + } + catch (_a) { + return false; + } +}, { message: 'Invalid Base64 string' }); +exports.BlobResourceContentsSchema = exports.ResourceContentsSchema.extend({ + /** + * A base64-encoded string representing the binary data of the item. + */ + blob: Base64Schema +}); +/** + * A known resource that the server is capable of reading. + */ +exports.ResourceSchema = z.object({ + ...exports.BaseMetadataSchema.shape, + ...exports.IconsSchema.shape, + /** + * The URI of this resource. + */ + uri: z.string(), + /** + * A description of what this resource represents. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description: z.optional(z.string()), + /** + * The MIME type of this resource, if known. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * A template description for resources available on the server. + */ +exports.ResourceTemplateSchema = z.object({ + ...exports.BaseMetadataSchema.shape, + ...exports.IconsSchema.shape, + /** + * A URI template (according to RFC 6570) that can be used to construct resource URIs. + */ + uriTemplate: z.string(), + /** + * A description of what this template is for. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description: z.optional(z.string()), + /** + * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * Sent from the client to request a list of resources the server has. + */ +exports.ListResourcesRequestSchema = exports.PaginatedRequestSchema.extend({ + method: z.literal('resources/list') +}); +/** + * The server's response to a resources/list request from the client. + */ +exports.ListResourcesResultSchema = exports.PaginatedResultSchema.extend({ + resources: z.array(exports.ResourceSchema) +}); +/** + * Sent from the client to request a list of resource templates the server has. + */ +exports.ListResourceTemplatesRequestSchema = exports.PaginatedRequestSchema.extend({ + method: z.literal('resources/templates/list') +}); +/** + * The server's response to a resources/templates/list request from the client. + */ +exports.ListResourceTemplatesResultSchema = exports.PaginatedResultSchema.extend({ + resourceTemplates: z.array(exports.ResourceTemplateSchema) +}); +exports.ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it. + * + * @format uri + */ + uri: z.string() +}); +/** + * Parameters for a `resources/read` request. + */ +exports.ReadResourceRequestParamsSchema = exports.ResourceRequestParamsSchema; +/** + * Sent from the client to the server, to read a specific resource URI. + */ +exports.ReadResourceRequestSchema = exports.RequestSchema.extend({ + method: z.literal('resources/read'), + params: exports.ReadResourceRequestParamsSchema +}); +/** + * The server's response to a resources/read request from the client. + */ +exports.ReadResourceResultSchema = exports.ResultSchema.extend({ + contents: z.array(z.union([exports.TextResourceContentsSchema, exports.BlobResourceContentsSchema])) +}); +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + */ +exports.ResourceListChangedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/resources/list_changed') +}); +exports.SubscribeRequestParamsSchema = exports.ResourceRequestParamsSchema; +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + */ +exports.SubscribeRequestSchema = exports.RequestSchema.extend({ + method: z.literal('resources/subscribe'), + params: exports.SubscribeRequestParamsSchema +}); +exports.UnsubscribeRequestParamsSchema = exports.ResourceRequestParamsSchema; +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + */ +exports.UnsubscribeRequestSchema = exports.RequestSchema.extend({ + method: z.literal('resources/unsubscribe'), + params: exports.UnsubscribeRequestParamsSchema +}); +/** + * Parameters for a `notifications/resources/updated` notification. + */ +exports.ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. + */ + uri: z.string() +}); +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + */ +exports.ResourceUpdatedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/resources/updated'), + params: exports.ResourceUpdatedNotificationParamsSchema +}); +/* Prompts */ +/** + * Describes an argument that a prompt can accept. + */ +exports.PromptArgumentSchema = z.object({ + /** + * The name of the argument. + */ + name: z.string(), + /** + * A human-readable description of the argument. + */ + description: z.optional(z.string()), + /** + * Whether this argument must be provided. + */ + required: z.optional(z.boolean()) +}); +/** + * A prompt or prompt template that the server offers. + */ +exports.PromptSchema = z.object({ + ...exports.BaseMetadataSchema.shape, + ...exports.IconsSchema.shape, + /** + * An optional description of what this prompt provides + */ + description: z.optional(z.string()), + /** + * A list of arguments to use for templating the prompt. + */ + arguments: z.optional(z.array(exports.PromptArgumentSchema)), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + */ +exports.ListPromptsRequestSchema = exports.PaginatedRequestSchema.extend({ + method: z.literal('prompts/list') +}); +/** + * The server's response to a prompts/list request from the client. + */ +exports.ListPromptsResultSchema = exports.PaginatedResultSchema.extend({ + prompts: z.array(exports.PromptSchema) +}); +/** + * Parameters for a `prompts/get` request. + */ +exports.GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The name of the prompt or prompt template. + */ + name: z.string(), + /** + * Arguments to use for templating the prompt. + */ + arguments: z.record(z.string(), z.string()).optional() +}); +/** + * Used by the client to get a prompt provided by the server. + */ +exports.GetPromptRequestSchema = exports.RequestSchema.extend({ + method: z.literal('prompts/get'), + params: exports.GetPromptRequestParamsSchema +}); +/** + * Text provided to or from an LLM. + */ +exports.TextContentSchema = z.object({ + type: z.literal('text'), + /** + * The text content of the message. + */ + text: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * An image provided to or from an LLM. + */ +exports.ImageContentSchema = z.object({ + type: z.literal('image'), + /** + * The base64-encoded image data. + */ + data: Base64Schema, + /** + * The MIME type of the image. Different providers may support different image types. + */ + mimeType: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * An Audio provided to or from an LLM. + */ +exports.AudioContentSchema = z.object({ + type: z.literal('audio'), + /** + * The base64-encoded audio data. + */ + data: Base64Schema, + /** + * The MIME type of the audio. Different providers may support different audio types. + */ + mimeType: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * A tool call request from an assistant (LLM). + * Represents the assistant's request to use a tool. + */ +exports.ToolUseContentSchema = z + .object({ + type: z.literal('tool_use'), + /** + * The name of the tool to invoke. + * Must match a tool name from the request's tools array. + */ + name: z.string(), + /** + * Unique identifier for this tool call. + * Used to correlate with ToolResultContent in subsequent messages. + */ + id: z.string(), + /** + * Arguments to pass to the tool. + * Must conform to the tool's inputSchema. + */ + input: z.object({}).passthrough(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * The contents of a resource, embedded into a prompt or tool call result. + */ +exports.EmbeddedResourceSchema = z.object({ + type: z.literal('resource'), + resource: z.union([exports.TextResourceContentsSchema, exports.BlobResourceContentsSchema]), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + */ +exports.ResourceLinkSchema = exports.ResourceSchema.extend({ + type: z.literal('resource_link') +}); +/** + * A content block that can be used in prompts and tool results. + */ +exports.ContentBlockSchema = z.union([ + exports.TextContentSchema, + exports.ImageContentSchema, + exports.AudioContentSchema, + exports.ResourceLinkSchema, + exports.EmbeddedResourceSchema +]); +/** + * Describes a message returned as part of a prompt. + */ +exports.PromptMessageSchema = z.object({ + role: z.enum(['user', 'assistant']), + content: exports.ContentBlockSchema +}); +/** + * The server's response to a prompts/get request from the client. + */ +exports.GetPromptResultSchema = exports.ResultSchema.extend({ + /** + * An optional description for the prompt. + */ + description: z.optional(z.string()), + messages: z.array(exports.PromptMessageSchema) +}); +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +exports.PromptListChangedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/prompts/list_changed') +}); +/* Tools */ +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + */ +exports.ToolAnnotationsSchema = z.object({ + /** + * A human-readable title for the tool. + */ + title: z.string().optional(), + /** + * If true, the tool does not modify its environment. + * + * Default: false + */ + readOnlyHint: z.boolean().optional(), + /** + * If true, the tool may perform destructive updates to its environment. + * If false, the tool performs only additive updates. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: true + */ + destructiveHint: z.boolean().optional(), + /** + * If true, calling the tool repeatedly with the same arguments + * will have no additional effect on the its environment. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: false + */ + idempotentHint: z.boolean().optional(), + /** + * If true, this tool may interact with an "open world" of external + * entities. If false, the tool's domain of interaction is closed. + * For example, the world of a web search tool is open, whereas that + * of a memory tool is not. + * + * Default: true + */ + openWorldHint: z.boolean().optional() +}); +/** + * Execution-related properties for a tool. + */ +exports.ToolExecutionSchema = z.object({ + /** + * Indicates the tool's preference for task-augmented execution. + * - "required": Clients MUST invoke the tool as a task + * - "optional": Clients MAY invoke the tool as a task or normal request + * - "forbidden": Clients MUST NOT attempt to invoke the tool as a task + * + * If not present, defaults to "forbidden". + */ + taskSupport: z.enum(['required', 'optional', 'forbidden']).optional() +}); +/** + * Definition for a tool the client can call. + */ +exports.ToolSchema = z.object({ + ...exports.BaseMetadataSchema.shape, + ...exports.IconsSchema.shape, + /** + * A human-readable description of the tool. + */ + description: z.string().optional(), + /** + * A JSON Schema 2020-12 object defining the expected parameters for the tool. + * Must have type: 'object' at the root level per MCP spec. + */ + inputSchema: z + .object({ + type: z.literal('object'), + properties: z.record(z.string(), AssertObjectSchema).optional(), + required: z.array(z.string()).optional() + }) + .catchall(z.unknown()), + /** + * An optional JSON Schema 2020-12 object defining the structure of the tool's output + * returned in the structuredContent field of a CallToolResult. + * Must have type: 'object' at the root level per MCP spec. + */ + outputSchema: z + .object({ + type: z.literal('object'), + properties: z.record(z.string(), AssertObjectSchema).optional(), + required: z.array(z.string()).optional() + }) + .catchall(z.unknown()) + .optional(), + /** + * Optional additional tool information. + */ + annotations: z.optional(exports.ToolAnnotationsSchema), + /** + * Execution-related properties for this tool. + */ + execution: z.optional(exports.ToolExecutionSchema), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * Sent from the client to request a list of tools the server has. + */ +exports.ListToolsRequestSchema = exports.PaginatedRequestSchema.extend({ + method: z.literal('tools/list') +}); +/** + * The server's response to a tools/list request from the client. + */ +exports.ListToolsResultSchema = exports.PaginatedResultSchema.extend({ + tools: z.array(exports.ToolSchema) +}); +/** + * The server's response to a tool call. + */ +exports.CallToolResultSchema = exports.ResultSchema.extend({ + /** + * A list of content objects that represent the result of the tool call. + * + * If the Tool does not define an outputSchema, this field MUST be present in the result. + * For backwards compatibility, this field is always present, but it may be empty. + */ + content: z.array(exports.ContentBlockSchema).default([]), + /** + * An object containing structured tool output. + * + * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema. + */ + structuredContent: z.record(z.string(), z.unknown()).optional(), + /** + * Whether the tool call ended in an error. + * + * If not set, this is assumed to be false (the call was successful). + * + * Any errors that originate from the tool SHOULD be reported inside the result + * object, with `isError` set to true, _not_ as an MCP protocol-level error + * response. Otherwise, the LLM would not be able to see that an error occurred + * and self-correct. + * + * However, any errors in _finding_ the tool, an error indicating that the + * server does not support tool calls, or any other exceptional conditions, + * should be reported as an MCP error response. + */ + isError: z.optional(z.boolean()) +}); +/** + * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. + */ +exports.CompatibilityCallToolResultSchema = exports.CallToolResultSchema.or(exports.ResultSchema.extend({ + toolResult: z.unknown() +})); +/** + * Parameters for a `tools/call` request. + */ +exports.CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The name of the tool to call. + */ + name: z.string(), + /** + * Arguments to pass to the tool. + */ + arguments: z.optional(z.record(z.string(), z.unknown())) +}); +/** + * Used by the client to invoke a tool provided by the server. + */ +exports.CallToolRequestSchema = exports.RequestSchema.extend({ + method: z.literal('tools/call'), + params: exports.CallToolRequestParamsSchema +}); +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +exports.ToolListChangedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/tools/list_changed') +}); +/* Logging */ +/** + * The severity of a log message. + */ +exports.LoggingLevelSchema = z.enum(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']); +/** + * Parameters for a `logging/setLevel` request. + */ +exports.SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message. + */ + level: exports.LoggingLevelSchema +}); +/** + * A request from the client to the server, to enable or adjust logging. + */ +exports.SetLevelRequestSchema = exports.RequestSchema.extend({ + method: z.literal('logging/setLevel'), + params: exports.SetLevelRequestParamsSchema +}); +/** + * Parameters for a `notifications/message` notification. + */ +exports.LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The severity of this log message. + */ + level: exports.LoggingLevelSchema, + /** + * An optional name of the logger issuing this message. + */ + logger: z.string().optional(), + /** + * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. + */ + data: z.unknown() +}); +/** + * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + */ +exports.LoggingMessageNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/message'), + params: exports.LoggingMessageNotificationParamsSchema +}); +/* Sampling */ +/** + * Hints to use for model selection. + */ +exports.ModelHintSchema = z.object({ + /** + * A hint for a model name. + */ + name: z.string().optional() +}); +/** + * The server's preferences for model selection, requested of the client during sampling. + */ +exports.ModelPreferencesSchema = z.object({ + /** + * Optional hints to use for model selection. + */ + hints: z.optional(z.array(exports.ModelHintSchema)), + /** + * How much to prioritize cost when selecting a model. + */ + costPriority: z.optional(z.number().min(0).max(1)), + /** + * How much to prioritize sampling speed (latency) when selecting a model. + */ + speedPriority: z.optional(z.number().min(0).max(1)), + /** + * How much to prioritize intelligence and capabilities when selecting a model. + */ + intelligencePriority: z.optional(z.number().min(0).max(1)) +}); +/** + * Controls tool usage behavior in sampling requests. + */ +exports.ToolChoiceSchema = z.object({ + /** + * Controls when tools are used: + * - "auto": Model decides whether to use tools (default) + * - "required": Model MUST use at least one tool before completing + * - "none": Model MUST NOT use any tools + */ + mode: z.optional(z.enum(['auto', 'required', 'none'])) +}); +/** + * The result of a tool execution, provided by the user (server). + * Represents the outcome of invoking a tool requested via ToolUseContent. + */ +exports.ToolResultContentSchema = z + .object({ + type: z.literal('tool_result'), + toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'), + content: z.array(exports.ContentBlockSchema).default([]), + structuredContent: z.object({}).passthrough().optional(), + isError: z.optional(z.boolean()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * Content block types allowed in sampling messages. + * This includes text, image, audio, tool use requests, and tool results. + */ +exports.SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [ + exports.TextContentSchema, + exports.ImageContentSchema, + exports.AudioContentSchema, + exports.ToolUseContentSchema, + exports.ToolResultContentSchema +]); +/** + * Describes a message issued to or received from an LLM API. + */ +exports.SamplingMessageSchema = z + .object({ + role: z.enum(['user', 'assistant']), + content: z.union([exports.SamplingMessageContentBlockSchema, z.array(exports.SamplingMessageContentBlockSchema)]), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * Parameters for a `sampling/createMessage` request. + */ +exports.CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({ + messages: z.array(exports.SamplingMessageSchema), + /** + * The server's preferences for which model to select. The client MAY modify or omit this request. + */ + modelPreferences: exports.ModelPreferencesSchema.optional(), + /** + * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt. + */ + systemPrompt: z.string().optional(), + /** + * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. + * The client MAY ignore this request. + * + * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client + * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases. + */ + includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(), + temperature: z.number().optional(), + /** + * The requested maximum number of tokens to sample (to prevent runaway completions). + * + * The client MAY choose to sample fewer tokens than the requested maximum. + */ + maxTokens: z.number().int(), + stopSequences: z.array(z.string()).optional(), + /** + * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific. + */ + metadata: AssertObjectSchema.optional(), + /** + * Tools that the model may use during generation. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + */ + tools: z.optional(z.array(exports.ToolSchema)), + /** + * Controls how the model uses tools. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + * Default is `{ mode: "auto" }`. + */ + toolChoice: z.optional(exports.ToolChoiceSchema) +}); +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + */ +exports.CreateMessageRequestSchema = exports.RequestSchema.extend({ + method: z.literal('sampling/createMessage'), + params: exports.CreateMessageRequestParamsSchema +}); +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + */ +exports.CreateMessageResultSchema = exports.ResultSchema.extend({ + /** + * The name of the model that generated the message. + */ + model: z.string(), + /** + * The reason why sampling stopped, if known. + * + * Standard values: + * - "endTurn": Natural end of the assistant's turn + * - "stopSequence": A stop sequence was encountered + * - "maxTokens": Maximum token limit was reached + * - "toolUse": The model wants to use one or more tools + * + * This field is an open string to allow for provider-specific stop reasons. + */ + stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())), + role: z.enum(['user', 'assistant']), + /** + * Response content. May be ToolUseContent if stopReason is "toolUse". + */ + content: z.union([exports.SamplingMessageContentBlockSchema, z.array(exports.SamplingMessageContentBlockSchema)]) +}); +/* Elicitation */ +/** + * Primitive schema definition for boolean fields. + */ +exports.BooleanSchemaSchema = z.object({ + type: z.literal('boolean'), + title: z.string().optional(), + description: z.string().optional(), + default: z.boolean().optional() +}); +/** + * Primitive schema definition for string fields. + */ +exports.StringSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + minLength: z.number().optional(), + maxLength: z.number().optional(), + format: z.enum(['email', 'uri', 'date', 'date-time']).optional(), + default: z.string().optional() +}); +/** + * Primitive schema definition for number fields. + */ +exports.NumberSchemaSchema = z.object({ + type: z.enum(['number', 'integer']), + title: z.string().optional(), + description: z.string().optional(), + minimum: z.number().optional(), + maximum: z.number().optional(), + default: z.number().optional() +}); +/** + * Schema for single-selection enumeration without display titles for options. + */ +exports.UntitledSingleSelectEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + enum: z.array(z.string()), + default: z.string().optional() +}); +/** + * Schema for single-selection enumeration with display titles for each option. + */ +exports.TitledSingleSelectEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + oneOf: z.array(z.object({ + const: z.string(), + title: z.string() + })), + default: z.string().optional() +}); +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + */ +exports.LegacyTitledEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + enum: z.array(z.string()), + enumNames: z.array(z.string()).optional(), + default: z.string().optional() +}); +// Combined single selection enumeration +exports.SingleSelectEnumSchemaSchema = z.union([exports.UntitledSingleSelectEnumSchemaSchema, exports.TitledSingleSelectEnumSchemaSchema]); +/** + * Schema for multiple-selection enumeration without display titles for options. + */ +exports.UntitledMultiSelectEnumSchemaSchema = z.object({ + type: z.literal('array'), + title: z.string().optional(), + description: z.string().optional(), + minItems: z.number().optional(), + maxItems: z.number().optional(), + items: z.object({ + type: z.literal('string'), + enum: z.array(z.string()) + }), + default: z.array(z.string()).optional() +}); +/** + * Schema for multiple-selection enumeration with display titles for each option. + */ +exports.TitledMultiSelectEnumSchemaSchema = z.object({ + type: z.literal('array'), + title: z.string().optional(), + description: z.string().optional(), + minItems: z.number().optional(), + maxItems: z.number().optional(), + items: z.object({ + anyOf: z.array(z.object({ + const: z.string(), + title: z.string() + })) + }), + default: z.array(z.string()).optional() +}); +/** + * Combined schema for multiple-selection enumeration + */ +exports.MultiSelectEnumSchemaSchema = z.union([exports.UntitledMultiSelectEnumSchemaSchema, exports.TitledMultiSelectEnumSchemaSchema]); +/** + * Primitive schema definition for enum fields. + */ +exports.EnumSchemaSchema = z.union([exports.LegacyTitledEnumSchemaSchema, exports.SingleSelectEnumSchemaSchema, exports.MultiSelectEnumSchemaSchema]); +/** + * Union of all primitive schema definitions. + */ +exports.PrimitiveSchemaDefinitionSchema = z.union([exports.EnumSchemaSchema, exports.BooleanSchemaSchema, exports.StringSchemaSchema, exports.NumberSchemaSchema]); +/** + * Parameters for an `elicitation/create` request for form-based elicitation. + */ +exports.ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The elicitation mode. + * + * Optional for backward compatibility. Clients MUST treat missing mode as "form". + */ + mode: z.literal('form').optional(), + /** + * The message to present to the user describing what information is being requested. + */ + message: z.string(), + /** + * A restricted subset of JSON Schema. + * Only top-level properties are allowed, without nesting. + */ + requestedSchema: z.object({ + type: z.literal('object'), + properties: z.record(z.string(), exports.PrimitiveSchemaDefinitionSchema), + required: z.array(z.string()).optional() + }) +}); +/** + * Parameters for an `elicitation/create` request for URL-based elicitation. + */ +exports.ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The elicitation mode. + */ + mode: z.literal('url'), + /** + * The message to present to the user explaining why the interaction is needed. + */ + message: z.string(), + /** + * The ID of the elicitation, which must be unique within the context of the server. + * The client MUST treat this ID as an opaque value. + */ + elicitationId: z.string(), + /** + * The URL that the user should navigate to. + */ + url: z.string().url() +}); +/** + * The parameters for a request to elicit additional information from the user via the client. + */ +exports.ElicitRequestParamsSchema = z.union([exports.ElicitRequestFormParamsSchema, exports.ElicitRequestURLParamsSchema]); +/** + * A request from the server to elicit user input via the client. + * The client should present the message and form fields to the user (form mode) + * or navigate to a URL (URL mode). + */ +exports.ElicitRequestSchema = exports.RequestSchema.extend({ + method: z.literal('elicitation/create'), + params: exports.ElicitRequestParamsSchema +}); +/** + * Parameters for a `notifications/elicitation/complete` notification. + * + * @category notifications/elicitation/complete + */ +exports.ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The ID of the elicitation that completed. + */ + elicitationId: z.string() +}); +/** + * A notification from the server to the client, informing it of a completion of an out-of-band elicitation request. + * + * @category notifications/elicitation/complete + */ +exports.ElicitationCompleteNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/elicitation/complete'), + params: exports.ElicitationCompleteNotificationParamsSchema +}); +/** + * The client's response to an elicitation/create request from the server. + */ +exports.ElicitResultSchema = exports.ResultSchema.extend({ + /** + * The user action in response to the elicitation. + * - "accept": User submitted the form/confirmed the action + * - "decline": User explicitly decline the action + * - "cancel": User dismissed without making an explicit choice + */ + action: z.enum(['accept', 'decline', 'cancel']), + /** + * The submitted form data, only present when action is "accept". + * Contains values matching the requested schema. + */ + content: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional() +}); +/* Autocomplete */ +/** + * A reference to a resource or resource template definition. + */ +exports.ResourceTemplateReferenceSchema = z.object({ + type: z.literal('ref/resource'), + /** + * The URI or URI template of the resource. + */ + uri: z.string() +}); +/** + * @deprecated Use ResourceTemplateReferenceSchema instead + */ +exports.ResourceReferenceSchema = exports.ResourceTemplateReferenceSchema; +/** + * Identifies a prompt. + */ +exports.PromptReferenceSchema = z.object({ + type: z.literal('ref/prompt'), + /** + * The name of the prompt or prompt template + */ + name: z.string() +}); +/** + * Parameters for a `completion/complete` request. + */ +exports.CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({ + ref: z.union([exports.PromptReferenceSchema, exports.ResourceTemplateReferenceSchema]), + /** + * The argument's information + */ + argument: z.object({ + /** + * The name of the argument + */ + name: z.string(), + /** + * The value of the argument to use for completion matching. + */ + value: z.string() + }), + context: z + .object({ + /** + * Previously-resolved variables in a URI template or prompt. + */ + arguments: z.record(z.string(), z.string()).optional() + }) + .optional() +}); +/** + * A request from the client to the server, to ask for completion options. + */ +exports.CompleteRequestSchema = exports.RequestSchema.extend({ + method: z.literal('completion/complete'), + params: exports.CompleteRequestParamsSchema +}); +function assertCompleteRequestPrompt(request) { + if (request.params.ref.type !== 'ref/prompt') { + throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`); + } + void request; +} +function assertCompleteRequestResourceTemplate(request) { + if (request.params.ref.type !== 'ref/resource') { + throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`); + } + void request; +} +/** + * The server's response to a completion/complete request + */ +exports.CompleteResultSchema = exports.ResultSchema.extend({ + completion: z.looseObject({ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.array(z.string()).max(100), + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.optional(z.number().int()), + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.optional(z.boolean()) + }) +}); +/* Roots */ +/** + * Represents a root directory or file that the server can operate on. + */ +exports.RootSchema = z.object({ + /** + * The URI identifying the root. This *must* start with file:// for now. + */ + uri: z.string().startsWith('file://'), + /** + * An optional name for the root. + */ + name: z.string().optional(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * Sent from the server to request a list of root URIs from the client. + */ +exports.ListRootsRequestSchema = exports.RequestSchema.extend({ + method: z.literal('roots/list') +}); +/** + * The client's response to a roots/list request from the server. + */ +exports.ListRootsResultSchema = exports.ResultSchema.extend({ + roots: z.array(exports.RootSchema) +}); +/** + * A notification from the client to the server, informing it that the list of roots has changed. + */ +exports.RootsListChangedNotificationSchema = exports.NotificationSchema.extend({ + method: z.literal('notifications/roots/list_changed') +}); +/* Client messages */ +exports.ClientRequestSchema = z.union([ + exports.PingRequestSchema, + exports.InitializeRequestSchema, + exports.CompleteRequestSchema, + exports.SetLevelRequestSchema, + exports.GetPromptRequestSchema, + exports.ListPromptsRequestSchema, + exports.ListResourcesRequestSchema, + exports.ListResourceTemplatesRequestSchema, + exports.ReadResourceRequestSchema, + exports.SubscribeRequestSchema, + exports.UnsubscribeRequestSchema, + exports.CallToolRequestSchema, + exports.ListToolsRequestSchema, + exports.GetTaskRequestSchema, + exports.GetTaskPayloadRequestSchema, + exports.ListTasksRequestSchema +]); +exports.ClientNotificationSchema = z.union([ + exports.CancelledNotificationSchema, + exports.ProgressNotificationSchema, + exports.InitializedNotificationSchema, + exports.RootsListChangedNotificationSchema, + exports.TaskStatusNotificationSchema +]); +exports.ClientResultSchema = z.union([ + exports.EmptyResultSchema, + exports.CreateMessageResultSchema, + exports.ElicitResultSchema, + exports.ListRootsResultSchema, + exports.GetTaskResultSchema, + exports.ListTasksResultSchema, + exports.CreateTaskResultSchema +]); +/* Server messages */ +exports.ServerRequestSchema = z.union([ + exports.PingRequestSchema, + exports.CreateMessageRequestSchema, + exports.ElicitRequestSchema, + exports.ListRootsRequestSchema, + exports.GetTaskRequestSchema, + exports.GetTaskPayloadRequestSchema, + exports.ListTasksRequestSchema +]); +exports.ServerNotificationSchema = z.union([ + exports.CancelledNotificationSchema, + exports.ProgressNotificationSchema, + exports.LoggingMessageNotificationSchema, + exports.ResourceUpdatedNotificationSchema, + exports.ResourceListChangedNotificationSchema, + exports.ToolListChangedNotificationSchema, + exports.PromptListChangedNotificationSchema, + exports.TaskStatusNotificationSchema, + exports.ElicitationCompleteNotificationSchema +]); +exports.ServerResultSchema = z.union([ + exports.EmptyResultSchema, + exports.InitializeResultSchema, + exports.CompleteResultSchema, + exports.GetPromptResultSchema, + exports.ListPromptsResultSchema, + exports.ListResourcesResultSchema, + exports.ListResourceTemplatesResultSchema, + exports.ReadResourceResultSchema, + exports.CallToolResultSchema, + exports.ListToolsResultSchema, + exports.GetTaskResultSchema, + exports.ListTasksResultSchema, + exports.CreateTaskResultSchema +]); +class McpError extends Error { + constructor(code, message, data) { + super(`MCP error ${code}: ${message}`); + this.code = code; + this.data = data; + this.name = 'McpError'; + } + /** + * Factory method to create the appropriate error type based on the error code and data + */ + static fromError(code, message, data) { + // Check for specific error types + if (code === ErrorCode.UrlElicitationRequired && data) { + const errorData = data; + if (errorData.elicitations) { + return new UrlElicitationRequiredError(errorData.elicitations, message); + } + } + // Default to generic McpError + return new McpError(code, message, data); + } +} +exports.McpError = McpError; +/** + * Specialized error type when a tool requires a URL mode elicitation. + * This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against. + */ +class UrlElicitationRequiredError extends McpError { + constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? 's' : ''} required`) { + super(ErrorCode.UrlElicitationRequired, message, { + elicitations: elicitations + }); + } + get elicitations() { + var _a, _b; + return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : []; + } +} +exports.UrlElicitationRequiredError = UrlElicitationRequiredError; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/cjs/types.js.map b/dist/cjs/types.js.map new file mode 100644 index 000000000..ed9dff8d5 --- /dev/null +++ b/dist/cjs/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA42DA,kEAKC;AAED,sFAKC;AAx3DD,0CAA4B;AAGf,QAAA,uBAAuB,GAAG,YAAY,CAAC;AACvC,QAAA,mCAAmC,GAAG,YAAY,CAAC;AACnD,QAAA,2BAA2B,GAAG,CAAC,+BAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAElG,QAAA,qBAAqB,GAAG,sCAAsC,CAAC;AAE5E,oBAAoB;AACP,QAAA,eAAe,GAAG,KAAK,CAAC;AAMrC;;;;GAIG;AACH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,YAAY,EAAE,YAAY;SAC7B,CAAC,CAAC;IACP,CAAC;IAED,IAAI,YAAY;;QACZ,OAAO,MAAA,MAAC,IAAI,CAAC,IAAmD,0CAAE,YAAY,mCAAI,EAAE,CAAC;IACzF,CAAC;CACJ;AAVD,kEAUC"} \ No newline at end of file diff --git a/dist/cjs/validation/ajv-provider.d.ts b/dist/cjs/validation/ajv-provider.d.ts new file mode 100644 index 000000000..43e24ffc9 --- /dev/null +++ b/dist/cjs/validation/ajv-provider.d.ts @@ -0,0 +1,53 @@ +/** + * AJV-based JSON Schema validator provider + */ +import { Ajv } from 'ajv'; +import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js'; +/** + * @example + * ```typescript + * // Use with default AJV instance (recommended) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Use with custom AJV instance + * import { Ajv } from 'ajv'; + * const ajv = new Ajv({ strict: true, allErrors: true }); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ +export declare class AjvJsonSchemaValidator implements jsonSchemaValidator { + private _ajv; + /** + * Create an AJV validator + * + * @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created. + * + * @example + * ```typescript + * // Use default configuration (recommended for most cases) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Or provide custom AJV instance for advanced configuration + * import { Ajv } from 'ajv'; + * import addFormats from 'ajv-formats'; + * + * const ajv = new Ajv({ validateFormats: true }); + * addFormats(ajv); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ + constructor(ajv?: Ajv); + /** + * Create a validator for the given JSON Schema + * + * The validator is compiled once and can be reused multiple times. + * If the schema has an $id, it will be cached by AJV automatically. + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +//# sourceMappingURL=ajv-provider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/validation/ajv-provider.d.ts.map b/dist/cjs/validation/ajv-provider.d.ts.map new file mode 100644 index 000000000..4e955a3b3 --- /dev/null +++ b/dist/cjs/validation/ajv-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ajv-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/ajv-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAgBtH;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,mBAAmB;IAC9D,OAAO,CAAC,IAAI,CAAM;IAElB;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,GAAG,CAAC,EAAE,GAAG;IAIrB;;;;;;;;OAQG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAyBlE"} \ No newline at end of file diff --git a/dist/cjs/validation/ajv-provider.js b/dist/cjs/validation/ajv-provider.js new file mode 100644 index 000000000..7356bfa30 --- /dev/null +++ b/dist/cjs/validation/ajv-provider.js @@ -0,0 +1,95 @@ +"use strict"; +/** + * AJV-based JSON Schema validator provider + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AjvJsonSchemaValidator = void 0; +const ajv_1 = require("ajv"); +const ajv_formats_1 = __importDefault(require("ajv-formats")); +function createDefaultAjvInstance() { + const ajv = new ajv_1.Ajv({ + strict: false, + validateFormats: true, + validateSchema: false, + allErrors: true + }); + const addFormats = ajv_formats_1.default; + addFormats(ajv); + return ajv; +} +/** + * @example + * ```typescript + * // Use with default AJV instance (recommended) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Use with custom AJV instance + * import { Ajv } from 'ajv'; + * const ajv = new Ajv({ strict: true, allErrors: true }); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ +class AjvJsonSchemaValidator { + /** + * Create an AJV validator + * + * @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created. + * + * @example + * ```typescript + * // Use default configuration (recommended for most cases) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Or provide custom AJV instance for advanced configuration + * import { Ajv } from 'ajv'; + * import addFormats from 'ajv-formats'; + * + * const ajv = new Ajv({ validateFormats: true }); + * addFormats(ajv); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ + constructor(ajv) { + this._ajv = ajv !== null && ajv !== void 0 ? ajv : createDefaultAjvInstance(); + } + /** + * Create a validator for the given JSON Schema + * + * The validator is compiled once and can be reused multiple times. + * If the schema has an $id, it will be cached by AJV automatically. + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema) { + var _a; + // Check if schema has $id and is already compiled/cached + const ajvValidator = '$id' in schema && typeof schema.$id === 'string' + ? ((_a = this._ajv.getSchema(schema.$id)) !== null && _a !== void 0 ? _a : this._ajv.compile(schema)) + : this._ajv.compile(schema); + return (input) => { + const valid = ajvValidator(input); + if (valid) { + return { + valid: true, + data: input, + errorMessage: undefined + }; + } + else { + return { + valid: false, + data: undefined, + errorMessage: this._ajv.errorsText(ajvValidator.errors) + }; + } + }; + } +} +exports.AjvJsonSchemaValidator = AjvJsonSchemaValidator; +//# sourceMappingURL=ajv-provider.js.map \ No newline at end of file diff --git a/dist/cjs/validation/ajv-provider.js.map b/dist/cjs/validation/ajv-provider.js.map new file mode 100644 index 000000000..fcaa27e9f --- /dev/null +++ b/dist/cjs/validation/ajv-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ajv-provider.js","sourceRoot":"","sources":["../../../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AAE,SAAS;oBACf,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;iBAC1D,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ;AA7DD,wDA6DC"} \ No newline at end of file diff --git a/dist/cjs/validation/cfworker-provider.d.ts b/dist/cjs/validation/cfworker-provider.d.ts new file mode 100644 index 000000000..89c244a60 --- /dev/null +++ b/dist/cjs/validation/cfworker-provider.d.ts @@ -0,0 +1,51 @@ +/** + * Cloudflare Worker-compatible JSON Schema validator provider + * + * This provider uses @cfworker/json-schema for validation without code generation, + * making it compatible with edge runtimes like Cloudflare Workers that restrict + * eval and new Function. + */ +import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js'; +/** + * JSON Schema draft version supported by @cfworker/json-schema + */ +export type CfWorkerSchemaDraft = '4' | '7' | '2019-09' | '2020-12'; +/** + * + * @example + * ```typescript + * // Use with default configuration (2020-12, shortcircuit) + * const validator = new CfWorkerJsonSchemaValidator(); + * + * // Use with custom configuration + * const validator = new CfWorkerJsonSchemaValidator({ + * draft: '2020-12', + * shortcircuit: false // Report all errors + * }); + * ``` + */ +export declare class CfWorkerJsonSchemaValidator implements jsonSchemaValidator { + private shortcircuit; + private draft; + /** + * Create a validator + * + * @param options - Configuration options + * @param options.shortcircuit - If true, stop validation after first error (default: true) + * @param options.draft - JSON Schema draft version to use (default: '2020-12') + */ + constructor(options?: { + shortcircuit?: boolean; + draft?: CfWorkerSchemaDraft; + }); + /** + * Create a validator for the given JSON Schema + * + * Unlike AJV, this validator is not cached internally + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +//# sourceMappingURL=cfworker-provider.d.ts.map \ No newline at end of file diff --git a/dist/cjs/validation/cfworker-provider.d.ts.map b/dist/cjs/validation/cfworker-provider.d.ts.map new file mode 100644 index 000000000..ce404d92f --- /dev/null +++ b/dist/cjs/validation/cfworker-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"cfworker-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACnE,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAsB;IAEnC;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,mBAAmB,CAAA;KAAE;IAK7E;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAsBlE"} \ No newline at end of file diff --git a/dist/cjs/validation/cfworker-provider.js b/dist/cjs/validation/cfworker-provider.js new file mode 100644 index 000000000..a080a373b --- /dev/null +++ b/dist/cjs/validation/cfworker-provider.js @@ -0,0 +1,70 @@ +"use strict"; +/** + * Cloudflare Worker-compatible JSON Schema validator provider + * + * This provider uses @cfworker/json-schema for validation without code generation, + * making it compatible with edge runtimes like Cloudflare Workers that restrict + * eval and new Function. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CfWorkerJsonSchemaValidator = void 0; +const json_schema_1 = require("@cfworker/json-schema"); +/** + * + * @example + * ```typescript + * // Use with default configuration (2020-12, shortcircuit) + * const validator = new CfWorkerJsonSchemaValidator(); + * + * // Use with custom configuration + * const validator = new CfWorkerJsonSchemaValidator({ + * draft: '2020-12', + * shortcircuit: false // Report all errors + * }); + * ``` + */ +class CfWorkerJsonSchemaValidator { + /** + * Create a validator + * + * @param options - Configuration options + * @param options.shortcircuit - If true, stop validation after first error (default: true) + * @param options.draft - JSON Schema draft version to use (default: '2020-12') + */ + constructor(options) { + var _a, _b; + this.shortcircuit = (_a = options === null || options === void 0 ? void 0 : options.shortcircuit) !== null && _a !== void 0 ? _a : true; + this.draft = (_b = options === null || options === void 0 ? void 0 : options.draft) !== null && _b !== void 0 ? _b : '2020-12'; + } + /** + * Create a validator for the given JSON Schema + * + * Unlike AJV, this validator is not cached internally + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema) { + const cfSchema = schema; + const validator = new json_schema_1.Validator(cfSchema, this.draft, this.shortcircuit); + return (input) => { + const result = validator.validate(input); + if (result.valid) { + return { + valid: true, + data: input, + errorMessage: undefined + }; + } + else { + return { + valid: false, + data: undefined, + errorMessage: result.errors.map(err => `${err.instanceLocation}: ${err.error}`).join('; ') + }; + } + }; + } +} +exports.CfWorkerJsonSchemaValidator = CfWorkerJsonSchemaValidator; +//# sourceMappingURL=cfworker-provider.js.map \ No newline at end of file diff --git a/dist/cjs/validation/cfworker-provider.js.map b/dist/cjs/validation/cfworker-provider.js.map new file mode 100644 index 000000000..b83afb324 --- /dev/null +++ b/dist/cjs/validation/cfworker-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cfworker-provider.js","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,uDAA+D;AAQ/D;;;;;;;;;;;;;GAaG;AACH,MAAa,2BAA2B;IAIpC;;;;;;OAMG;IACH,YAAY,OAAiE;;QACzE,IAAI,CAAC,YAAY,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,IAAI,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,SAAS,CAAC;IAC7C,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CAAI,MAAsB;QAClC,MAAM,QAAQ,GAAG,MAA2B,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,uBAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAEzE,OAAO,CAAC,KAAc,EAAgC,EAAE;YACpD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEzC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAU;oBAChB,YAAY,EAAE,SAAS;iBAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO;oBACH,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,SAAS;oBACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,gBAAgB,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC7F,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ;AA9CD,kEA8CC"} \ No newline at end of file diff --git a/dist/cjs/validation/index.d.ts b/dist/cjs/validation/index.d.ts new file mode 100644 index 000000000..99e993967 --- /dev/null +++ b/dist/cjs/validation/index.d.ts @@ -0,0 +1,29 @@ +/** + * JSON Schema validation + * + * This module provides configurable JSON Schema validation for the MCP SDK. + * Choose a validator based on your runtime environment: + * + * - AjvJsonSchemaValidator: Best for Node.js (default, fastest) + * Import from: @modelcontextprotocol/sdk/validation/ajv + * Requires peer dependencies: ajv, ajv-formats + * + * - CfWorkerJsonSchemaValidator: Best for edge runtimes + * Import from: @modelcontextprotocol/sdk/validation/cfworker + * Requires peer dependency: @cfworker/json-schema + * + * @example + * ```typescript + * // For Node.js with AJV + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // For Cloudflare Workers + * import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker'; + * const validator = new CfWorkerJsonSchemaValidator(); + * ``` + * + * @module validation + */ +export type { JsonSchemaType, JsonSchemaValidator, JsonSchemaValidatorResult, jsonSchemaValidator } from './types.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/validation/index.d.ts.map b/dist/cjs/validation/index.d.ts.map new file mode 100644 index 000000000..a8845b96e --- /dev/null +++ b/dist/cjs/validation/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/cjs/validation/index.js b/dist/cjs/validation/index.js new file mode 100644 index 000000000..c8be9256d --- /dev/null +++ b/dist/cjs/validation/index.js @@ -0,0 +1,30 @@ +"use strict"; +/** + * JSON Schema validation + * + * This module provides configurable JSON Schema validation for the MCP SDK. + * Choose a validator based on your runtime environment: + * + * - AjvJsonSchemaValidator: Best for Node.js (default, fastest) + * Import from: @modelcontextprotocol/sdk/validation/ajv + * Requires peer dependencies: ajv, ajv-formats + * + * - CfWorkerJsonSchemaValidator: Best for edge runtimes + * Import from: @modelcontextprotocol/sdk/validation/cfworker + * Requires peer dependency: @cfworker/json-schema + * + * @example + * ```typescript + * // For Node.js with AJV + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // For Cloudflare Workers + * import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker'; + * const validator = new CfWorkerJsonSchemaValidator(); + * ``` + * + * @module validation + */ +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/validation/index.js.map b/dist/cjs/validation/index.js.map new file mode 100644 index 000000000..1d5874d99 --- /dev/null +++ b/dist/cjs/validation/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"} \ No newline at end of file diff --git a/dist/cjs/validation/types.d.ts b/dist/cjs/validation/types.d.ts new file mode 100644 index 000000000..5872215c7 --- /dev/null +++ b/dist/cjs/validation/types.d.ts @@ -0,0 +1,55 @@ +import type { Schema } from '@cfworker/json-schema'; +/** + * Result of a JSON Schema validation operation + */ +export type JsonSchemaValidatorResult = { + valid: true; + data: T; + errorMessage: undefined; +} | { + valid: false; + data: undefined; + errorMessage: string; +}; +/** + * A validator function that validates data against a JSON Schema + */ +export type JsonSchemaValidator = (input: unknown) => JsonSchemaValidatorResult; +/** + * Provider interface for creating validators from JSON Schemas + * + * This is the main extension point for custom validator implementations. + * Implementations should: + * - Support JSON Schema Draft 2020-12 (or be compatible with it) + * - Return validator functions that can be called multiple times + * - Handle schema compilation/caching internally + * - Provide clear error messages on validation failure + * + * @example + * ```typescript + * class MyValidatorProvider implements jsonSchemaValidator { + * getValidator(schema: JsonSchemaType): JsonSchemaValidator { + * // Compile/cache validator from schema + * return (input: unknown) => { + * // Validate input against schema + * if (valid) { + * return { valid: true, data: input as T, errorMessage: undefined }; + * } else { + * return { valid: false, data: undefined, errorMessage: 'Error details' }; + * } + * }; + * } + * } + * ``` + */ +export interface jsonSchemaValidator { + /** + * Create a validator for the given JSON Schema + * + * @param schema - Standard JSON Schema object + * @returns A validator function that can be called multiple times + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +export type JsonSchemaType = Schema; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/cjs/validation/types.d.ts.map b/dist/cjs/validation/types.d.ts.map new file mode 100644 index 000000000..3bdf64e58 --- /dev/null +++ b/dist/cjs/validation/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACjC;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,GACjD;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/cjs/validation/types.js b/dist/cjs/validation/types.js new file mode 100644 index 000000000..11e638d1e --- /dev/null +++ b/dist/cjs/validation/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/cjs/validation/types.js.map b/dist/cjs/validation/types.js.map new file mode 100644 index 000000000..51361cf6a --- /dev/null +++ b/dist/cjs/validation/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/client/auth-extensions.d.ts b/dist/esm/client/auth-extensions.d.ts new file mode 100644 index 000000000..2a3f6bff6 --- /dev/null +++ b/dist/esm/client/auth-extensions.d.ts @@ -0,0 +1,178 @@ +/** + * OAuth provider extensions for specialized authentication flows. + * + * This module provides ready-to-use OAuthClientProvider implementations + * for common machine-to-machine authentication scenarios. + */ +import { OAuthClientInformation, OAuthClientMetadata, OAuthTokens } from '../shared/auth.js'; +import { AddClientAuthentication, OAuthClientProvider } from './auth.js'; +/** + * Helper to produce a private_key_jwt client authentication function. + * + * Usage: + * const addClientAuth = createPrivateKeyJwtAuth({ issuer, subject, privateKey, alg, audience? }); + * // pass addClientAuth as provider.addClientAuthentication implementation + */ +export declare function createPrivateKeyJwtAuth(options: { + issuer: string; + subject: string; + privateKey: string | Uint8Array | Record; + alg: string; + audience?: string | URL; + lifetimeSeconds?: number; + claims?: Record; +}): AddClientAuthentication; +/** + * Options for creating a ClientCredentialsProvider. + */ +export interface ClientCredentialsProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * The client_secret for client_secret_basic authentication. + */ + clientSecret: string; + /** + * Optional client name for metadata. + */ + clientName?: string; +} +/** + * OAuth provider for client_credentials grant with client_secret_basic authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a client_id and client_secret. + * + * @example + * const provider = new ClientCredentialsProvider({ + * clientId: 'my-client', + * clientSecret: 'my-secret' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export declare class ClientCredentialsProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + constructor(options: ClientCredentialsProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +/** + * Options for creating a PrivateKeyJwtProvider. + */ +export interface PrivateKeyJwtProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * The private key for signing JWT assertions. + * Can be a PEM string, Uint8Array, or JWK object. + */ + privateKey: string | Uint8Array | Record; + /** + * The algorithm to use for signing (e.g., 'RS256', 'ES256'). + */ + algorithm: string; + /** + * Optional client name for metadata. + */ + clientName?: string; + /** + * Optional JWT lifetime in seconds (default: 300). + */ + jwtLifetimeSeconds?: number; +} +/** + * OAuth provider for client_credentials grant with private_key_jwt authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a signed JWT assertion (RFC 7523 Section 2.2). + * + * @example + * const provider = new PrivateKeyJwtProvider({ + * clientId: 'my-client', + * privateKey: pemEncodedPrivateKey, + * algorithm: 'RS256' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export declare class PrivateKeyJwtProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + addClientAuthentication: AddClientAuthentication; + constructor(options: PrivateKeyJwtProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +/** + * Options for creating a StaticPrivateKeyJwtProvider. + */ +export interface StaticPrivateKeyJwtProviderOptions { + /** + * The client_id for this OAuth client. + */ + clientId: string; + /** + * A pre-built JWT client assertion to use for authentication. + * + * This token should already contain the appropriate claims + * (iss, sub, aud, exp, etc.) and be signed by the client's key. + */ + jwtBearerAssertion: string; + /** + * Optional client name for metadata. + */ + clientName?: string; +} +/** + * OAuth provider for client_credentials grant with a static private_key_jwt assertion. + * + * This provider mirrors {@link PrivateKeyJwtProvider} but instead of constructing and + * signing a JWT on each request, it accepts a pre-built JWT assertion string and + * uses it directly for authentication. + */ +export declare class StaticPrivateKeyJwtProvider implements OAuthClientProvider { + private _tokens?; + private _clientInfo; + private _clientMetadata; + addClientAuthentication: AddClientAuthentication; + constructor(options: StaticPrivateKeyJwtProviderOptions); + get redirectUrl(): undefined; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformation; + saveClientInformation(info: OAuthClientInformation): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(): void; + saveCodeVerifier(): void; + codeVerifier(): string; + prepareTokenRequest(scope?: string): URLSearchParams; +} +//# sourceMappingURL=auth-extensions.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/auth-extensions.d.ts.map b/dist/esm/client/auth-extensions.d.ts.map new file mode 100644 index 000000000..863e23a83 --- /dev/null +++ b/dist/esm/client/auth-extensions.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-extensions.d.ts","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,uBAAuB,CAgE1B;AAED;;GAEG;AACH,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M,GAAG,eAAe;CAKvD"} \ No newline at end of file diff --git a/dist/esm/client/auth-extensions.js b/dist/esm/client/auth-extensions.js new file mode 100644 index 000000000..6e4a255dd --- /dev/null +++ b/dist/esm/client/auth-extensions.js @@ -0,0 +1,270 @@ +/** + * OAuth provider extensions for specialized authentication flows. + * + * This module provides ready-to-use OAuthClientProvider implementations + * for common machine-to-machine authentication scenarios. + */ +/** + * Helper to produce a private_key_jwt client authentication function. + * + * Usage: + * const addClientAuth = createPrivateKeyJwtAuth({ issuer, subject, privateKey, alg, audience? }); + * // pass addClientAuth as provider.addClientAuthentication implementation + */ +export function createPrivateKeyJwtAuth(options) { + return async (_headers, params, url, metadata) => { + var _a, _b, _c; + // Lazy import to avoid heavy dependency unless used + if (typeof globalThis.crypto === 'undefined') { + throw new TypeError('crypto is not available, please ensure you add have Web Crypto API support for older Node.js versions (see https://github.com/modelcontextprotocol/typescript-sdk#nodejs-web-crypto-globalthiscrypto-compatibility)'); + } + const jose = await import('jose'); + const audience = String((_b = (_a = options.audience) !== null && _a !== void 0 ? _a : metadata === null || metadata === void 0 ? void 0 : metadata.issuer) !== null && _b !== void 0 ? _b : url); + const lifetimeSeconds = (_c = options.lifetimeSeconds) !== null && _c !== void 0 ? _c : 300; + const now = Math.floor(Date.now() / 1000); + const jti = `${Date.now()}-${Math.random().toString(36).slice(2)}`; + const baseClaims = { + iss: options.issuer, + sub: options.subject, + aud: audience, + exp: now + lifetimeSeconds, + iat: now, + jti + }; + const claims = options.claims ? { ...baseClaims, ...options.claims } : baseClaims; + // Import key for the requested algorithm + const alg = options.alg; + let key; + if (typeof options.privateKey === 'string') { + if (alg.startsWith('RS') || alg.startsWith('ES') || alg.startsWith('PS')) { + key = await jose.importPKCS8(options.privateKey, alg); + } + else if (alg.startsWith('HS')) { + key = new TextEncoder().encode(options.privateKey); + } + else { + throw new Error(`Unsupported algorithm ${alg}`); + } + } + else if (options.privateKey instanceof Uint8Array) { + if (alg.startsWith('HS')) { + key = options.privateKey; + } + else { + // Assume PKCS#8 DER in Uint8Array for asymmetric algorithms + key = await jose.importPKCS8(new TextDecoder().decode(options.privateKey), alg); + } + } + else { + // Treat as JWK + key = await jose.importJWK(options.privateKey, alg); + } + // Sign JWT + const assertion = await new jose.SignJWT(claims) + .setProtectedHeader({ alg, typ: 'JWT' }) + .setIssuer(options.issuer) + .setSubject(options.subject) + .setAudience(audience) + .setIssuedAt(now) + .setExpirationTime(now + lifetimeSeconds) + .setJti(jti) + .sign(key); + params.set('client_assertion', assertion); + params.set('client_assertion_type', 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'); + }; +} +/** + * OAuth provider for client_credentials grant with client_secret_basic authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a client_id and client_secret. + * + * @example + * const provider = new ClientCredentialsProvider({ + * clientId: 'my-client', + * clientSecret: 'my-secret' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export class ClientCredentialsProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId, + client_secret: options.clientSecret + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'client-credentials-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'client_secret_basic' + }; + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +/** + * OAuth provider for client_credentials grant with private_key_jwt authentication. + * + * This provider is designed for machine-to-machine authentication where + * the client authenticates using a signed JWT assertion (RFC 7523 Section 2.2). + * + * @example + * const provider = new PrivateKeyJwtProvider({ + * clientId: 'my-client', + * privateKey: pemEncodedPrivateKey, + * algorithm: 'RS256' + * }); + * + * const transport = new StreamableHTTPClientTransport(serverUrl, { + * authProvider: provider + * }); + */ +export class PrivateKeyJwtProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'private-key-jwt-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'private_key_jwt' + }; + this.addClientAuthentication = createPrivateKeyJwtAuth({ + issuer: options.clientId, + subject: options.clientId, + privateKey: options.privateKey, + alg: options.algorithm, + lifetimeSeconds: options.jwtLifetimeSeconds + }); + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +/** + * OAuth provider for client_credentials grant with a static private_key_jwt assertion. + * + * This provider mirrors {@link PrivateKeyJwtProvider} but instead of constructing and + * signing a JWT on each request, it accepts a pre-built JWT assertion string and + * uses it directly for authentication. + */ +export class StaticPrivateKeyJwtProvider { + constructor(options) { + var _a; + this._clientInfo = { + client_id: options.clientId + }; + this._clientMetadata = { + client_name: (_a = options.clientName) !== null && _a !== void 0 ? _a : 'static-private-key-jwt-client', + redirect_uris: [], + grant_types: ['client_credentials'], + token_endpoint_auth_method: 'private_key_jwt' + }; + const assertion = options.jwtBearerAssertion; + this.addClientAuthentication = async (_headers, params) => { + params.set('client_assertion', assertion); + params.set('client_assertion_type', 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'); + }; + } + get redirectUrl() { + return undefined; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInfo; + } + saveClientInformation(info) { + this._clientInfo = info; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization() { + throw new Error('redirectToAuthorization is not used for client_credentials flow'); + } + saveCodeVerifier() { + // Not used for client_credentials + } + codeVerifier() { + throw new Error('codeVerifier is not used for client_credentials flow'); + } + prepareTokenRequest(scope) { + const params = new URLSearchParams({ grant_type: 'client_credentials' }); + if (scope) + params.set('scope', scope); + return params; + } +} +//# sourceMappingURL=auth-extensions.js.map \ No newline at end of file diff --git a/dist/esm/client/auth-extensions.js.map b/dist/esm/client/auth-extensions.js.map new file mode 100644 index 000000000..1fa5d75c4 --- /dev/null +++ b/dist/esm/client/auth-extensions.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-extensions.js","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAQvC;IACG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;;QAC7C,oDAAoD;QACpD,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YAC3C,MAAM,IAAI,SAAS,CACf,qNAAqN,CACxN,CAAC;QACN,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,mCAAI,GAAG,CAAC,CAAC;QACrE,MAAM,eAAe,GAAG,MAAA,OAAO,CAAC,e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sDAAsD,CAAC,CAAC;IAC5E,CAAC;IAED,mBAAmB,CAAC,KAAc;QAC9B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,CAAC;QACzE,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/client/auth.d.ts b/dist/esm/client/auth.d.ts new file mode 100644 index 000000000..c1405d6c0 --- /dev/null +++ b/dist/esm/client/auth.d.ts @@ -0,0 +1,368 @@ +import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens, OAuthMetadata, OAuthClientInformationFull, OAuthProtectedResourceMetadata, AuthorizationServerMetadata } from '../shared/auth.js'; +import { OAuthError } from '../server/auth/errors.js'; +import { FetchLike } from '../shared/transport.js'; +/** + * Function type for adding client authentication to token requests. + */ +export type AddClientAuthentication = (headers: Headers, params: URLSearchParams, url: string | URL, metadata?: AuthorizationServerMetadata) => void | Promise; +/** + * Implements an end-to-end OAuth client to be used with one MCP server. + * + * This client relies upon a concept of an authorized "session," the exact + * meaning of which is application-defined. Tokens, authorization codes, and + * code verifiers should not cross different sessions. + */ +export interface OAuthClientProvider { + /** + * The URL to redirect the user agent to after authorization. + * Return undefined for non-interactive flows that don't require user interaction + * (e.g., client_credentials, jwt-bearer). + */ + get redirectUrl(): string | URL | undefined; + /** + * External URL the server should use to fetch client metadata document + */ + clientMetadataUrl?: string; + /** + * Metadata about this OAuth client. + */ + get clientMetadata(): OAuthClientMetadata; + /** + * Returns a OAuth2 state parameter. + */ + state?(): string | Promise; + /** + * Loads information about this OAuth client, as registered already with the + * server, or returns `undefined` if the client is not registered with the + * server. + */ + clientInformation(): OAuthClientInformationMixed | undefined | Promise; + /** + * If implemented, this permits the OAuth client to dynamically register with + * the server. Client information saved this way should later be read via + * `clientInformation()`. + * + * This method is not required to be implemented if client information is + * statically known (e.g., pre-registered). + */ + saveClientInformation?(clientInformation: OAuthClientInformationMixed): void | Promise; + /** + * Loads any existing OAuth tokens for the current session, or returns + * `undefined` if there are no saved tokens. + */ + tokens(): OAuthTokens | undefined | Promise; + /** + * Stores new OAuth tokens for the current session, after a successful + * authorization. + */ + saveTokens(tokens: OAuthTokens): void | Promise; + /** + * Invoked to redirect the user agent to the given URL to begin the authorization flow. + */ + redirectToAuthorization(authorizationUrl: URL): void | Promise; + /** + * Saves a PKCE code verifier for the current session, before redirecting to + * the authorization flow. + */ + saveCodeVerifier(codeVerifier: string): void | Promise; + /** + * Loads the PKCE code verifier for the current session, necessary to validate + * the authorization result. + */ + codeVerifier(): string | Promise; + /** + * Adds custom client authentication to OAuth token requests. + * + * This optional method allows implementations to customize how client credentials + * are included in token exchange and refresh requests. When provided, this method + * is called instead of the default authentication logic, giving full control over + * the authentication mechanism. + * + * Common use cases include: + * - Supporting authentication methods beyond the standard OAuth 2.0 methods + * - Adding custom headers for proprietary authentication schemes + * - Implementing client assertion-based authentication (e.g., JWT bearer tokens) + * + * @param headers - The request headers (can be modified to add authentication) + * @param params - The request body parameters (can be modified to add credentials) + * @param url - The token endpoint URL being called + * @param metadata - Optional OAuth metadata for the server, which may include supported authentication methods + */ + addClientAuthentication?: AddClientAuthentication; + /** + * If defined, overrides the selection and validation of the + * RFC 8707 Resource Indicator. If left undefined, default + * validation behavior will be used. + * + * Implementations must verify the returned resource matches the MCP server. + */ + validateResourceURL?(serverUrl: string | URL, resource?: string): Promise; + /** + * If implemented, provides a way for the client to invalidate (e.g. delete) the specified + * credentials, in the case where the server has indicated that they are no longer valid. + * This avoids requiring the user to intervene manually. + */ + invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise; + /** + * Prepares grant-specific parameters for a token request. + * + * This optional method allows providers to customize the token request based on + * the grant type they support. When implemented, it returns the grant type and + * any grant-specific parameters needed for the token exchange. + * + * If not implemented, the default behavior depends on the flow: + * - For authorization code flow: uses code, code_verifier, and redirect_uri + * - For client_credentials: detected via grant_types in clientMetadata + * + * @param scope - Optional scope to request + * @returns Grant type and parameters, or undefined to use default behavior + * + * @example + * // For client_credentials grant: + * prepareTokenRequest(scope) { + * return { + * grantType: 'client_credentials', + * params: scope ? { scope } : {} + * }; + * } + * + * @example + * // For authorization_code grant (default behavior): + * async prepareTokenRequest() { + * return { + * grantType: 'authorization_code', + * params: { + * code: this.authorizationCode, + * code_verifier: await this.codeVerifier(), + * redirect_uri: String(this.redirectUrl) + * } + * }; + * } + */ + prepareTokenRequest?(scope?: string): URLSearchParams | Promise | undefined; +} +export type AuthResult = 'AUTHORIZED' | 'REDIRECT'; +export declare class UnauthorizedError extends Error { + constructor(message?: string); +} +type ClientAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none'; +/** + * Determines the best client authentication method to use based on server support and client configuration. + * + * Priority order (highest to lowest): + * 1. client_secret_basic (if client secret is available) + * 2. client_secret_post (if client secret is available) + * 3. none (for public clients) + * + * @param clientInformation - OAuth client information containing credentials + * @param supportedMethods - Authentication methods supported by the authorization server + * @returns The selected authentication method + */ +export declare function selectClientAuthMethod(clientInformation: OAuthClientInformationMixed, supportedMethods: string[]): ClientAuthMethod; +/** + * Parses an OAuth error response from a string or Response object. + * + * If the input is a standard OAuth2.0 error response, it will be parsed according to the spec + * and an instance of the appropriate OAuthError subclass will be returned. + * If parsing fails, it falls back to a generic ServerError that includes + * the response status (if available) and original content. + * + * @param input - A Response object or string containing the error response + * @returns A Promise that resolves to an OAuthError instance + */ +export declare function parseErrorResponse(input: Response | string): Promise; +/** + * Orchestrates the full auth flow with a server. + * + * This can be used as a single entry point for all authorization functionality, + * instead of linking together the other lower-level functions in this module. + */ +export declare function auth(provider: OAuthClientProvider, options: { + serverUrl: string | URL; + authorizationCode?: string; + scope?: string; + resourceMetadataUrl?: URL; + fetchFn?: FetchLike; +}): Promise; +/** + * SEP-991: URL-based Client IDs + * Validate that the client_id is a valid URL with https scheme + */ +export declare function isHttpsUrl(value?: string): boolean; +export declare function selectResourceURL(serverUrl: string | URL, provider: OAuthClientProvider, resourceMetadata?: OAuthProtectedResourceMetadata): Promise; +/** + * Extract resource_metadata, scope, and error from WWW-Authenticate header. + */ +export declare function extractWWWAuthenticateParams(res: Response): { + resourceMetadataUrl?: URL; + scope?: string; + error?: string; +}; +/** + * Extract resource_metadata from response header. + * @deprecated Use `extractWWWAuthenticateParams` instead. + */ +export declare function extractResourceMetadataUrl(res: Response): URL | undefined; +/** + * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + */ +export declare function discoverOAuthProtectedResourceMetadata(serverUrl: string | URL, opts?: { + protocolVersion?: string; + resourceMetadataUrl?: string | URL; +}, fetchFn?: FetchLike): Promise; +/** + * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + * + * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`. + */ +export declare function discoverOAuthMetadata(issuer: string | URL, { authorizationServerUrl, protocolVersion }?: { + authorizationServerUrl?: string | URL; + protocolVersion?: string; +}, fetchFn?: FetchLike): Promise; +/** + * Builds a list of discovery URLs to try for authorization server metadata. + * URLs are returned in priority order: + * 1. OAuth metadata at the given URL + * 2. OIDC metadata endpoints at the given URL + */ +export declare function buildDiscoveryUrls(authorizationServerUrl: string | URL): { + url: URL; + type: 'oauth' | 'oidc'; +}[]; +/** + * Discovers authorization server metadata with support for RFC 8414 OAuth 2.0 Authorization Server Metadata + * and OpenID Connect Discovery 1.0 specifications. + * + * This function implements a fallback strategy for authorization server discovery: + * 1. Attempts RFC 8414 OAuth metadata discovery first + * 2. If OAuth discovery fails, falls back to OpenID Connect Discovery + * + * @param authorizationServerUrl - The authorization server URL obtained from the MCP Server's + * protected resource metadata, or the MCP server's URL if the + * metadata was not found. + * @param options - Configuration options + * @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch + * @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION + * @returns Promise resolving to authorization server metadata, or undefined if discovery fails + */ +export declare function discoverAuthorizationServerMetadata(authorizationServerUrl: string | URL, { fetchFn, protocolVersion }?: { + fetchFn?: FetchLike; + protocolVersion?: string; +}): Promise; +/** + * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL. + */ +export declare function startAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, redirectUrl, scope, state, resource }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + redirectUrl: string | URL; + scope?: string; + state?: string; + resource?: URL; +}): Promise<{ + authorizationUrl: URL; + codeVerifier: string; +}>; +/** + * Prepares token request parameters for an authorization code exchange. + * + * This is the default implementation used by fetchToken when the provider + * doesn't implement prepareTokenRequest. + * + * @param authorizationCode - The authorization code received from the authorization endpoint + * @param codeVerifier - The PKCE code verifier + * @param redirectUri - The redirect URI used in the authorization request + * @returns URLSearchParams for the authorization_code grant + */ +export declare function prepareAuthorizationCodeRequest(authorizationCode: string, codeVerifier: string, redirectUri: string | URL): URLSearchParams; +/** + * Exchanges an authorization code for an access token with the given server. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Falls back to appropriate defaults when server metadata is unavailable + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, auth code, etc. + * @returns Promise resolving to OAuth tokens + * @throws {Error} When token exchange fails or authentication is invalid + */ +export declare function exchangeAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + authorizationCode: string; + codeVerifier: string; + redirectUri: string | URL; + resource?: URL; + addClientAuthentication?: OAuthClientProvider['addClientAuthentication']; + fetchFn?: FetchLike; +}): Promise; +/** + * Exchange a refresh token for an updated access token. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Preserves the original refresh token if a new one is not returned + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, refresh token, etc. + * @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced) + * @throws {Error} When token refresh fails or authentication is invalid + */ +export declare function refreshAuthorization(authorizationServerUrl: string | URL, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientInformation: OAuthClientInformationMixed; + refreshToken: string; + resource?: URL; + addClientAuthentication?: OAuthClientProvider['addClientAuthentication']; + fetchFn?: FetchLike; +}): Promise; +/** + * Unified token fetching that works with any grant type via provider.prepareTokenRequest(). + * + * This function provides a single entry point for obtaining tokens regardless of the + * OAuth grant type. The provider's prepareTokenRequest() method determines which grant + * to use and supplies the grant-specific parameters. + * + * @param provider - OAuth client provider that implements prepareTokenRequest() + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration for the token request + * @returns Promise resolving to OAuth tokens + * @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails + * + * @example + * // Provider for client_credentials: + * class MyProvider implements OAuthClientProvider { + * prepareTokenRequest(scope) { + * const params = new URLSearchParams({ grant_type: 'client_credentials' }); + * if (scope) params.set('scope', scope); + * return params; + * } + * // ... other methods + * } + * + * const tokens = await fetchToken(provider, authServerUrl, { metadata }); + */ +export declare function fetchToken(provider: OAuthClientProvider, authorizationServerUrl: string | URL, { metadata, resource, authorizationCode, fetchFn }?: { + metadata?: AuthorizationServerMetadata; + resource?: URL; + /** Authorization code for the default authorization_code grant flow */ + authorizationCode?: string; + fetchFn?: FetchLike; +}): Promise; +/** + * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591. + */ +export declare function registerClient(authorizationServerUrl: string | URL, { metadata, clientMetadata, fetchFn }: { + metadata?: AuthorizationServerMetadata; + clientMetadata: OAuthClientMetadata; + fetchFn?: FetchLike; +}): Promise; +export {}; +//# sourceMappingURL=auth.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/auth.d.ts.map b/dist/esm/client/auth.d.ts.map new file mode 100644 index 000000000..012c44018 --- /dev/null +++ b/dist/esm/client/auth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/client/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,mBAAmB,EAEnB,2BAA2B,EAC3B,WAAW,EACX,aAAa,EACb,0BAA0B,EAC1B,8BAA8B,EAE9B,2BAA2B,EAE9B,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAKH,UAAU,EAGb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAClC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,QAAQ,CAAC,EAAE,2BAA2B,KACrC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;OAIG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC;IAE5C;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,IAAI,cAAc,IAAI,mBAAmB,CAAC;IAE1C;;OAEG;IACH,KAAK,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnC;;;;OAIG;IACH,iBAAiB,IAAI,2BAA2B,GAAG,SAAS,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAC;IAEhH;;;;;;;OAOG;IACH,qBAAqB,CAAC,CAAC,iBAAiB,EAAE,2BAA2B,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CA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,CAAC;CACvB,GACF,OAAO,CAAC,WAAW,CAAC,CAiBtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,UAAU,CAC5B,QAAQ,EAAE,mBAAmB,EAC7B,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACI,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACV,GAAE;IACC,QAAQ,CAAC,EAAE,2BAA2B,CAAC;IACvC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,SAAS,CAAC;CAClB,GACP,OAAO,CAAC,WAAW,CAAC,CA+BtB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAChC,sBAAsB,EAAE,MAAM,GAAG,GAAG,EACpC,EACI,QAAQ,EACR,cAAc,EACd,OAAO,EACV,EAAE;IACC,QAAQ,CAAC,EAAE,2BAA2B,CAAC;IACvC,cAAc,EAAE,mBAAmB,CAAC;IACpC,OAAO,CAAC,EAAE,SAAS,CAAC;CACvB,GACF,OAAO,CAAC,0BAA0B,CAAC,CA0BrC"} \ No newline at end of file diff --git a/dist/esm/client/auth.js b/dist/esm/client/auth.js new file mode 100644 index 000000000..53234ac0e --- /dev/null +++ b/dist/esm/client/auth.js @@ -0,0 +1,831 @@ +import pkceChallenge from 'pkce-challenge'; +import { LATEST_PROTOCOL_VERSION } from '../types.js'; +import { OAuthErrorResponseSchema, OpenIdProviderDiscoveryMetadataSchema } from '../shared/auth.js'; +import { OAuthClientInformationFullSchema, OAuthMetadataSchema, OAuthProtectedResourceMetadataSchema, OAuthTokensSchema } from '../shared/auth.js'; +import { checkResourceAllowed, resourceUrlFromServerUrl } from '../shared/auth-utils.js'; +import { InvalidClientError, InvalidClientMetadataError, InvalidGrantError, OAUTH_ERRORS, OAuthError, ServerError, UnauthorizedClientError } from '../server/auth/errors.js'; +export class UnauthorizedError extends Error { + constructor(message) { + super(message !== null && message !== void 0 ? message : 'Unauthorized'); + } +} +function isClientAuthMethod(method) { + return ['client_secret_basic', 'client_secret_post', 'none'].includes(method); +} +const AUTHORIZATION_CODE_RESPONSE_TYPE = 'code'; +const AUTHORIZATION_CODE_CHALLENGE_METHOD = 'S256'; +/** + * Determines the best client authentication method to use based on server support and client configuration. + * + * Priority order (highest to lowest): + * 1. client_secret_basic (if client secret is available) + * 2. client_secret_post (if client secret is available) + * 3. none (for public clients) + * + * @param clientInformation - OAuth client information containing credentials + * @param supportedMethods - Authentication methods supported by the authorization server + * @returns The selected authentication method + */ +export function selectClientAuthMethod(clientInformation, supportedMethods) { + const hasClientSecret = clientInformation.client_secret !== undefined; + // If server doesn't specify supported methods, use RFC 6749 defaults + if (supportedMethods.length === 0) { + return hasClientSecret ? 'client_secret_post' : 'none'; + } + // Prefer the method returned by the server during client registration if valid and supported + if ('token_endpoint_auth_method' in clientInformation && + clientInformation.token_endpoint_auth_method && + isClientAuthMethod(clientInformation.token_endpoint_auth_method) && + supportedMethods.includes(clientInformation.token_endpoint_auth_method)) { + return clientInformation.token_endpoint_auth_method; + } + // Try methods in priority order (most secure first) + if (hasClientSecret && supportedMethods.includes('client_secret_basic')) { + return 'client_secret_basic'; + } + if (hasClientSecret && supportedMethods.includes('client_secret_post')) { + return 'client_secret_post'; + } + if (supportedMethods.includes('none')) { + return 'none'; + } + // Fallback: use what we have + return hasClientSecret ? 'client_secret_post' : 'none'; +} +/** + * Applies client authentication to the request based on the specified method. + * + * Implements OAuth 2.1 client authentication methods: + * - client_secret_basic: HTTP Basic authentication (RFC 6749 Section 2.3.1) + * - client_secret_post: Credentials in request body (RFC 6749 Section 2.3.1) + * - none: Public client authentication (RFC 6749 Section 2.1) + * + * @param method - The authentication method to use + * @param clientInformation - OAuth client information containing credentials + * @param headers - HTTP headers object to modify + * @param params - URL search parameters to modify + * @throws {Error} When required credentials are missing + */ +function applyClientAuthentication(method, clientInformation, headers, params) { + const { client_id, client_secret } = clientInformation; + switch (method) { + case 'client_secret_basic': + applyBasicAuth(client_id, client_secret, headers); + return; + case 'client_secret_post': + applyPostAuth(client_id, client_secret, params); + return; + case 'none': + applyPublicAuth(client_id, params); + return; + default: + throw new Error(`Unsupported client authentication method: ${method}`); + } +} +/** + * Applies HTTP Basic authentication (RFC 6749 Section 2.3.1) + */ +function applyBasicAuth(clientId, clientSecret, headers) { + if (!clientSecret) { + throw new Error('client_secret_basic authentication requires a client_secret'); + } + const credentials = btoa(`${clientId}:${clientSecret}`); + headers.set('Authorization', `Basic ${credentials}`); +} +/** + * Applies POST body authentication (RFC 6749 Section 2.3.1) + */ +function applyPostAuth(clientId, clientSecret, params) { + params.set('client_id', clientId); + if (clientSecret) { + params.set('client_secret', clientSecret); + } +} +/** + * Applies public client authentication (RFC 6749 Section 2.1) + */ +function applyPublicAuth(clientId, params) { + params.set('client_id', clientId); +} +/** + * Parses an OAuth error response from a string or Response object. + * + * If the input is a standard OAuth2.0 error response, it will be parsed according to the spec + * and an instance of the appropriate OAuthError subclass will be returned. + * If parsing fails, it falls back to a generic ServerError that includes + * the response status (if available) and original content. + * + * @param input - A Response object or string containing the error response + * @returns A Promise that resolves to an OAuthError instance + */ +export async function parseErrorResponse(input) { + const statusCode = input instanceof Response ? input.status : undefined; + const body = input instanceof Response ? await input.text() : input; + try { + const result = OAuthErrorResponseSchema.parse(JSON.parse(body)); + const { error, error_description, error_uri } = result; + const errorClass = OAUTH_ERRORS[error] || ServerError; + return new errorClass(error_description || '', error_uri); + } + catch (error) { + // Not a valid OAuth error response, but try to inform the user of the raw data anyway + const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ''}Invalid OAuth error response: ${error}. Raw body: ${body}`; + return new ServerError(errorMessage); + } +} +/** + * Orchestrates the full auth flow with a server. + * + * This can be used as a single entry point for all authorization functionality, + * instead of linking together the other lower-level functions in this module. + */ +export async function auth(provider, options) { + var _a, _b; + try { + return await authInternal(provider, options); + } + catch (error) { + // Handle recoverable error types by invalidating credentials and retrying + if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) { + await ((_a = provider.invalidateCredentials) === null || _a === void 0 ? void 0 : _a.call(provider, 'all')); + return await authInternal(provider, options); + } + else if (error instanceof InvalidGrantError) { + await ((_b = provider.invalidateCredentials) === null || _b === void 0 ? void 0 : _b.call(provider, 'tokens')); + return await authInternal(provider, options); + } + // Throw otherwise + throw error; + } +} +async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) { + var _a, _b; + let resourceMetadata; + let authorizationServerUrl; + try { + resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn); + if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) { + authorizationServerUrl = resourceMetadata.authorization_servers[0]; + } + } + catch (_c) { + // Ignore errors and fall back to /.well-known/oauth-authorization-server + } + /** + * If we don't get a valid authorization server metadata from protected resource metadata, + * fallback to the legacy MCP spec's implementation (version 2025-03-26): MCP server base URL acts as the Authorization server. + */ + if (!authorizationServerUrl) { + authorizationServerUrl = new URL('/', serverUrl); + } + const resource = await selectResourceURL(serverUrl, provider, resourceMetadata); + const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { + fetchFn + }); + // Handle client registration if needed + let clientInformation = await Promise.resolve(provider.clientInformation()); + if (!clientInformation) { + if (authorizationCode !== undefined) { + throw new Error('Existing OAuth client information is required when exchanging an authorization code'); + } + const supportsUrlBasedClientId = (metadata === null || metadata === void 0 ? void 0 : metadata.client_id_metadata_document_supported) === true; + const clientMetadataUrl = provider.clientMetadataUrl; + if (clientMetadataUrl && !isHttpsUrl(clientMetadataUrl)) { + throw new InvalidClientMetadataError(`clientMetadataUrl must be a valid HTTPS URL with a non-root pathname, got: ${clientMetadataUrl}`); + } + const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl; + if (shouldUseUrlBasedClientId) { + // SEP-991: URL-based Client IDs + clientInformation = { + client_id: clientMetadataUrl + }; + await ((_a = provider.saveClientInformation) === null || _a === void 0 ? void 0 : _a.call(provider, clientInformation)); + } + else { + // Fallback to dynamic registration + if (!provider.saveClientInformation) { + throw new Error('OAuth client information must be saveable for dynamic registration'); + } + const fullInformation = await registerClient(authorizationServerUrl, { + metadata, + clientMetadata: provider.clientMetadata, + fetchFn + }); + await provider.saveClientInformation(fullInformation); + clientInformation = fullInformation; + } + } + // Non-interactive flows (e.g., client_credentials, jwt-bearer) don't need a redirect URL + const nonInteractiveFlow = !provider.redirectUrl; + // Exchange authorization code for tokens, or fetch tokens directly for non-interactive flows + if (authorizationCode !== undefined || nonInteractiveFlow) { + const tokens = await fetchToken(provider, authorizationServerUrl, { + metadata, + resource, + authorizationCode, + fetchFn + }); + await provider.saveTokens(tokens); + return 'AUTHORIZED'; + } + const tokens = await provider.tokens(); + // Handle token refresh or new authorization + if (tokens === null || tokens === void 0 ? void 0 : tokens.refresh_token) { + try { + // Attempt to refresh the token + const newTokens = await refreshAuthorization(authorizationServerUrl, { + metadata, + clientInformation, + refreshToken: tokens.refresh_token, + resource, + addClientAuthentication: provider.addClientAuthentication, + fetchFn + }); + await provider.saveTokens(newTokens); + return 'AUTHORIZED'; + } + catch (error) { + // If this is a ServerError, or an unknown type, log it out and try to continue. Otherwise, escalate so we can fix things and retry. + if (!(error instanceof OAuthError) || error instanceof ServerError) { + // Could not refresh OAuth tokens + } + else { + // Refresh failed for another reason, re-throw + throw error; + } + } + } + const state = provider.state ? await provider.state() : undefined; + // Start new authorization flow + const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, { + metadata, + clientInformation, + state, + redirectUrl: provider.redirectUrl, + scope: scope || ((_b = resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.scopes_supported) === null || _b === void 0 ? void 0 : _b.join(' ')) || provider.clientMetadata.scope, + resource + }); + await provider.saveCodeVerifier(codeVerifier); + await provider.redirectToAuthorization(authorizationUrl); + return 'REDIRECT'; +} +/** + * SEP-991: URL-based Client IDs + * Validate that the client_id is a valid URL with https scheme + */ +export function isHttpsUrl(value) { + if (!value) + return false; + try { + const url = new URL(value); + return url.protocol === 'https:' && url.pathname !== '/'; + } + catch (_a) { + return false; + } +} +export async function selectResourceURL(serverUrl, provider, resourceMetadata) { + const defaultResource = resourceUrlFromServerUrl(serverUrl); + // If provider has custom validation, delegate to it + if (provider.validateResourceURL) { + return await provider.validateResourceURL(defaultResource, resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.resource); + } + // Only include resource parameter when Protected Resource Metadata is present + if (!resourceMetadata) { + return undefined; + } + // Validate that the metadata's resource is compatible with our request + if (!checkResourceAllowed({ requestedResource: defaultResource, configuredResource: resourceMetadata.resource })) { + throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`); + } + // Prefer the resource from metadata since it's what the server is telling us to request + return new URL(resourceMetadata.resource); +} +/** + * Extract resource_metadata, scope, and error from WWW-Authenticate header. + */ +export function extractWWWAuthenticateParams(res) { + const authenticateHeader = res.headers.get('WWW-Authenticate'); + if (!authenticateHeader) { + return {}; + } + const [type, scheme] = authenticateHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !scheme) { + return {}; + } + const resourceMetadataMatch = extractFieldFromWwwAuth(res, 'resource_metadata') || undefined; + let resourceMetadataUrl; + if (resourceMetadataMatch) { + try { + resourceMetadataUrl = new URL(resourceMetadataMatch); + } + catch (_a) { + // Ignore invalid URL + } + } + const scope = extractFieldFromWwwAuth(res, 'scope') || undefined; + const error = extractFieldFromWwwAuth(res, 'error') || undefined; + return { + resourceMetadataUrl, + scope, + error + }; +} +/** + * Extracts a specific field's value from the WWW-Authenticate header string. + * + * @param response The HTTP response object containing the headers. + * @param fieldName The name of the field to extract (e.g., "realm", "nonce"). + * @returns The field value + */ +function extractFieldFromWwwAuth(response, fieldName) { + const wwwAuthHeader = response.headers.get('WWW-Authenticate'); + if (!wwwAuthHeader) { + return null; + } + const pattern = new RegExp(`${fieldName}=(?:"([^"]+)"|([^\\s,]+))`); + const match = wwwAuthHeader.match(pattern); + if (match) { + // Pattern matches: field_name="value" or field_name=value (unquoted) + return match[1] || match[2]; + } + return null; +} +/** + * Extract resource_metadata from response header. + * @deprecated Use `extractWWWAuthenticateParams` instead. + */ +export function extractResourceMetadataUrl(res) { + const authenticateHeader = res.headers.get('WWW-Authenticate'); + if (!authenticateHeader) { + return undefined; + } + const [type, scheme] = authenticateHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !scheme) { + return undefined; + } + const regex = /resource_metadata="([^"]*)"/; + const match = regex.exec(authenticateHeader); + if (!match) { + return undefined; + } + try { + return new URL(match[1]); + } + catch (_a) { + return undefined; + } +} +/** + * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + */ +export async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) { + var _a, _b; + const response = await discoverMetadataWithFallback(serverUrl, 'oauth-protected-resource', fetchFn, { + protocolVersion: opts === null || opts === void 0 ? void 0 : opts.protocolVersion, + metadataUrl: opts === null || opts === void 0 ? void 0 : opts.resourceMetadataUrl + }); + if (!response || response.status === 404) { + await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`); + } + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`); + } + return OAuthProtectedResourceMetadataSchema.parse(await response.json()); +} +/** + * Helper function to handle fetch with CORS retry logic + */ +async function fetchWithCorsRetry(url, headers, fetchFn = fetch) { + try { + return await fetchFn(url, { headers }); + } + catch (error) { + if (error instanceof TypeError) { + if (headers) { + // CORS errors come back as TypeError, retry without headers + return fetchWithCorsRetry(url, undefined, fetchFn); + } + else { + // We're getting CORS errors on retry too, return undefined + return undefined; + } + } + throw error; + } +} +/** + * Constructs the well-known path for auth-related metadata discovery + */ +function buildWellKnownPath(wellKnownPrefix, pathname = '', options = {}) { + // Strip trailing slash from pathname to avoid double slashes + if (pathname.endsWith('/')) { + pathname = pathname.slice(0, -1); + } + return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`; +} +/** + * Tries to discover OAuth metadata at a specific URL + */ +async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) { + const headers = { + 'MCP-Protocol-Version': protocolVersion + }; + return await fetchWithCorsRetry(url, headers, fetchFn); +} +/** + * Determines if fallback to root discovery should be attempted + */ +function shouldAttemptFallback(response, pathname) { + return !response || (response.status >= 400 && response.status < 500 && pathname !== '/'); +} +/** + * Generic function for discovering OAuth metadata with fallback support + */ +async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) { + var _a, _b; + const issuer = new URL(serverUrl); + const protocolVersion = (_a = opts === null || opts === void 0 ? void 0 : opts.protocolVersion) !== null && _a !== void 0 ? _a : LATEST_PROTOCOL_VERSION; + let url; + if (opts === null || opts === void 0 ? void 0 : opts.metadataUrl) { + url = new URL(opts.metadataUrl); + } + else { + // Try path-aware discovery first + const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname); + url = new URL(wellKnownPath, (_b = opts === null || opts === void 0 ? void 0 : opts.metadataServerUrl) !== null && _b !== void 0 ? _b : issuer); + url.search = issuer.search; + } + let response = await tryMetadataDiscovery(url, protocolVersion, fetchFn); + // If path-aware discovery fails with 404 and we're not already at root, try fallback to root discovery + if (!(opts === null || opts === void 0 ? void 0 : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) { + const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer); + response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn); + } + return response; +} +/** + * Looks up RFC 8414 OAuth 2.0 Authorization Server Metadata. + * + * If the server returns a 404 for the well-known endpoint, this function will + * return `undefined`. Any other errors will be thrown as exceptions. + * + * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`. + */ +export async function discoverOAuthMetadata(issuer, { authorizationServerUrl, protocolVersion } = {}, fetchFn = fetch) { + var _a, _b; + if (typeof issuer === 'string') { + issuer = new URL(issuer); + } + if (!authorizationServerUrl) { + authorizationServerUrl = issuer; + } + if (typeof authorizationServerUrl === 'string') { + authorizationServerUrl = new URL(authorizationServerUrl); + } + protocolVersion !== null && protocolVersion !== void 0 ? protocolVersion : (protocolVersion = LATEST_PROTOCOL_VERSION); + const response = await discoverMetadataWithFallback(authorizationServerUrl, 'oauth-authorization-server', fetchFn, { + protocolVersion, + metadataServerUrl: authorizationServerUrl + }); + if (!response || response.status === 404) { + await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + return undefined; + } + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`); + } + return OAuthMetadataSchema.parse(await response.json()); +} +/** + * Builds a list of discovery URLs to try for authorization server metadata. + * URLs are returned in priority order: + * 1. OAuth metadata at the given URL + * 2. OIDC metadata endpoints at the given URL + */ +export function buildDiscoveryUrls(authorizationServerUrl) { + const url = typeof authorizationServerUrl === 'string' ? new URL(authorizationServerUrl) : authorizationServerUrl; + const hasPath = url.pathname !== '/'; + const urlsToTry = []; + if (!hasPath) { + // Root path: https://example.com/.well-known/oauth-authorization-server + urlsToTry.push({ + url: new URL('/.well-known/oauth-authorization-server', url.origin), + type: 'oauth' + }); + // OIDC: https://example.com/.well-known/openid-configuration + urlsToTry.push({ + url: new URL(`/.well-known/openid-configuration`, url.origin), + type: 'oidc' + }); + return urlsToTry; + } + // Strip trailing slash from pathname to avoid double slashes + let pathname = url.pathname; + if (pathname.endsWith('/')) { + pathname = pathname.slice(0, -1); + } + // 1. OAuth metadata at the given URL + // Insert well-known before the path: https://example.com/.well-known/oauth-authorization-server/tenant1 + urlsToTry.push({ + url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url.origin), + type: 'oauth' + }); + // 2. OIDC metadata endpoints + // RFC 8414 style: Insert /.well-known/openid-configuration before the path + urlsToTry.push({ + url: new URL(`/.well-known/openid-configuration${pathname}`, url.origin), + type: 'oidc' + }); + // OIDC Discovery 1.0 style: Append /.well-known/openid-configuration after the path + urlsToTry.push({ + url: new URL(`${pathname}/.well-known/openid-configuration`, url.origin), + type: 'oidc' + }); + return urlsToTry; +} +/** + * Discovers authorization server metadata with support for RFC 8414 OAuth 2.0 Authorization Server Metadata + * and OpenID Connect Discovery 1.0 specifications. + * + * This function implements a fallback strategy for authorization server discovery: + * 1. Attempts RFC 8414 OAuth metadata discovery first + * 2. If OAuth discovery fails, falls back to OpenID Connect Discovery + * + * @param authorizationServerUrl - The authorization server URL obtained from the MCP Server's + * protected resource metadata, or the MCP server's URL if the + * metadata was not found. + * @param options - Configuration options + * @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch + * @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION + * @returns Promise resolving to authorization server metadata, or undefined if discovery fails + */ +export async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) { + var _a; + const headers = { + 'MCP-Protocol-Version': protocolVersion, + Accept: 'application/json' + }; + // Get the list of URLs to try + const urlsToTry = buildDiscoveryUrls(authorizationServerUrl); + // Try each URL in order + for (const { url: endpointUrl, type } of urlsToTry) { + const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn); + if (!response) { + /** + * CORS error occurred - don't throw as the endpoint may not allow CORS, + * continue trying other possible endpoints + */ + continue; + } + if (!response.ok) { + await ((_a = response.body) === null || _a === void 0 ? void 0 : _a.cancel()); + // Continue looking for any 4xx response code. + if (response.status >= 400 && response.status < 500) { + continue; // Try next URL + } + throw new Error(`HTTP ${response.status} trying to load ${type === 'oauth' ? 'OAuth' : 'OpenID provider'} metadata from ${endpointUrl}`); + } + // Parse and validate based on type + if (type === 'oauth') { + return OAuthMetadataSchema.parse(await response.json()); + } + else { + return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json()); + } + } + return undefined; +} +/** + * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL. + */ +export async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) { + let authorizationUrl; + if (metadata) { + authorizationUrl = new URL(metadata.authorization_endpoint); + if (!metadata.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) { + throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`); + } + if (metadata.code_challenge_methods_supported && + !metadata.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) { + throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`); + } + } + else { + authorizationUrl = new URL('/authorize', authorizationServerUrl); + } + // Generate PKCE challenge + const challenge = await pkceChallenge(); + const codeVerifier = challenge.code_verifier; + const codeChallenge = challenge.code_challenge; + authorizationUrl.searchParams.set('response_type', AUTHORIZATION_CODE_RESPONSE_TYPE); + authorizationUrl.searchParams.set('client_id', clientInformation.client_id); + authorizationUrl.searchParams.set('code_challenge', codeChallenge); + authorizationUrl.searchParams.set('code_challenge_method', AUTHORIZATION_CODE_CHALLENGE_METHOD); + authorizationUrl.searchParams.set('redirect_uri', String(redirectUrl)); + if (state) { + authorizationUrl.searchParams.set('state', state); + } + if (scope) { + authorizationUrl.searchParams.set('scope', scope); + } + if (scope === null || scope === void 0 ? void 0 : scope.includes('offline_access')) { + // if the request includes the OIDC-only "offline_access" scope, + // we need to set the prompt to "consent" to ensure the user is prompted to grant offline access + // https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess + authorizationUrl.searchParams.append('prompt', 'consent'); + } + if (resource) { + authorizationUrl.searchParams.set('resource', resource.href); + } + return { authorizationUrl, codeVerifier }; +} +/** + * Prepares token request parameters for an authorization code exchange. + * + * This is the default implementation used by fetchToken when the provider + * doesn't implement prepareTokenRequest. + * + * @param authorizationCode - The authorization code received from the authorization endpoint + * @param codeVerifier - The PKCE code verifier + * @param redirectUri - The redirect URI used in the authorization request + * @returns URLSearchParams for the authorization_code grant + */ +export function prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri) { + return new URLSearchParams({ + grant_type: 'authorization_code', + code: authorizationCode, + code_verifier: codeVerifier, + redirect_uri: String(redirectUri) + }); +} +/** + * Internal helper to execute a token request with the given parameters. + * Used by exchangeAuthorization, refreshAuthorization, and fetchToken. + */ +async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequestParams, clientInformation, addClientAuthentication, resource, fetchFn }) { + var _a; + const tokenUrl = (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL('/token', authorizationServerUrl); + const headers = new Headers({ + 'Content-Type': 'application/x-www-form-urlencoded', + Accept: 'application/json' + }); + if (resource) { + tokenRequestParams.set('resource', resource.href); + } + if (addClientAuthentication) { + await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata); + } + else if (clientInformation) { + const supportedMethods = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint_auth_methods_supported) !== null && _a !== void 0 ? _a : []; + const authMethod = selectClientAuthMethod(clientInformation, supportedMethods); + applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams); + } + const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(tokenUrl, { + method: 'POST', + headers, + body: tokenRequestParams + }); + if (!response.ok) { + throw await parseErrorResponse(response); + } + return OAuthTokensSchema.parse(await response.json()); +} +/** + * Exchanges an authorization code for an access token with the given server. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Falls back to appropriate defaults when server metadata is unavailable + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, auth code, etc. + * @returns Promise resolving to OAuth tokens + * @throws {Error} When token exchange fails or authentication is invalid + */ +export async function exchangeAuthorization(authorizationServerUrl, { metadata, clientInformation, authorizationCode, codeVerifier, redirectUri, resource, addClientAuthentication, fetchFn }) { + const tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, redirectUri); + return executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation, + addClientAuthentication, + resource, + fetchFn + }); +} +/** + * Exchange a refresh token for an updated access token. + * + * Supports multiple client authentication methods as specified in OAuth 2.1: + * - Automatically selects the best authentication method based on server support + * - Preserves the original refresh token if a new one is not returned + * + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration object containing client info, refresh token, etc. + * @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced) + * @throws {Error} When token refresh fails or authentication is invalid + */ +export async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) { + const tokenRequestParams = new URLSearchParams({ + grant_type: 'refresh_token', + refresh_token: refreshToken + }); + const tokens = await executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation, + addClientAuthentication, + resource, + fetchFn + }); + // Preserve original refresh token if server didn't return a new one + return { refresh_token: refreshToken, ...tokens }; +} +/** + * Unified token fetching that works with any grant type via provider.prepareTokenRequest(). + * + * This function provides a single entry point for obtaining tokens regardless of the + * OAuth grant type. The provider's prepareTokenRequest() method determines which grant + * to use and supplies the grant-specific parameters. + * + * @param provider - OAuth client provider that implements prepareTokenRequest() + * @param authorizationServerUrl - The authorization server's base URL + * @param options - Configuration for the token request + * @returns Promise resolving to OAuth tokens + * @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails + * + * @example + * // Provider for client_credentials: + * class MyProvider implements OAuthClientProvider { + * prepareTokenRequest(scope) { + * const params = new URLSearchParams({ grant_type: 'client_credentials' }); + * if (scope) params.set('scope', scope); + * return params; + * } + * // ... other methods + * } + * + * const tokens = await fetchToken(provider, authServerUrl, { metadata }); + */ +export async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) { + const scope = provider.clientMetadata.scope; + // Use provider's prepareTokenRequest if available, otherwise fall back to authorization_code + let tokenRequestParams; + if (provider.prepareTokenRequest) { + tokenRequestParams = await provider.prepareTokenRequest(scope); + } + // Default to authorization_code grant if no custom prepareTokenRequest + if (!tokenRequestParams) { + if (!authorizationCode) { + throw new Error('Either provider.prepareTokenRequest() or authorizationCode is required'); + } + if (!provider.redirectUrl) { + throw new Error('redirectUrl is required for authorization_code flow'); + } + const codeVerifier = await provider.codeVerifier(); + tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl); + } + const clientInformation = await provider.clientInformation(); + return executeTokenRequest(authorizationServerUrl, { + metadata, + tokenRequestParams, + clientInformation: clientInformation !== null && clientInformation !== void 0 ? clientInformation : undefined, + addClientAuthentication: provider.addClientAuthentication, + resource, + fetchFn + }); +} +/** + * Performs OAuth 2.0 Dynamic Client Registration according to RFC 7591. + */ +export async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) { + let registrationUrl; + if (metadata) { + if (!metadata.registration_endpoint) { + throw new Error('Incompatible auth server: does not support dynamic client registration'); + } + registrationUrl = new URL(metadata.registration_endpoint); + } + else { + registrationUrl = new URL('/register', authorizationServerUrl); + } + const response = await (fetchFn !== null && fetchFn !== void 0 ? fetchFn : fetch)(registrationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(clientMetadata) + }); + if (!response.ok) { + throw await parseErrorResponse(response); + } + return OAuthClientInformationFullSchema.parse(await response.json()); +} +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/dist/esm/client/auth.js.map b/dist/esm/client/auth.js.map new file mode 100644 index 000000000..b5c3db804 --- /dev/null +++ b/dist/esm/client/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../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diff --git a/dist/esm/client/index.d.ts b/dist/esm/client/index.d.ts new file mode 100644 index 000000000..cb81a4123 --- /dev/null +++ b/dist/esm/client/index.d.ts @@ -0,0 +1,481 @@ +import { Protocol, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js'; +import type { Transport } from '../shared/transport.js'; +import { type CallToolRequest, CallToolResultSchema, type ClientCapabilities, type ClientNotification, type ClientRequest, type ClientResult, type CompatibilityCallToolResultSchema, type CompleteRequest, type GetPromptRequest, type Implementation, type ListPromptsRequest, type ListResourcesRequest, type ListResourceTemplatesRequest, type ListToolsRequest, type LoggingLevel, type Notification, type ReadResourceRequest, type Request, type Result, type ServerCapabilities, type SubscribeRequest, type UnsubscribeRequest } from '../types.js'; +import type { jsonSchemaValidator } from '../validation/types.js'; +import { AnyObjectSchema, SchemaOutput } from '../server/zod-compat.js'; +import type { RequestHandlerExtra } from '../shared/protocol.js'; +import { ExperimentalClientTasks } from '../experimental/tasks/client.js'; +/** + * Determines which elicitation modes are supported based on declared client capabilities. + * + * According to the spec: + * - An empty elicitation capability object defaults to form mode support (backwards compatibility) + * - URL mode is only supported if explicitly declared + * + * @param capabilities - The client's elicitation capabilities + * @returns An object indicating which modes are supported + */ +export declare function getSupportedElicitationModes(capabilities: ClientCapabilities['elicitation']): { + supportsFormMode: boolean; + supportsUrlMode: boolean; +}; +export type ClientOptions = ProtocolOptions & { + /** + * Capabilities to advertise as being supported by this client. + */ + capabilities?: ClientCapabilities; + /** + * JSON Schema validator for tool output validation. + * + * The validator is used to validate structured content returned by tools + * against their declared output schemas. + * + * @default AjvJsonSchemaValidator + * + * @example + * ```typescript + * // ajv + * const client = new Client( + * { name: 'my-client', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new AjvJsonSchemaValidator() + * } + * ); + * + * // @cfworker/json-schema + * const client = new Client( + * { name: 'my-client', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new CfWorkerJsonSchemaValidator() + * } + * ); + * ``` + */ + jsonSchemaValidator?: jsonSchemaValidator; +}; +/** + * An MCP client on top of a pluggable transport. + * + * The client will automatically begin the initialization flow with the server when connect() is called. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed client + * const client = new Client({ + * name: "CustomClient", + * version: "1.0.0" + * }) + * ``` + */ +export declare class Client extends Protocol { + private _clientInfo; + private _serverCapabilities?; + private _serverVersion?; + private _capabilities; + private _instructions?; + private _jsonSchemaValidator; + private _cachedToolOutputValidators; + private _cachedKnownTaskTools; + private _cachedRequiredTaskTools; + private _experimental?; + /** + * Initializes this client with the given name and version information. + */ + constructor(_clientInfo: Implementation, options?: ClientOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalClientTasks; + }; + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities: ClientCapabilities): void; + /** + * Override request handler registration to enforce client-side validation for elicitation. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => ClientResult | ResultT | Promise): void; + protected assertCapability(capability: keyof ServerCapabilities, method: string): void; + connect(transport: Transport, options?: RequestOptions): Promise; + /** + * After initialization has completed, this will be populated with the server's reported capabilities. + */ + getServerCapabilities(): ServerCapabilities | undefined; + /** + * After initialization has completed, this will be populated with information about the server's name and version. + */ + getServerVersion(): Implementation | undefined; + /** + * After initialization has completed, this may be populated with information about the server's instructions. + */ + getInstructions(): string | undefined; + protected assertCapabilityForMethod(method: RequestT['method']): void; + protected assertNotificationCapability(method: NotificationT['method']): void; + protected assertRequestHandlerCapability(method: string): void; + protected assertTaskCapability(method: string): void; + protected assertTaskHandlerCapability(method: string): void; + ping(options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + complete(params: CompleteRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + completion: { + [x: string]: unknown; + values: string[]; + total?: number | undefined; + hasMore?: boolean | undefined; + }; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + setLoggingLevel(level: LoggingLevel, options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + getPrompt(params: GetPromptRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + messages: { + role: "user" | "assistant"; + content: { + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + description?: string | undefined; + }>; + listPrompts(params?: ListPromptsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + prompts: { + name: string; + description?: string | undefined; + arguments?: { + name: string; + description?: string | undefined; + required?: boolean | undefined; + }[] | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + listResources(params?: ListResourcesRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + resources: { + uri: string; + name: string; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + listResourceTemplates(params?: ListResourceTemplatesRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + resourceTemplates: { + uriTemplate: string; + name: string; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + readResource(params: ReadResourceRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + contents: ({ + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + subscribeResource(params: SubscribeRequest['params'], options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + unsubscribeResource(params: UnsubscribeRequest['params'], options?: RequestOptions): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + /** + * Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema. + * + * For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead. + */ + callTool(params: CallToolRequest['params'], resultSchema?: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema, options?: RequestOptions): Promise<{ + [x: string]: unknown; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + structuredContent?: Record | undefined; + isError?: boolean | undefined; + } | { + [x: string]: unknown; + toolResult: unknown; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + private isToolTask; + /** + * Check if a tool requires task-based execution. + * Unlike isToolTask which includes 'optional' tools, this only checks for 'required'. + */ + private isToolTaskRequired; + /** + * Cache validators for tool output schemas. + * Called after listTools() to pre-compile validators for better performance. + */ + private cacheToolMetadata; + /** + * Get cached validator for a tool + */ + private getToolOutputValidator; + listTools(params?: ListToolsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + tools: { + inputSchema: { + [x: string]: unknown; + type: "object"; + properties?: Record | undefined; + required?: string[] | undefined; + }; + name: string; + description?: string | undefined; + outputSchema?: { + [x: string]: unknown; + type: "object"; + properties?: Record | undefined; + required?: string[] | undefined; + } | undefined; + annotations?: { + title?: string | undefined; + readOnlyHint?: boolean | undefined; + destructiveHint?: boolean | undefined; + idempotentHint?: boolean | undefined; + openWorldHint?: boolean | undefined; + } | undefined; + execution?: { + taskSupport?: "optional" | "required" | "forbidden" | undefined; + } | undefined; + _meta?: Record | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + nextCursor?: string | undefined; + }>; + sendRootsListChanged(): Promise; +} +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/index.d.ts.map b/dist/esm/client/index.d.ts.map new file mode 100644 index 000000000..a0df292e3 --- /dev/null +++ b/dist/esm/client/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EACH,KAAK,eAAe,EACpB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iCAAiC,EACtC,KAAK,eAAe,EAIpB,KAAK,gBAAgB,EAErB,KAAK,cAAc,EAGnB,KAAK,kBAAkB,EAEvB,KAAK,oBAAoB,EAEzB,KAAK,4B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AmB,CAAC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;IAIxF;;;;OAIG;IACG,QAAQ,CACV,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,EACjC,YAAY,GAAE,OAAO,oBAAoB,GAAG,OAAO,iCAAwD,EAC3G,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkD5B,OAAO,CAAC,UAAU;IAQlB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAuBzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAIxB,SAAS,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IASvE,oBAAoB;CAG7B"} \ No newline at end of file diff --git a/dist/esm/client/index.js b/dist/esm/client/index.js new file mode 100644 index 000000000..74f583805 --- /dev/null +++ b/dist/esm/client/index.js @@ -0,0 +1,541 @@ +import { mergeCapabilities, Protocol } from '../shared/protocol.js'; +import { CallToolResultSchema, CompleteResultSchema, EmptyResultSchema, ErrorCode, GetPromptResultSchema, InitializeResultSchema, LATEST_PROTOCOL_VERSION, ListPromptsResultSchema, ListResourcesResultSchema, ListResourceTemplatesResultSchema, ListToolsResultSchema, McpError, ReadResourceResultSchema, SUPPORTED_PROTOCOL_VERSIONS, ElicitResultSchema, ElicitRequestSchema, CreateTaskResultSchema, CreateMessageRequestSchema, CreateMessageResultSchema } from '../types.js'; +import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js'; +import { getObjectShape, isZ4Schema, safeParse } from '../server/zod-compat.js'; +import { ExperimentalClientTasks } from '../experimental/tasks/client.js'; +import { assertToolsCallTaskCapability, assertClientRequestTaskCapability } from '../experimental/tasks/helpers.js'; +/** + * Elicitation default application helper. Applies defaults to the data based on the schema. + * + * @param schema - The schema to apply defaults to. + * @param data - The data to apply defaults to. + */ +function applyElicitationDefaults(schema, data) { + if (!schema || data === null || typeof data !== 'object') + return; + // Handle object properties + if (schema.type === 'object' && schema.properties && typeof schema.properties === 'object') { + const obj = data; + const props = schema.properties; + for (const key of Object.keys(props)) { + const propSchema = props[key]; + // If missing or explicitly undefined, apply default if present + if (obj[key] === undefined && Object.prototype.hasOwnProperty.call(propSchema, 'default')) { + obj[key] = propSchema.default; + } + // Recurse into existing nested objects/arrays + if (obj[key] !== undefined) { + applyElicitationDefaults(propSchema, obj[key]); + } + } + } + if (Array.isArray(schema.anyOf)) { + for (const sub of schema.anyOf) { + applyElicitationDefaults(sub, data); + } + } + // Combine schemas + if (Array.isArray(schema.oneOf)) { + for (const sub of schema.oneOf) { + applyElicitationDefaults(sub, data); + } + } +} +/** + * Determines which elicitation modes are supported based on declared client capabilities. + * + * According to the spec: + * - An empty elicitation capability object defaults to form mode support (backwards compatibility) + * - URL mode is only supported if explicitly declared + * + * @param capabilities - The client's elicitation capabilities + * @returns An object indicating which modes are supported + */ +export function getSupportedElicitationModes(capabilities) { + if (!capabilities) { + return { supportsFormMode: false, supportsUrlMode: false }; + } + const hasFormCapability = capabilities.form !== undefined; + const hasUrlCapability = capabilities.url !== undefined; + // If neither form nor url are explicitly declared, form mode is supported (backwards compatibility) + const supportsFormMode = hasFormCapability || (!hasFormCapability && !hasUrlCapability); + const supportsUrlMode = hasUrlCapability; + return { supportsFormMode, supportsUrlMode }; +} +/** + * An MCP client on top of a pluggable transport. + * + * The client will automatically begin the initialization flow with the server when connect() is called. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed client + * const client = new Client({ + * name: "CustomClient", + * version: "1.0.0" + * }) + * ``` + */ +export class Client extends Protocol { + /** + * Initializes this client with the given name and version information. + */ + constructor(_clientInfo, options) { + var _a, _b; + super(options); + this._clientInfo = _clientInfo; + this._cachedToolOutputValidators = new Map(); + this._cachedKnownTaskTools = new Set(); + this._cachedRequiredTaskTools = new Set(); + this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {}; + this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new AjvJsonSchemaValidator(); + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new ExperimentalClientTasks(this) + }; + } + return this._experimental; + } + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities) { + if (this.transport) { + throw new Error('Cannot register capabilities after connecting to transport'); + } + this._capabilities = mergeCapabilities(this._capabilities, capabilities); + } + /** + * Override request handler registration to enforce client-side validation for elicitation. + */ + setRequestHandler(requestSchema, handler) { + var _a, _b, _c; + const shape = getObjectShape(requestSchema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value using type-safe property access + let methodValue; + if (isZ4Schema(methodSchema)) { + const v4Schema = methodSchema; + const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + methodValue = (_b = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b !== void 0 ? _b : v4Schema.value; + } + else { + const v3Schema = methodSchema; + const legacyDef = v3Schema._def; + methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value; + } + if (typeof methodValue !== 'string') { + throw new Error('Schema method literal must be a string'); + } + const method = methodValue; + if (method === 'elicitation/create') { + const wrappedHandler = async (request, extra) => { + var _a, _b, _c; + const validatedRequest = safeParse(ElicitRequestSchema, request); + if (!validatedRequest.success) { + // Type guard: if success is false, error is guaranteed to exist + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const mode = (_a = params.mode) !== null && _a !== void 0 ? _a : 'form'; + const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation); + if (mode === 'form' && !supportsFormMode) { + throw new McpError(ErrorCode.InvalidParams, 'Client does not support form-mode elicitation requests'); + } + if (mode === 'url' && !supportsUrlMode) { + throw new McpError(ErrorCode.InvalidParams, 'Client does not support URL-mode elicitation requests'); + } + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = safeParse(CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against ElicitResultSchema + const validationResult = safeParse(ElicitResultSchema, result); + if (!validationResult.success) { + // Type guard: if success is false, error is guaranteed to exist + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`); + } + const validatedResult = validationResult.data; + const requestedSchema = mode === 'form' ? params.requestedSchema : undefined; + if (mode === 'form' && validatedResult.action === 'accept' && validatedResult.content && requestedSchema) { + if ((_c = (_b = this._capabilities.elicitation) === null || _b === void 0 ? void 0 : _b.form) === null || _c === void 0 ? void 0 : _c.applyDefaults) { + try { + applyElicitationDefaults(requestedSchema, validatedResult.content); + } + catch (_d) { + // gracefully ignore errors in default application + } + } + } + return validatedResult; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + if (method === 'sampling/createMessage') { + const wrappedHandler = async (request, extra) => { + const validatedRequest = safeParse(CreateMessageRequestSchema, request); + if (!validatedRequest.success) { + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = safeParse(CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against CreateMessageResultSchema + const validationResult = safeParse(CreateMessageResultSchema, result); + if (!validationResult.success) { + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`); + } + return validationResult.data; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + // Other handlers use default behavior + return super.setRequestHandler(requestSchema, handler); + } + assertCapability(capability, method) { + var _a; + if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) { + throw new Error(`Server does not support ${capability} (required for ${method})`); + } + } + async connect(transport, options) { + await super.connect(transport); + // When transport sessionId is already set this means we are trying to reconnect. + // In this case we don't need to initialize again. + if (transport.sessionId !== undefined) { + return; + } + try { + const result = await this.request({ + method: 'initialize', + params: { + protocolVersion: LATEST_PROTOCOL_VERSION, + capabilities: this._capabilities, + clientInfo: this._clientInfo + } + }, InitializeResultSchema, options); + if (result === undefined) { + throw new Error(`Server sent invalid initialize result: ${result}`); + } + if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) { + throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`); + } + this._serverCapabilities = result.capabilities; + this._serverVersion = result.serverInfo; + // HTTP transports must set the protocol version in each header after initialization. + if (transport.setProtocolVersion) { + transport.setProtocolVersion(result.protocolVersion); + } + this._instructions = result.instructions; + await this.notification({ + method: 'notifications/initialized' + }); + } + catch (error) { + // Disconnect if initialization fails. + void this.close(); + throw error; + } + } + /** + * After initialization has completed, this will be populated with the server's reported capabilities. + */ + getServerCapabilities() { + return this._serverCapabilities; + } + /** + * After initialization has completed, this will be populated with information about the server's name and version. + */ + getServerVersion() { + return this._serverVersion; + } + /** + * After initialization has completed, this may be populated with information about the server's instructions. + */ + getInstructions() { + return this._instructions; + } + assertCapabilityForMethod(method) { + var _a, _b, _c, _d, _e; + switch (method) { + case 'logging/setLevel': + if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.logging)) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'prompts/get': + case 'prompts/list': + if (!((_b = this._serverCapabilities) === null || _b === void 0 ? void 0 : _b.prompts)) { + throw new Error(`Server does not support prompts (required for ${method})`); + } + break; + case 'resources/list': + case 'resources/templates/list': + case 'resources/read': + case 'resources/subscribe': + case 'resources/unsubscribe': + if (!((_c = this._serverCapabilities) === null || _c === void 0 ? void 0 : _c.resources)) { + throw new Error(`Server does not support resources (required for ${method})`); + } + if (method === 'resources/subscribe' && !this._serverCapabilities.resources.subscribe) { + throw new Error(`Server does not support resource subscriptions (required for ${method})`); + } + break; + case 'tools/call': + case 'tools/list': + if (!((_d = this._serverCapabilities) === null || _d === void 0 ? void 0 : _d.tools)) { + throw new Error(`Server does not support tools (required for ${method})`); + } + break; + case 'completion/complete': + if (!((_e = this._serverCapabilities) === null || _e === void 0 ? void 0 : _e.completions)) { + throw new Error(`Server does not support completions (required for ${method})`); + } + break; + case 'initialize': + // No specific capability required for initialize + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertNotificationCapability(method) { + var _a; + switch (method) { + case 'notifications/roots/list_changed': + if (!((_a = this._capabilities.roots) === null || _a === void 0 ? void 0 : _a.listChanged)) { + throw new Error(`Client does not support roots list changed notifications (required for ${method})`); + } + break; + case 'notifications/initialized': + // No specific capability required for initialized + break; + case 'notifications/cancelled': + // Cancellation notifications are always allowed + break; + case 'notifications/progress': + // Progress notifications are always allowed + break; + } + } + assertRequestHandlerCapability(method) { + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + switch (method) { + case 'sampling/createMessage': + if (!this._capabilities.sampling) { + throw new Error(`Client does not support sampling capability (required for ${method})`); + } + break; + case 'elicitation/create': + if (!this._capabilities.elicitation) { + throw new Error(`Client does not support elicitation capability (required for ${method})`); + } + break; + case 'roots/list': + if (!this._capabilities.roots) { + throw new Error(`Client does not support roots capability (required for ${method})`); + } + break; + case 'tasks/get': + case 'tasks/list': + case 'tasks/result': + case 'tasks/cancel': + if (!this._capabilities.tasks) { + throw new Error(`Client does not support tasks capability (required for ${method})`); + } + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertTaskCapability(method) { + var _a, _b; + assertToolsCallTaskCapability((_b = (_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests, method, 'Server'); + } + assertTaskHandlerCapability(method) { + var _a; + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + assertClientRequestTaskCapability((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, 'Client'); + } + async ping(options) { + return this.request({ method: 'ping' }, EmptyResultSchema, options); + } + async complete(params, options) { + return this.request({ method: 'completion/complete', params }, CompleteResultSchema, options); + } + async setLoggingLevel(level, options) { + return this.request({ method: 'logging/setLevel', params: { level } }, EmptyResultSchema, options); + } + async getPrompt(params, options) { + return this.request({ method: 'prompts/get', params }, GetPromptResultSchema, options); + } + async listPrompts(params, options) { + return this.request({ method: 'prompts/list', params }, ListPromptsResultSchema, options); + } + async listResources(params, options) { + return this.request({ method: 'resources/list', params }, ListResourcesResultSchema, options); + } + async listResourceTemplates(params, options) { + return this.request({ method: 'resources/templates/list', params }, ListResourceTemplatesResultSchema, options); + } + async readResource(params, options) { + return this.request({ method: 'resources/read', params }, ReadResourceResultSchema, options); + } + async subscribeResource(params, options) { + return this.request({ method: 'resources/subscribe', params }, EmptyResultSchema, options); + } + async unsubscribeResource(params, options) { + return this.request({ method: 'resources/unsubscribe', params }, EmptyResultSchema, options); + } + /** + * Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema. + * + * For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead. + */ + async callTool(params, resultSchema = CallToolResultSchema, options) { + // Guard: required-task tools need experimental API + if (this.isToolTaskRequired(params.name)) { + throw new McpError(ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`); + } + const result = await this.request({ method: 'tools/call', params }, resultSchema, options); + // Check if the tool has an outputSchema + const validator = this.getToolOutputValidator(params.name); + if (validator) { + // If tool has outputSchema, it MUST return structuredContent (unless it's an error) + if (!result.structuredContent && !result.isError) { + throw new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`); + } + // Only validate structured content if present (not when there's an error) + if (result.structuredContent) { + try { + // Validate the structured content against the schema + const validationResult = validator(result.structuredContent); + if (!validationResult.valid) { + throw new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`); + } + } + catch (error) { + if (error instanceof McpError) { + throw error; + } + throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`); + } + } + } + return result; + } + isToolTask(toolName) { + var _a, _b, _c, _d; + if (!((_d = (_c = (_b = (_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests) === null || _c === void 0 ? void 0 : _c.tools) === null || _d === void 0 ? void 0 : _d.call)) { + return false; + } + return this._cachedKnownTaskTools.has(toolName); + } + /** + * Check if a tool requires task-based execution. + * Unlike isToolTask which includes 'optional' tools, this only checks for 'required'. + */ + isToolTaskRequired(toolName) { + return this._cachedRequiredTaskTools.has(toolName); + } + /** + * Cache validators for tool output schemas. + * Called after listTools() to pre-compile validators for better performance. + */ + cacheToolMetadata(tools) { + var _a; + this._cachedToolOutputValidators.clear(); + this._cachedKnownTaskTools.clear(); + this._cachedRequiredTaskTools.clear(); + for (const tool of tools) { + // If the tool has an outputSchema, create and cache the validator + if (tool.outputSchema) { + const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema); + this._cachedToolOutputValidators.set(tool.name, toolValidator); + } + // If the tool supports task-based execution, cache that information + const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport; + if (taskSupport === 'required' || taskSupport === 'optional') { + this._cachedKnownTaskTools.add(tool.name); + } + if (taskSupport === 'required') { + this._cachedRequiredTaskTools.add(tool.name); + } + } + } + /** + * Get cached validator for a tool + */ + getToolOutputValidator(toolName) { + return this._cachedToolOutputValidators.get(toolName); + } + async listTools(params, options) { + const result = await this.request({ method: 'tools/list', params }, ListToolsResultSchema, options); + // Cache the tools and their output schemas for future validation + this.cacheToolMetadata(result.tools); + return result; + } + async sendRootsListChanged() { + return this.notification({ method: 'notifications/roots/list_changed' }); + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/client/index.js.map b/dist/esm/client/index.js.map new file mode 100644 index 000000000..0102c4d00 --- /dev/null +++ b/dist/esm/client/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAA6C,MAAM,uBAAuB,CAAC;AAG/G,OAAO,EAEH,oBAAoB,EAOpB,oBAAoB,E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CAAC;YAC9C,CAAC;YACD,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;gBAC7B,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACK,sBAAsB,CAAC,QAAgB;QAC3C,OAAO,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAmC,EAAE,OAAwB;QACzE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;QAEpG,iEAAiE;QACjE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,oBAAoB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,kCAAkC,EAAE,CAAC,CAAC;IAC7E,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/client/middleware.d.ts b/dist/esm/client/middleware.d.ts new file mode 100644 index 000000000..726ac578a --- /dev/null +++ b/dist/esm/client/middleware.d.ts @@ -0,0 +1,169 @@ +import { OAuthClientProvider } from './auth.js'; +import { FetchLike } from '../shared/transport.js'; +/** + * Middleware function that wraps and enhances fetch functionality. + * Takes a fetch handler and returns an enhanced fetch handler. + */ +export type Middleware = (next: FetchLike) => FetchLike; +/** + * Creates a fetch wrapper that handles OAuth authentication automatically. + * + * This wrapper will: + * - Add Authorization headers with access tokens + * - Handle 401 responses by attempting re-authentication + * - Retry the original request after successful auth + * - Handle OAuth errors appropriately (InvalidClientError, etc.) + * + * The baseUrl parameter is optional and defaults to using the domain from the request URL. + * However, you should explicitly provide baseUrl when: + * - Making requests to multiple subdomains (e.g., api.example.com, cdn.example.com) + * - Using API paths that differ from OAuth discovery paths (e.g., requesting /api/v1/data but OAuth is at /) + * - The OAuth server is on a different domain than your API requests + * - You want to ensure consistent OAuth behavior regardless of request URLs + * + * For MCP transports, set baseUrl to the same URL you pass to the transport constructor. + * + * Note: This wrapper is designed for general-purpose fetch operations. + * MCP transports (SSE and StreamableHTTP) already have built-in OAuth handling + * and should not need this wrapper. + * + * @param provider - OAuth client provider for authentication + * @param baseUrl - Base URL for OAuth server discovery (defaults to request URL domain) + * @returns A fetch middleware function + */ +export declare const withOAuth: (provider: OAuthClientProvider, baseUrl?: string | URL) => Middleware; +/** + * Logger function type for HTTP requests + */ +export type RequestLogger = (input: { + method: string; + url: string | URL; + status: number; + statusText: string; + duration: number; + requestHeaders?: Headers; + responseHeaders?: Headers; + error?: Error; +}) => void; +/** + * Configuration options for the logging middleware + */ +export type LoggingOptions = { + /** + * Custom logger function, defaults to console logging + */ + logger?: RequestLogger; + /** + * Whether to include request headers in logs + * @default false + */ + includeRequestHeaders?: boolean; + /** + * Whether to include response headers in logs + * @default false + */ + includeResponseHeaders?: boolean; + /** + * Status level filter - only log requests with status >= this value + * Set to 0 to log all requests, 400 to log only errors + * @default 0 + */ + statusLevel?: number; +}; +/** + * Creates a fetch middleware that logs HTTP requests and responses. + * + * When called without arguments `withLogging()`, it uses the default logger that: + * - Logs successful requests (2xx) to `console.log` + * - Logs error responses (4xx/5xx) and network errors to `console.error` + * - Logs all requests regardless of status (statusLevel: 0) + * - Does not include request or response headers in logs + * - Measures and displays request duration in milliseconds + * + * Important: the default logger uses both `console.log` and `console.error` so it should not be used with + * `stdio` transports and applications. + * + * @param options - Logging configuration options + * @returns A fetch middleware function + */ +export declare const withLogging: (options?: LoggingOptions) => Middleware; +/** + * Composes multiple fetch middleware functions into a single middleware pipeline. + * Middleware are applied in the order they appear, creating a chain of handlers. + * + * @example + * ```typescript + * // Create a middleware pipeline that handles both OAuth and logging + * const enhancedFetch = applyMiddlewares( + * withOAuth(oauthProvider, 'https://api.example.com'), + * withLogging({ statusLevel: 400 }) + * )(fetch); + * + * // Use the enhanced fetch - it will handle auth and log errors + * const response = await enhancedFetch('https://api.example.com/data'); + * ``` + * + * @param middleware - Array of fetch middleware to compose into a pipeline + * @returns A single composed middleware function + */ +export declare const applyMiddlewares: (...middleware: Middleware[]) => Middleware; +/** + * Helper function to create custom fetch middleware with cleaner syntax. + * Provides the next handler and request details as separate parameters for easier access. + * + * @example + * ```typescript + * // Create custom authentication middleware + * const customAuthMiddleware = createMiddleware(async (next, input, init) => { + * const headers = new Headers(init?.headers); + * headers.set('X-Custom-Auth', 'my-token'); + * + * const response = await next(input, { ...init, headers }); + * + * if (response.status === 401) { + * console.log('Authentication failed'); + * } + * + * return response; + * }); + * + * // Create conditional middleware + * const conditionalMiddleware = createMiddleware(async (next, input, init) => { + * const url = typeof input === 'string' ? input : input.toString(); + * + * // Only add headers for API routes + * if (url.includes('/api/')) { + * const headers = new Headers(init?.headers); + * headers.set('X-API-Version', 'v2'); + * return next(input, { ...init, headers }); + * } + * + * // Pass through for non-API routes + * return next(input, init); + * }); + * + * // Create caching middleware + * const cacheMiddleware = createMiddleware(async (next, input, init) => { + * const cacheKey = typeof input === 'string' ? input : input.toString(); + * + * // Check cache first + * const cached = await getFromCache(cacheKey); + * if (cached) { + * return new Response(cached, { status: 200 }); + * } + * + * // Make request and cache result + * const response = await next(input, init); + * if (response.ok) { + * await saveToCache(cacheKey, await response.clone().text()); + * } + * + * return response; + * }); + * ``` + * + * @param handler - Function that receives the next handler and request parameters + * @returns A fetch middleware function + */ +export declare const createMiddleware: (handler: (next: FetchLike, input: string | URL, init?: RequestInit) => Promise) => Middleware; +//# sourceMappingURL=middleware.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/middleware.d.ts.map b/dist/esm/client/middleware.d.ts.map new file mode 100644 index 000000000..88ac77806 --- /dev/null +++ b/dist/esm/client/middleware.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.d.ts","sourceRoot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AACH,eAAO,MAAM,gBAAgB,YAAa,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,KAAG,UAE3H,CAAC"} \ No newline at end of file diff --git a/dist/esm/client/middleware.js b/dist/esm/client/middleware.js new file mode 100644 index 000000000..9e24de68f --- /dev/null +++ b/dist/esm/client/middleware.js @@ -0,0 +1,245 @@ +import { auth, extractWWWAuthenticateParams, UnauthorizedError } from './auth.js'; +/** + * Creates a fetch wrapper that handles OAuth authentication automatically. + * + * This wrapper will: + * - Add Authorization headers with access tokens + * - Handle 401 responses by attempting re-authentication + * - Retry the original request after successful auth + * - Handle OAuth errors appropriately (InvalidClientError, etc.) + * + * The baseUrl parameter is optional and defaults to using the domain from the request URL. + * However, you should explicitly provide baseUrl when: + * - Making requests to multiple subdomains (e.g., api.example.com, cdn.example.com) + * - Using API paths that differ from OAuth discovery paths (e.g., requesting /api/v1/data but OAuth is at /) + * - The OAuth server is on a different domain than your API requests + * - You want to ensure consistent OAuth behavior regardless of request URLs + * + * For MCP transports, set baseUrl to the same URL you pass to the transport constructor. + * + * Note: This wrapper is designed for general-purpose fetch operations. + * MCP transports (SSE and StreamableHTTP) already have built-in OAuth handling + * and should not need this wrapper. + * + * @param provider - OAuth client provider for authentication + * @param baseUrl - Base URL for OAuth server discovery (defaults to request URL domain) + * @returns A fetch middleware function + */ +export const withOAuth = (provider, baseUrl) => next => { + return async (input, init) => { + const makeRequest = async () => { + const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers); + // Add authorization header if tokens are available + const tokens = await provider.tokens(); + if (tokens) { + headers.set('Authorization', `Bearer ${tokens.access_token}`); + } + return await next(input, { ...init, headers }); + }; + let response = await makeRequest(); + // Handle 401 responses by attempting re-authentication + if (response.status === 401) { + try { + const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response); + // Use provided baseUrl or extract from request URL + const serverUrl = baseUrl || (typeof input === 'string' ? new URL(input).origin : input.origin); + const result = await auth(provider, { + serverUrl, + resourceMetadataUrl, + scope, + fetchFn: next + }); + if (result === 'REDIRECT') { + throw new UnauthorizedError('Authentication requires user authorization - redirect initiated'); + } + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(`Authentication failed with result: ${result}`); + } + // Retry the request with fresh tokens + response = await makeRequest(); + } + catch (error) { + if (error instanceof UnauthorizedError) { + throw error; + } + throw new UnauthorizedError(`Failed to re-authenticate: ${error instanceof Error ? error.message : String(error)}`); + } + } + // If we still have a 401 after re-auth attempt, throw an error + if (response.status === 401) { + const url = typeof input === 'string' ? input : input.toString(); + throw new UnauthorizedError(`Authentication failed for ${url}`); + } + return response; + }; +}; +/** + * Creates a fetch middleware that logs HTTP requests and responses. + * + * When called without arguments `withLogging()`, it uses the default logger that: + * - Logs successful requests (2xx) to `console.log` + * - Logs error responses (4xx/5xx) and network errors to `console.error` + * - Logs all requests regardless of status (statusLevel: 0) + * - Does not include request or response headers in logs + * - Measures and displays request duration in milliseconds + * + * Important: the default logger uses both `console.log` and `console.error` so it should not be used with + * `stdio` transports and applications. + * + * @param options - Logging configuration options + * @returns A fetch middleware function + */ +export const withLogging = (options = {}) => { + const { logger, includeRequestHeaders = false, includeResponseHeaders = false, statusLevel = 0 } = options; + const defaultLogger = input => { + const { method, url, status, statusText, duration, requestHeaders, responseHeaders, error } = input; + let message = error + ? `HTTP ${method} ${url} failed: ${error.message} (${duration}ms)` + : `HTTP ${method} ${url} ${status} ${statusText} (${duration}ms)`; + // Add headers to message if requested + if (includeRequestHeaders && requestHeaders) { + const reqHeaders = Array.from(requestHeaders.entries()) + .map(([key, value]) => `${key}: ${value}`) + .join(', '); + message += `\n Request Headers: {${reqHeaders}}`; + } + if (includeResponseHeaders && responseHeaders) { + const resHeaders = Array.from(responseHeaders.entries()) + .map(([key, value]) => `${key}: ${value}`) + .join(', '); + message += `\n Response Headers: {${resHeaders}}`; + } + if (error || status >= 400) { + // eslint-disable-next-line no-console + console.error(message); + } + else { + // eslint-disable-next-line no-console + console.log(message); + } + }; + const logFn = logger || defaultLogger; + return next => async (input, init) => { + const startTime = performance.now(); + const method = (init === null || init === void 0 ? void 0 : init.method) || 'GET'; + const url = typeof input === 'string' ? input : input.toString(); + const requestHeaders = includeRequestHeaders ? new Headers(init === null || init === void 0 ? void 0 : init.headers) : undefined; + try { + const response = await next(input, init); + const duration = performance.now() - startTime; + // Only log if status meets the log level threshold + if (response.status >= statusLevel) { + logFn({ + method, + url, + status: response.status, + statusText: response.statusText, + duration, + requestHeaders, + responseHeaders: includeResponseHeaders ? response.headers : undefined + }); + } + return response; + } + catch (error) { + const duration = performance.now() - startTime; + // Always log errors regardless of log level + logFn({ + method, + url, + status: 0, + statusText: 'Network Error', + duration, + requestHeaders, + error: error + }); + throw error; + } + }; +}; +/** + * Composes multiple fetch middleware functions into a single middleware pipeline. + * Middleware are applied in the order they appear, creating a chain of handlers. + * + * @example + * ```typescript + * // Create a middleware pipeline that handles both OAuth and logging + * const enhancedFetch = applyMiddlewares( + * withOAuth(oauthProvider, 'https://api.example.com'), + * withLogging({ statusLevel: 400 }) + * )(fetch); + * + * // Use the enhanced fetch - it will handle auth and log errors + * const response = await enhancedFetch('https://api.example.com/data'); + * ``` + * + * @param middleware - Array of fetch middleware to compose into a pipeline + * @returns A single composed middleware function + */ +export const applyMiddlewares = (...middleware) => { + return next => { + return middleware.reduce((handler, mw) => mw(handler), next); + }; +}; +/** + * Helper function to create custom fetch middleware with cleaner syntax. + * Provides the next handler and request details as separate parameters for easier access. + * + * @example + * ```typescript + * // Create custom authentication middleware + * const customAuthMiddleware = createMiddleware(async (next, input, init) => { + * const headers = new Headers(init?.headers); + * headers.set('X-Custom-Auth', 'my-token'); + * + * const response = await next(input, { ...init, headers }); + * + * if (response.status === 401) { + * console.log('Authentication failed'); + * } + * + * return response; + * }); + * + * // Create conditional middleware + * const conditionalMiddleware = createMiddleware(async (next, input, init) => { + * const url = typeof input === 'string' ? input : input.toString(); + * + * // Only add headers for API routes + * if (url.includes('/api/')) { + * const headers = new Headers(init?.headers); + * headers.set('X-API-Version', 'v2'); + * return next(input, { ...init, headers }); + * } + * + * // Pass through for non-API routes + * return next(input, init); + * }); + * + * // Create caching middleware + * const cacheMiddleware = createMiddleware(async (next, input, init) => { + * const cacheKey = typeof input === 'string' ? input : input.toString(); + * + * // Check cache first + * const cached = await getFromCache(cacheKey); + * if (cached) { + * return new Response(cached, { status: 200 }); + * } + * + * // Make request and cache result + * const response = await next(input, init); + * if (response.ok) { + * await saveToCache(cacheKey, await response.clone().text()); + * } + * + * return response; + * }); + * ``` + * + * @param handler - Function that receives the next handler and request parameters + * @returns A fetch middleware function + */ +export const createMiddleware = (handler) => { + return next => (input, init) => handler(next, input, init); +}; +//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/esm/client/middleware.js.map b/dist/esm/client/middleware.js.map new file mode 100644 index 000000000..eabfcc54d --- /dev/null +++ b/dist/esm/client/middleware.js.map @@ -0,0 +1 @@ +{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,4BAA4B,EAAuB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AASvG;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,SAAS,GAClB,CAAC,QAA6B,EAAE,OAAsB,EAAc,EAAE,CACtE,IAAI,CAAC,EAAE;IACH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,WAAW,GAAG,KAAK,IAAuB,EAAE;YAC9C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,CAAC;YAE3C,mDAAmD;YACnD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvC,IAAI,MAAM,EAAE,CAAC;g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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAwF,EAAc,EAAE;IACrI,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAqB,EAAE,IAAI,CAAC,CAAC;AAC/E,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/client/sse.d.ts b/dist/esm/client/sse.d.ts new file mode 100644 index 000000000..acf99f1ea --- /dev/null +++ b/dist/esm/client/sse.d.ts @@ -0,0 +1,81 @@ +import { type ErrorEvent, type EventSourceInit } from 'eventsource'; +import { Transport, FetchLike } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +import { OAuthClientProvider } from './auth.js'; +export declare class SseError extends Error { + readonly code: number | undefined; + readonly event: ErrorEvent; + constructor(code: number | undefined, message: string | undefined, event: ErrorEvent); +} +/** + * Configuration options for the `SSEClientTransport`. + */ +export type SSEClientTransportOptions = { + /** + * An OAuth client provider to use for authentication. + * + * When an `authProvider` is specified and the SSE connection is started: + * 1. The connection is attempted with any existing access token from the `authProvider`. + * 2. If the access token has expired, the `authProvider` is used to refresh the token. + * 3. If token refresh fails or no access token exists, and auth is required, `OAuthClientProvider.redirectToAuthorization` is called, and an `UnauthorizedError` will be thrown from `connect`/`start`. + * + * After the user has finished authorizing via their user agent, and is redirected back to the MCP client application, call `SSEClientTransport.finishAuth` with the authorization code before retrying the connection. + * + * If an `authProvider` is not provided, and auth is required, an `UnauthorizedError` will be thrown. + * + * `UnauthorizedError` might also be thrown when sending any message over the SSE transport, indicating that the session has expired, and needs to be re-authed and reconnected. + */ + authProvider?: OAuthClientProvider; + /** + * Customizes the initial SSE request to the server (the request that begins the stream). + * + * NOTE: Setting this property will prevent an `Authorization` header from + * being automatically attached to the SSE request, if an `authProvider` is + * also given. This can be worked around by setting the `Authorization` header + * manually. + */ + eventSourceInit?: EventSourceInit; + /** + * Customizes recurring POST requests to the server. + */ + requestInit?: RequestInit; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; +}; +/** + * Client transport for SSE: this will connect to a server using Server-Sent Events for receiving + * messages and make separate POST requests for sending messages. + * @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period. + */ +export declare class SSEClientTransport implements Transport { + private _eventSource?; + private _endpoint?; + private _abortController?; + private _url; + private _resourceMetadataUrl?; + private _scope?; + private _eventSourceInit?; + private _requestInit?; + private _authProvider?; + private _fetch?; + private _fetchWithInit; + private _protocolVersion?; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL, opts?: SSEClientTransportOptions); + private _authThenStart; + private _commonHeaders; + private _startOrAuth; + start(): Promise; + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + finishAuth(authorizationCode: string): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; + setProtocolVersion(version: string): void; +} +//# sourceMappingURL=sse.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/sse.d.ts.map b/dist/esm/client/sse.d.ts.map new file mode 100644 index 000000000..1d38f0eb6 --- /dev/null +++ b/dist/esm/client/sse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/client/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAuB,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAkD,mBAAmB,EAAqB,MAAM,WAAW,CAAC;AAEnH,qBAAa,QAAS,SAAQ,KAA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AEG;IACG,UAAU,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA+ClD,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG5C"} \ No newline at end of file diff --git a/dist/esm/client/sse.js b/dist/esm/client/sse.js new file mode 100644 index 000000000..271be7eac --- /dev/null +++ b/dist/esm/client/sse.js @@ -0,0 +1,208 @@ +import { EventSource } from 'eventsource'; +import { createFetchWithInit } from '../shared/transport.js'; +import { JSONRPCMessageSchema } from '../types.js'; +import { auth, extractWWWAuthenticateParams, UnauthorizedError } from './auth.js'; +export class SseError extends Error { + constructor(code, message, event) { + super(`SSE error: ${message}`); + this.code = code; + this.event = event; + } +} +/** + * Client transport for SSE: this will connect to a server using Server-Sent Events for receiving + * messages and make separate POST requests for sending messages. + * @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period. + */ +export class SSEClientTransport { + constructor(url, opts) { + this._url = url; + this._resourceMetadataUrl = undefined; + this._scope = undefined; + this._eventSourceInit = opts === null || opts === void 0 ? void 0 : opts.eventSourceInit; + this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit; + this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider; + this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch; + this._fetchWithInit = createFetchWithInit(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit); + } + async _authThenStart() { + var _a; + if (!this._authProvider) { + throw new UnauthorizedError('No auth provider'); + } + let result; + try { + result = await auth(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(); + } + return await this._startOrAuth(); + } + async _commonHeaders() { + var _a; + const headers = {}; + if (this._authProvider) { + const tokens = await this._authProvider.tokens(); + if (tokens) { + headers['Authorization'] = `Bearer ${tokens.access_token}`; + } + } + if (this._protocolVersion) { + headers['mcp-protocol-version'] = this._protocolVersion; + } + return new Headers({ ...headers, ...(_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers }); + } + _startOrAuth() { + var _a, _b, _c; + const fetchImpl = ((_c = (_b = (_a = this === null || this === void 0 ? void 0 : this._eventSourceInit) === null || _a === void 0 ? void 0 : _a.fetch) !== null && _b !== void 0 ? _b : this._fetch) !== null && _c !== void 0 ? _c : fetch); + return new Promise((resolve, reject) => { + this._eventSource = new EventSource(this._url.href, { + ...this._eventSourceInit, + fetch: async (url, init) => { + const headers = await this._commonHeaders(); + headers.set('Accept', 'text/event-stream'); + const response = await fetchImpl(url, { + ...init, + headers + }); + if (response.status === 401 && response.headers.has('www-authenticate')) { + const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + } + return response; + } + }); + this._abortController = new AbortController(); + this._eventSource.onerror = event => { + var _a; + if (event.code === 401 && this._authProvider) { + this._authThenStart().then(resolve, reject); + return; + } + const error = new SseError(event.code, event.message, event); + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + this._eventSource.onopen = () => { + // The connection is open, but we need to wait for the endpoint to be received. + }; + this._eventSource.addEventListener('endpoint', (event) => { + var _a; + const messageEvent = event; + try { + this._endpoint = new URL(messageEvent.data, this._url); + if (this._endpoint.origin !== this._url.origin) { + throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`); + } + } + catch (error) { + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + void this.close(); + return; + } + resolve(); + }); + this._eventSource.onmessage = (event) => { + var _a, _b; + const messageEvent = event; + let message; + try { + message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data)); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + return; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message); + }; + }); + } + async start() { + if (this._eventSource) { + throw new Error('SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return await this._startOrAuth(); + } + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + async finishAuth(authorizationCode) { + if (!this._authProvider) { + throw new UnauthorizedError('No auth provider'); + } + const result = await auth(this._authProvider, { + serverUrl: this._url, + authorizationCode, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError('Failed to authorize'); + } + } + async close() { + var _a, _b, _c; + (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort(); + (_b = this._eventSource) === null || _b === void 0 ? void 0 : _b.close(); + (_c = this.onclose) === null || _c === void 0 ? void 0 : _c.call(this); + } + async send(message) { + var _a, _b, _c; + if (!this._endpoint) { + throw new Error('Not connected'); + } + try { + const headers = await this._commonHeaders(); + headers.set('content-type', 'application/json'); + const init = { + ...this._requestInit, + method: 'POST', + headers, + body: JSON.stringify(message), + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._endpoint, init); + if (!response.ok) { + const text = await response.text().catch(() => null); + if (response.status === 401 && this._authProvider) { + const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + const result = await auth(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(); + } + // Purposely _not_ awaited, so we don't call onerror twice + return this.send(message); + } + throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`); + } + } + catch (error) { + (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, error); + throw error; + } + } + setProtocolVersion(version) { + this._protocolVersion = version; + } +} +//# sourceMappingURL=sse.js.map \ No newline at end of file diff --git a/dist/esm/client/sse.js.map b/dist/esm/client/sse.js.map new file mode 100644 index 000000000..8e4bc276f --- /dev/null +++ b/dist/esm/client/sse.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/client/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyC,MAAM,aAAa,CAAC;AACjF,OAAO,EAAwB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAkB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,IAAI,EAAc,4BAA4B,EAAuB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAC/B,YACoB,IAAwB,EACxC,OAA2B,EACX,KAAiB;QAEjC,KAAK,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;QAJf,SAAI,GAAJ,IAAI,CAAoB;QAExB,UAAK,GAAL,KAAK,CAAY;IAGrC,CAAC;CACJ;AA2CD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAkB3B,YAAY,GAAQ,EAAE,IAAgC;QAClD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,gBAAgB,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,IAAI,aAAJ,IAAI,uB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M,KAAK,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;oBAChD,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;oBAC9E,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;oBAChD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;oBAEpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;wBAC1C,SAAS,EAAE,IAAI,CAAC,IAAI;wBACpB,mBAAmB,EAAE,IAAI,CAAC,oBAAoB;wBAC9C,KAAK,EAAE,IAAI,CAAC,MAAM;wBAClB,OAAO,EAAE,IAAI,CAAC,cAAc;qBAC/B,CAAC,CAAC;oBACH,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;wBAC1B,MAAM,IAAI,iBAAiB,EAAE,CAAC;oBAClC,CAAC;oBAED,0DAA0D;oBAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;gBAED,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;YACpF,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,OAAe;QAC9B,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IACpC,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/client/stdio.d.ts b/dist/esm/client/stdio.d.ts new file mode 100644 index 000000000..58d0b6ccb --- /dev/null +++ b/dist/esm/client/stdio.d.ts @@ -0,0 +1,78 @@ +import { IOType } from 'node:child_process'; +import { Stream } from 'node:stream'; +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +export type StdioServerParameters = { + /** + * The executable to run to start the server. + */ + command: string; + /** + * Command line arguments to pass to the executable. + */ + args?: string[]; + /** + * The environment to use when spawning the process. + * + * If not specified, the result of getDefaultEnvironment() will be used. + */ + env?: Record; + /** + * How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn`. + * + * The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr. + */ + stderr?: IOType | Stream | number; + /** + * The working directory to use when spawning the process. + * + * If not specified, the current working directory will be inherited. + */ + cwd?: string; +}; +/** + * Environment variables to inherit by default, if an environment is not explicitly given. + */ +export declare const DEFAULT_INHERITED_ENV_VARS: string[]; +/** + * Returns a default environment object including only environment variables deemed safe to inherit. + */ +export declare function getDefaultEnvironment(): Record; +/** + * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. + * + * This transport is only available in Node.js environments. + */ +export declare class StdioClientTransport implements Transport { + private _process?; + private _abortController; + private _readBuffer; + private _serverParams; + private _stderrStream; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(server: StdioServerParameters); + /** + * Starts the server process and prepares to communicate with it. + */ + start(): Promise; + /** + * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped". + * + * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to + * attach listeners before the start method is invoked. This prevents loss of any early + * error output emitted by the child process. + */ + get stderr(): Stream | null; + /** + * The child process pid spawned by this transport. + * + * This is only available after the transport has been started. + */ + get pid(): number | null; + private processReadBuffer; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/stdio.d.ts.map b/dist/esm/client/stdio.d.ts.map new file mode 100644 index 000000000..44f6de451 --- /dev/null +++ b/dist/esm/client/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/client/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,E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AG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED,OAAO,CAAC,iBAAiB;IAenB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAc/C"} \ No newline at end of file diff --git a/dist/esm/client/stdio.js b/dist/esm/client/stdio.js new file mode 100644 index 000000000..d77c64d15 --- /dev/null +++ b/dist/esm/client/stdio.js @@ -0,0 +1,176 @@ +import spawn from 'cross-spawn'; +import process from 'node:process'; +import { PassThrough } from 'node:stream'; +import { ReadBuffer, serializeMessage } from '../shared/stdio.js'; +/** + * Environment variables to inherit by default, if an environment is not explicitly given. + */ +export const DEFAULT_INHERITED_ENV_VARS = process.platform === 'win32' + ? [ + 'APPDATA', + 'HOMEDRIVE', + 'HOMEPATH', + 'LOCALAPPDATA', + 'PATH', + 'PROCESSOR_ARCHITECTURE', + 'SYSTEMDRIVE', + 'SYSTEMROOT', + 'TEMP', + 'USERNAME', + 'USERPROFILE', + 'PROGRAMFILES' + ] + : /* list inspired by the default env inheritance of sudo */ + ['HOME', 'LOGNAME', 'PATH', 'SHELL', 'TERM', 'USER']; +/** + * Returns a default environment object including only environment variables deemed safe to inherit. + */ +export function getDefaultEnvironment() { + const env = {}; + for (const key of DEFAULT_INHERITED_ENV_VARS) { + const value = process.env[key]; + if (value === undefined) { + continue; + } + if (value.startsWith('()')) { + // Skip functions, which are a security risk. + continue; + } + env[key] = value; + } + return env; +} +/** + * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. + * + * This transport is only available in Node.js environments. + */ +export class StdioClientTransport { + constructor(server) { + this._abortController = new AbortController(); + this._readBuffer = new ReadBuffer(); + this._stderrStream = null; + this._serverParams = server; + if (server.stderr === 'pipe' || server.stderr === 'overlapped') { + this._stderrStream = new PassThrough(); + } + } + /** + * Starts the server process and prepares to communicate with it. + */ + async start() { + if (this._process) { + throw new Error('StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return new Promise((resolve, reject) => { + var _a, _b, _c, _d, _e; + this._process = spawn(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== void 0 ? _a : [], { + // merge default env with server env because mcp server needs some env vars + env: { + ...getDefaultEnvironment(), + ...this._serverParams.env + }, + stdio: ['pipe', 'pipe', (_b = this._serverParams.stderr) !== null && _b !== void 0 ? _b : 'inherit'], + shell: false, + signal: this._abortController.signal, + windowsHide: process.platform === 'win32' && isElectron(), + cwd: this._serverParams.cwd + }); + this._process.on('error', error => { + var _a, _b; + if (error.name === 'AbortError') { + // Expected when close() is called. + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + return; + } + reject(error); + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + }); + this._process.on('spawn', () => { + resolve(); + }); + this._process.on('close', _code => { + var _a; + this._process = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }); + (_c = this._process.stdin) === null || _c === void 0 ? void 0 : _c.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + (_d = this._process.stdout) === null || _d === void 0 ? void 0 : _d.on('data', chunk => { + this._readBuffer.append(chunk); + this.processReadBuffer(); + }); + (_e = this._process.stdout) === null || _e === void 0 ? void 0 : _e.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + if (this._stderrStream && this._process.stderr) { + this._process.stderr.pipe(this._stderrStream); + } + }); + } + /** + * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped". + * + * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to + * attach listeners before the start method is invoked. This prevents loss of any early + * error output emitted by the child process. + */ + get stderr() { + var _a, _b; + if (this._stderrStream) { + return this._stderrStream; + } + return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.stderr) !== null && _b !== void 0 ? _b : null; + } + /** + * The child process pid spawned by this transport. + * + * This is only available after the transport has been started. + */ + get pid() { + var _a, _b; + return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.pid) !== null && _b !== void 0 ? _b : null; + } + processReadBuffer() { + var _a, _b; + while (true) { + try { + const message = this._readBuffer.readMessage(); + if (message === null) { + break; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + async close() { + this._abortController.abort(); + this._process = undefined; + this._readBuffer.clear(); + } + send(message) { + return new Promise(resolve => { + var _a; + if (!((_a = this._process) === null || _a === void 0 ? void 0 : _a.stdin)) { + throw new Error('Not connected'); + } + const json = serializeMessage(message); + if (this._process.stdin.write(json)) { + resolve(); + } + else { + this._process.stdin.once('drain', resolve); + } + }); + } +} +function isElectron() { + return 'type' in process; +} +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/esm/client/stdio.js.map b/dist/esm/client/stdio.js.map new file mode 100644 index 000000000..ad681edeb --- /dev/null +++ b/dist/esm/client/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/client/stdio.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAU,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqClE;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACnC,OAAO,CAAC,QAAQ,KAAK,OAAO;IACxB,CAAC,CAAC;QACI,SAAS;QACT,WAAW;QACX,UAAU;QACV,cAAc;QACd,MAAM;QACN,wBAAwB;QACxB,aAAa;QACb,YAAY;QACZ,MAAM;QACN,UAAU;QACV,aAAa;QACb,cAAc;KACjB;IACH,CAAC,CAAC,0DAA0D;QAC1D,CAAC,MAAM,EAAE,SAAS,EAAE,M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AAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;YACnC,CAAC;QACL,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,OAAuB;QACxB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;;YACzB,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,CAAA,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;YACrC,CAAC;YAED,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACvC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClC,OAAO,EAAE,CAAC;YACd,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,UAAU;IACf,OAAO,MAAM,IAAI,OAAO,CAAC;AAC7B,CAAC"} \ No newline at end of file diff --git a/dist/esm/client/streamableHttp.d.ts b/dist/esm/client/streamableHttp.d.ts new file mode 100644 index 000000000..8488d7b1d --- /dev/null +++ b/dist/esm/client/streamableHttp.d.ts @@ -0,0 +1,170 @@ +import { Transport, FetchLike } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +import { OAuthClientProvider } from './auth.js'; +export declare class StreamableHTTPError extends Error { + readonly code: number | undefined; + constructor(code: number | undefined, message: string | undefined); +} +/** + * Options for starting or authenticating an SSE connection + */ +export interface StartSSEOptions { + /** + * The resumption token used to continue long-running requests that were interrupted. + * + * This allows clients to reconnect and continue from where they left off. + */ + resumptionToken?: string; + /** + * A callback that is invoked when the resumption token changes. + * + * This allows clients to persist the latest token for potential reconnection. + */ + onresumptiontoken?: (token: string) => void; + /** + * Override Message ID to associate with the replay message + * so that response can be associate with the new resumed request. + */ + replayMessageId?: string | number; +} +/** + * Configuration options for reconnection behavior of the StreamableHTTPClientTransport. + */ +export interface StreamableHTTPReconnectionOptions { + /** + * Maximum backoff time between reconnection attempts in milliseconds. + * Default is 30000 (30 seconds). + */ + maxReconnectionDelay: number; + /** + * Initial backoff time between reconnection attempts in milliseconds. + * Default is 1000 (1 second). + */ + initialReconnectionDelay: number; + /** + * The factor by which the reconnection delay increases after each attempt. + * Default is 1.5. + */ + reconnectionDelayGrowFactor: number; + /** + * Maximum number of reconnection attempts before giving up. + * Default is 2. + */ + maxRetries: number; +} +/** + * Configuration options for the `StreamableHTTPClientTransport`. + */ +export type StreamableHTTPClientTransportOptions = { + /** + * An OAuth client provider to use for authentication. + * + * When an `authProvider` is specified and the connection is started: + * 1. The connection is attempted with any existing access token from the `authProvider`. + * 2. If the access token has expired, the `authProvider` is used to refresh the token. + * 3. If token refresh fails or no access token exists, and auth is required, `OAuthClientProvider.redirectToAuthorization` is called, and an `UnauthorizedError` will be thrown from `connect`/`start`. + * + * After the user has finished authorizing via their user agent, and is redirected back to the MCP client application, call `StreamableHTTPClientTransport.finishAuth` with the authorization code before retrying the connection. + * + * If an `authProvider` is not provided, and auth is required, an `UnauthorizedError` will be thrown. + * + * `UnauthorizedError` might also be thrown when sending any message over the transport, indicating that the session has expired, and needs to be re-authed and reconnected. + */ + authProvider?: OAuthClientProvider; + /** + * Customizes HTTP requests to the server. + */ + requestInit?: RequestInit; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; + /** + * Options to configure the reconnection behavior. + */ + reconnectionOptions?: StreamableHTTPReconnectionOptions; + /** + * Session ID for the connection. This is used to identify the session on the server. + * When not provided and connecting to a server that supports session IDs, the server will generate a new session ID. + */ + sessionId?: string; +}; +/** + * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events + * for receiving messages. + */ +export declare class StreamableHTTPClientTransport implements Transport { + private _abortController?; + private _url; + private _resourceMetadataUrl?; + private _scope?; + private _requestInit?; + private _authProvider?; + private _fetch?; + private _fetchWithInit; + private _sessionId?; + private _reconnectionOptions; + private _protocolVersion?; + private _hasCompletedAuthFlow; + private _lastUpscopingHeader?; + private _serverRetryMs?; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL, opts?: StreamableHTTPClientTransportOptions); + private _authThenStart; + private _commonHeaders; + private _startOrAuthSse; + /** + * Calculates the next reconnection delay using backoff algorithm + * + * @param attempt Current reconnection attempt count for the specific stream + * @returns Time to wait in milliseconds before next reconnection attempt + */ + private _getNextReconnectionDelay; + /** + * Schedule a reconnection attempt using server-provided retry interval or backoff + * + * @param lastEventId The ID of the last received event for resumability + * @param attemptCount Current reconnection attempt count for this specific stream + */ + private _scheduleReconnection; + private _handleSseStream; + start(): Promise; + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + finishAuth(authorizationCode: string): Promise; + close(): Promise; + send(message: JSONRPCMessage | JSONRPCMessage[], options?: { + resumptionToken?: string; + onresumptiontoken?: (token: string) => void; + }): Promise; + get sessionId(): string | undefined; + /** + * Terminates the current session by sending a DELETE request to the server. + * + * Clients that no longer need a particular session + * (e.g., because the user is leaving the client application) SHOULD send an + * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly + * terminate the session. + * + * The server MAY respond with HTTP 405 Method Not Allowed, indicating that + * the server does not allow clients to terminate sessions. + */ + terminateSession(): Promise; + setProtocolVersion(version: string): void; + get protocolVersion(): string | undefined; + /** + * Resume an SSE stream from a previous event ID. + * Opens a GET SSE connection with Last-Event-ID header to replay missed events. + * + * @param lastEventId The event ID to resume from + * @param options Optional callback to receive new resumption tokens + */ + resumeStream(lastEventId: string, options?: { + onresumptiontoken?: (token: string) => void; + }): Promise; +} +//# sourceMappingURL=streamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/streamableHttp.d.ts.map b/dist/esm/client/streamableHttp.d.ts.map new file mode 100644 index 000000000..f9472e54a --- /dev/null +++ b/dist/esm/client/streamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.d.ts","sourceRoot":"","sources":["../../../src/client/streamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAyC,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAkE,cAAc,EAAwB,MAAM,aAAa,CAAC;AACnI,OAAO,EAAkD,mBAAmB,EAAqB,MAAM,WAAW,CAAC;AAWnH,qBAAa,mBAAoB,SAAQ,KAAK;aAEtB,IAAI,EAAE,MAAM,GAAG,SAAS;gBAAxB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxC,OAAO,EAAE,MAAM,GAAG,SAAS;CAIlC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE5C;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAC9C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,wBAAwB,EAAE,MAAM,CAAC;IAEjC;;;OAGG;IACH,2BAA2B,EAAE,MAAM,CAAC;IAEpC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;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AAO,CAAC,gBAAgB;IAoGlB,KAAK;IAUX;;OAEG;IACG,UAAU,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,IAAI,CACN,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GACpF,OAAO,CAAC,IAAI,CAAC;IAsJhB,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED;;;;;;;;;;OAUG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAGzC,IAAI,eAAe,IAAI,MAAM,GAAG,SAAS,CAExC;IAED;;;;;;OAMG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAMpH"} \ No newline at end of file diff --git a/dist/esm/client/streamableHttp.js b/dist/esm/client/streamableHttp.js new file mode 100644 index 000000000..8fd896c2e --- /dev/null +++ b/dist/esm/client/streamableHttp.js @@ -0,0 +1,468 @@ +import { createFetchWithInit, normalizeHeaders } from '../shared/transport.js'; +import { isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessageSchema } from '../types.js'; +import { auth, extractWWWAuthenticateParams, UnauthorizedError } from './auth.js'; +import { EventSourceParserStream } from 'eventsource-parser/stream'; +// Default reconnection options for StreamableHTTP connections +const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = { + initialReconnectionDelay: 1000, + maxReconnectionDelay: 30000, + reconnectionDelayGrowFactor: 1.5, + maxRetries: 2 +}; +export class StreamableHTTPError extends Error { + constructor(code, message) { + super(`Streamable HTTP error: ${message}`); + this.code = code; + } +} +/** + * Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events + * for receiving messages. + */ +export class StreamableHTTPClientTransport { + constructor(url, opts) { + var _a; + this._hasCompletedAuthFlow = false; // Circuit breaker: detect auth success followed by immediate 401 + this._url = url; + this._resourceMetadataUrl = undefined; + this._scope = undefined; + this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit; + this._authProvider = opts === null || opts === void 0 ? void 0 : opts.authProvider; + this._fetch = opts === null || opts === void 0 ? void 0 : opts.fetch; + this._fetchWithInit = createFetchWithInit(opts === null || opts === void 0 ? void 0 : opts.fetch, opts === null || opts === void 0 ? void 0 : opts.requestInit); + this._sessionId = opts === null || opts === void 0 ? void 0 : opts.sessionId; + this._reconnectionOptions = (_a = opts === null || opts === void 0 ? void 0 : opts.reconnectionOptions) !== null && _a !== void 0 ? _a : DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS; + } + async _authThenStart() { + var _a; + if (!this._authProvider) { + throw new UnauthorizedError('No auth provider'); + } + let result; + try { + result = await auth(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(); + } + return await this._startOrAuthSse({ resumptionToken: undefined }); + } + async _commonHeaders() { + var _a; + const headers = {}; + if (this._authProvider) { + const tokens = await this._authProvider.tokens(); + if (tokens) { + headers['Authorization'] = `Bearer ${tokens.access_token}`; + } + } + if (this._sessionId) { + headers['mcp-session-id'] = this._sessionId; + } + if (this._protocolVersion) { + headers['mcp-protocol-version'] = this._protocolVersion; + } + const extraHeaders = normalizeHeaders((_a = this._requestInit) === null || _a === void 0 ? void 0 : _a.headers); + return new Headers({ + ...headers, + ...extraHeaders + }); + } + async _startOrAuthSse(options) { + var _a, _b, _c, _d; + const { resumptionToken } = options; + try { + // Try to open an initial SSE stream with GET to listen for server messages + // This is optional according to the spec - server may not support it + const headers = await this._commonHeaders(); + headers.set('Accept', 'text/event-stream'); + // Include Last-Event-ID header for resumable streams if provided + if (resumptionToken) { + headers.set('last-event-id', resumptionToken); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._url, { + method: 'GET', + headers, + signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal + }); + if (!response.ok) { + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + if (response.status === 401 && this._authProvider) { + // Need to authenticate + return await this._authThenStart(); + } + // 405 indicates that the server does not offer an SSE stream at GET endpoint + // This is an expected case that should not trigger an error + if (response.status === 405) { + return; + } + throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`); + } + this._handleSseStream(response.body, options, true); + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + throw error; + } + } + /** + * Calculates the next reconnection delay using backoff algorithm + * + * @param attempt Current reconnection attempt count for the specific stream + * @returns Time to wait in milliseconds before next reconnection attempt + */ + _getNextReconnectionDelay(attempt) { + // Use server-provided retry value if available + if (this._serverRetryMs !== undefined) { + return this._serverRetryMs; + } + // Fall back to exponential backoff + const initialDelay = this._reconnectionOptions.initialReconnectionDelay; + const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor; + const maxDelay = this._reconnectionOptions.maxReconnectionDelay; + // Cap at maximum delay + return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay); + } + /** + * Schedule a reconnection attempt using server-provided retry interval or backoff + * + * @param lastEventId The ID of the last received event for resumability + * @param attemptCount Current reconnection attempt count for this specific stream + */ + _scheduleReconnection(options, attemptCount = 0) { + var _a; + // Use provided options or default options + const maxRetries = this._reconnectionOptions.maxRetries; + // Check if we've exceeded maximum retry attempts + if (maxRetries > 0 && attemptCount >= maxRetries) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`)); + return; + } + // Calculate next delay based on current attempt count + const delay = this._getNextReconnectionDelay(attemptCount); + // Schedule the reconnection + setTimeout(() => { + // Use the last event ID to resume where we left off + this._startOrAuthSse(options).catch(error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`)); + // Schedule another attempt if this one failed, incrementing the attempt counter + this._scheduleReconnection(options, attemptCount + 1); + }); + }, delay); + } + _handleSseStream(stream, options, isReconnectable) { + if (!stream) { + return; + } + const { onresumptiontoken, replayMessageId } = options; + let lastEventId; + // Track whether we've received a priming event (event with ID) + // Per spec, server SHOULD send a priming event with ID before closing + let hasPrimingEvent = false; + const processStream = async () => { + var _a, _b, _c, _d; + // this is the closest we can get to trying to catch network errors + // if something happens reader will throw + try { + // Create a pipeline: binary stream -> text decoder -> SSE parser + const reader = stream + .pipeThrough(new TextDecoderStream()) + .pipeThrough(new EventSourceParserStream({ + onRetry: (retryMs) => { + // Capture server-provided retry value for reconnection timing + this._serverRetryMs = retryMs; + } + })) + .getReader(); + while (true) { + const { value: event, done } = await reader.read(); + if (done) { + break; + } + // Update last event ID if provided + if (event.id) { + lastEventId = event.id; + // Mark that we've received a priming event - stream is now resumable + hasPrimingEvent = true; + onresumptiontoken === null || onresumptiontoken === void 0 ? void 0 : onresumptiontoken(event.id); + } + // Skip events with no data (priming events, keep-alives) + if (!event.data) { + continue; + } + if (!event.event || event.event === 'message') { + try { + const message = JSONRPCMessageSchema.parse(JSON.parse(event.data)); + if (replayMessageId !== undefined && isJSONRPCResponse(message)) { + message.id = replayMessageId; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + // Handle graceful server-side disconnect + // Server may close connection after sending event ID and retry field + // Reconnect if: already reconnectable (GET stream) OR received a priming event (POST stream with event ID) + const canResume = isReconnectable || hasPrimingEvent; + if (canResume && this._abortController && !this._abortController.signal.aborted) { + this._scheduleReconnection({ + resumptionToken: lastEventId, + onresumptiontoken, + replayMessageId + }, 0); + } + } + catch (error) { + // Handle stream errors - likely a network disconnect + (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`)); + // Attempt to reconnect if the stream disconnects unexpectedly and we aren't closing + // Reconnect if: already reconnectable (GET stream) OR received a priming event (POST stream with event ID) + const canResume = isReconnectable || hasPrimingEvent; + if (canResume && this._abortController && !this._abortController.signal.aborted) { + // Use the exponential backoff reconnection strategy + try { + this._scheduleReconnection({ + resumptionToken: lastEventId, + onresumptiontoken, + replayMessageId + }, 0); + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, new Error(`Failed to reconnect: ${error instanceof Error ? error.message : String(error)}`)); + } + } + } + }; + processStream(); + } + async start() { + if (this._abortController) { + throw new Error('StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + this._abortController = new AbortController(); + } + /** + * Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth. + */ + async finishAuth(authorizationCode) { + if (!this._authProvider) { + throw new UnauthorizedError('No auth provider'); + } + const result = await auth(this._authProvider, { + serverUrl: this._url, + authorizationCode, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError('Failed to authorize'); + } + } + async close() { + var _a, _b; + // Abort any pending requests + (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort(); + (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this); + } + async send(message, options) { + var _a, _b, _c, _d, _e; + try { + const { resumptionToken, onresumptiontoken } = options || {}; + if (resumptionToken) { + // If we have at last event ID, we need to reconnect the SSE stream + this._startOrAuthSse({ resumptionToken, replayMessageId: isJSONRPCRequest(message) ? message.id : undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); }); + return; + } + const headers = await this._commonHeaders(); + headers.set('content-type', 'application/json'); + headers.set('accept', 'application/json, text/event-stream'); + const init = { + ...this._requestInit, + method: 'POST', + headers, + body: JSON.stringify(message), + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init); + // Handle session ID received during initialization + const sessionId = response.headers.get('mcp-session-id'); + if (sessionId) { + this._sessionId = sessionId; + } + if (!response.ok) { + const text = await response.text().catch(() => null); + if (response.status === 401 && this._authProvider) { + // Prevent infinite recursion when server returns 401 after successful auth + if (this._hasCompletedAuthFlow) { + throw new StreamableHTTPError(401, 'Server returned 401 after successful authentication'); + } + const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response); + this._resourceMetadataUrl = resourceMetadataUrl; + this._scope = scope; + const result = await auth(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetchWithInit + }); + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(); + } + // Mark that we completed auth flow + this._hasCompletedAuthFlow = true; + // Purposely _not_ awaited, so we don't call onerror twice + return this.send(message); + } + if (response.status === 403 && this._authProvider) { + const { resourceMetadataUrl, scope, error } = extractWWWAuthenticateParams(response); + if (error === 'insufficient_scope') { + const wwwAuthHeader = response.headers.get('WWW-Authenticate'); + // Check if we've already tried upscoping with this header to prevent infinite loops. + if (this._lastUpscopingHeader === wwwAuthHeader) { + throw new StreamableHTTPError(403, 'Server returned 403 after trying upscoping'); + } + if (scope) { + this._scope = scope; + } + if (resourceMetadataUrl) { + this._resourceMetadataUrl = resourceMetadataUrl; + } + // Mark that upscoping was tried. + this._lastUpscopingHeader = wwwAuthHeader !== null && wwwAuthHeader !== void 0 ? wwwAuthHeader : undefined; + const result = await auth(this._authProvider, { + serverUrl: this._url, + resourceMetadataUrl: this._resourceMetadataUrl, + scope: this._scope, + fetchFn: this._fetch + }); + if (result !== 'AUTHORIZED') { + throw new UnauthorizedError(); + } + return this.send(message); + } + } + throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`); + } + // Reset auth loop flag on successful response + this._hasCompletedAuthFlow = false; + this._lastUpscopingHeader = undefined; + // If the response is 202 Accepted, there's no body to process + if (response.status === 202) { + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + // if the accepted notification is initialized, we start the SSE stream + // if it's supported by the server + if (isInitializedNotification(message)) { + // Start without a lastEventId since this is a fresh connection + this._startOrAuthSse({ resumptionToken: undefined }).catch(err => { var _a; return (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, err); }); + } + return; + } + // Get original message(s) for detecting request IDs + const messages = Array.isArray(message) ? message : [message]; + const hasRequests = messages.filter(msg => 'method' in msg && 'id' in msg && msg.id !== undefined).length > 0; + // Check the response type + const contentType = response.headers.get('content-type'); + if (hasRequests) { + if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/event-stream')) { + // Handle SSE stream responses for requests + // We use the same handler as standalone streams, which now supports + // reconnection with the last event ID + this._handleSseStream(response.body, { onresumptiontoken }, false); + } + else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) { + // For non-streaming servers, we might get direct JSON responses + const data = await response.json(); + const responseMessages = Array.isArray(data) + ? data.map(msg => JSONRPCMessageSchema.parse(msg)) + : [JSONRPCMessageSchema.parse(data)]; + for (const msg of responseMessages) { + (_d = this.onmessage) === null || _d === void 0 ? void 0 : _d.call(this, msg); + } + } + else { + throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`); + } + } + } + catch (error) { + (_e = this.onerror) === null || _e === void 0 ? void 0 : _e.call(this, error); + throw error; + } + } + get sessionId() { + return this._sessionId; + } + /** + * Terminates the current session by sending a DELETE request to the server. + * + * Clients that no longer need a particular session + * (e.g., because the user is leaving the client application) SHOULD send an + * HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly + * terminate the session. + * + * The server MAY respond with HTTP 405 Method Not Allowed, indicating that + * the server does not allow clients to terminate sessions. + */ + async terminateSession() { + var _a, _b, _c, _d; + if (!this._sessionId) { + return; // No session to terminate + } + try { + const headers = await this._commonHeaders(); + const init = { + ...this._requestInit, + method: 'DELETE', + headers, + signal: (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.signal + }; + const response = await ((_b = this._fetch) !== null && _b !== void 0 ? _b : fetch)(this._url, init); + await ((_c = response.body) === null || _c === void 0 ? void 0 : _c.cancel()); + // We specifically handle 405 as a valid response according to the spec, + // meaning the server does not support explicit session termination + if (!response.ok && response.status !== 405) { + throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`); + } + this._sessionId = undefined; + } + catch (error) { + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + throw error; + } + } + setProtocolVersion(version) { + this._protocolVersion = version; + } + get protocolVersion() { + return this._protocolVersion; + } + /** + * Resume an SSE stream from a previous event ID. + * Opens a GET SSE connection with Last-Event-ID header to replay missed events. + * + * @param lastEventId The event ID to resume from + * @param options Optional callback to receive new resumption tokens + */ + async resumeStream(lastEventId, options) { + await this._startOrAuthSse({ + resumptionToken: lastEventId, + onresumptiontoken: options === null || options === void 0 ? void 0 : options.onresumptiontoken + }); + } +} +//# sourceMappingURL=streamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/client/streamableHttp.js.map b/dist/esm/client/streamableHttp.js.map new file mode 100644 index 000000000..99b976bb8 --- /dev/null +++ b/dist/esm/client/streamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.js","sourceRoot":"","sources":["../../../src/client/streamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,m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AO,KAAK,EAAE,CAAC;YACb,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,OAAe;QAC9B,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IACpC,CAAC;IACD,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,WAAmB,EAAE,OAAyD;QAC7F,MAAM,IAAI,CAAC,eAAe,CAAC;YACvB,eAAe,EAAE,WAAW;YAC5B,iBAAiB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB;SAChD,CAAC,CAAC;IACP,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/client/websocket.d.ts b/dist/esm/client/websocket.d.ts new file mode 100644 index 000000000..78f95de3b --- /dev/null +++ b/dist/esm/client/websocket.d.ts @@ -0,0 +1,17 @@ +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage } from '../types.js'; +/** + * Client transport for WebSocket: this will connect to a server over the WebSocket protocol. + */ +export declare class WebSocketClientTransport implements Transport { + private _socket?; + private _url; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + constructor(url: URL); + start(): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=websocket.d.ts.map \ No newline at end of file diff --git a/dist/esm/client/websocket.d.ts.map b/dist/esm/client/websocket.d.ts.map new file mode 100644 index 000000000..2882d9822 --- /dev/null +++ b/dist/esm/client/websocket.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/client/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AAInE;;GAEG;AACH,qBAAa,wBAAyB,YAAW,SAAS;IACtD,OAAO,CAAC,OAAO,CAAC,CAAY;IAC5B,OAAO,CAAC,IAAI,CAAM;IAElB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;gBAElC,GAAG,EAAE,GAAG;IAIpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsChB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAW/C"} \ No newline at end of file diff --git a/dist/esm/client/websocket.js b/dist/esm/client/websocket.js new file mode 100644 index 000000000..d55feabeb --- /dev/null +++ b/dist/esm/client/websocket.js @@ -0,0 +1,59 @@ +import { JSONRPCMessageSchema } from '../types.js'; +const SUBPROTOCOL = 'mcp'; +/** + * Client transport for WebSocket: this will connect to a server over the WebSocket protocol. + */ +export class WebSocketClientTransport { + constructor(url) { + this._url = url; + } + start() { + if (this._socket) { + throw new Error('WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.'); + } + return new Promise((resolve, reject) => { + this._socket = new WebSocket(this._url, SUBPROTOCOL); + this._socket.onerror = event => { + var _a; + const error = 'error' in event ? event.error : new Error(`WebSocket error: ${JSON.stringify(event)}`); + reject(error); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + this._socket.onopen = () => { + resolve(); + }; + this._socket.onclose = () => { + var _a; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }; + this._socket.onmessage = (event) => { + var _a, _b; + let message; + try { + message = JSONRPCMessageSchema.parse(JSON.parse(event.data)); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + return; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, message); + }; + }); + } + async close() { + var _a; + (_a = this._socket) === null || _a === void 0 ? void 0 : _a.close(); + } + send(message) { + return new Promise((resolve, reject) => { + var _a; + if (!this._socket) { + reject(new Error('Not connected')); + return; + } + (_a = this._socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(message)); + resolve(); + }); + } +} +//# sourceMappingURL=websocket.js.map \ No newline at end of file diff --git a/dist/esm/client/websocket.js.map b/dist/esm/client/websocket.js.map new file mode 100644 index 000000000..616164b1d --- /dev/null +++ b/dist/esm/client/websocket.js.map @@ -0,0 +1 @@ +{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/client/websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAQjC,YAAY,GAAQ;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IACpB,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACX,mHAAmH,CACtH,CAAC;QACN,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YAErD,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE;;gBAC3B,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,KAAe,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACjH,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAK,CAAC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/examples/client/elicitationUrlExample.d.ts new file mode 100644 index 000000000..611f6eba2 --- /dev/null +++ b/dist/esm/examples/client/elicitationUrlExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationUrlExample.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/elicitationUrlExample.d.ts.map b/dist/esm/examples/client/elicitationUrlExample.d.ts.map new file mode 100644 index 000000000..e749adfb9 --- /dev/null +++ b/dist/esm/examples/client/elicitationUrlExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/elicitationUrlExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/elicitationUrlExample.js b/dist/esm/examples/client/elicitationUrlExample.js new file mode 100644 index 000000000..741e83d3e --- /dev/null +++ b/dist/esm/examples/client/elicitationUrlExample.js @@ -0,0 +1,691 @@ +// Run with: npx tsx src/examples/client/elicitationUrlExample.ts +// +// This example demonstrates how to use URL elicitation to securely +// collect user input in a remote (HTTP) server. +// URL elicitation allows servers to prompt the end-user to open a URL in their browser +// to collect sensitive information. +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { createInterface } from 'node:readline'; +import { ListToolsResultSchema, CallToolResultSchema, ElicitRequestSchema, McpError, ErrorCode, UrlElicitationRequiredError, ElicitationCompleteNotificationSchema } from '../../types.js'; +import { getDisplayName } from '../../shared/metadataUtils.js'; +import { exec } from 'node:child_process'; +import { InMemoryOAuthClientProvider } from './simpleOAuthClientProvider.js'; +import { UnauthorizedError } from '../../client/auth.js'; +import { createServer } from 'node:http'; +// Set up OAuth (required for this example) +const OAUTH_CALLBACK_PORT = 8090; // Use different port than auth server (3001) +const OAUTH_CALLBACK_URL = `http://localhost:${OAUTH_CALLBACK_PORT}/callback`; +let oauthProvider = undefined; +console.log('Getting OAuth token...'); +const clientMetadata = { + client_name: 'Elicitation MCP Client', + redirect_uris: [OAUTH_CALLBACK_URL], + grant_types: ['authorization_code', 'refresh_token'], + response_types: ['code'], + token_endpoint_auth_method: 'client_secret_post', + scope: 'mcp:tools' +}; +oauthProvider = new InMemoryOAuthClientProvider(OAUTH_CALLBACK_URL, clientMetadata, (redirectUrl) => { + console.log(`🌐 Opening browser for OAuth redirect: ${redirectUrl.toString()}`); + openBrowser(redirectUrl.toString()); +}); +// Create readline interface for user input +const readline = createInterface({ + input: process.stdin, + output: process.stdout +}); +let abortCommand = new AbortController(); +// Global client and transport for interactive commands +let client = null; +let transport = null; +let serverUrl = 'http://localhost:3000/mcp'; +let sessionId = undefined; +let isProcessingCommand = false; +let isProcessingElicitations = false; +const elicitationQueue = []; +let elicitationQueueSignal = null; +let elicitationsCompleteSignal = null; +// Map to track pending URL elicitations waiting for completion notifications +const pendingURLElicitations = new Map(); +async function main() { + console.log('MCP Interactive Client'); + console.log('====================='); + // Connect to server immediately with default settings + await connect(); + // Start the elicitation loop in the background + elicitationLoop().catch(error => { + console.error('Unexpected error in elicitation loop:', error); + process.exit(1); + }); + // Short delay allowing the server to send any SSE elicitations on connection + await new Promise(resolve => setTimeout(resolve, 200)); + // Wait until we are done processing any initial elicitations + await waitForElicitationsToComplete(); + // Print help and start the command loop + printHelp(); + await commandLoop(); +} +async function waitForElicitationsToComplete() { + // Wait until the queue is empty and nothing is being processed + while (elicitationQueue.length > 0 || isProcessingElicitations) { + await new Promise(resolve => setTimeout(resolve, 100)); + } +} +function printHelp() { + console.log('\nAvailable commands:'); + console.log(' connect [url] - Connect to MCP server (default: http://localhost:3000/mcp)'); + console.log(' disconnect - Disconnect from server'); + console.log(' terminate-session - Terminate the current session'); + console.log(' reconnect - Reconnect to the server'); + console.log(' list-tools - List available tools'); + console.log(' call-tool [args] - Call a tool with optional JSON arguments'); + console.log(' payment-confirm - Test URL elicitation via error response with payment-confirm tool'); + console.log(' third-party-auth - Test tool that requires third-party OAuth credentials'); + console.log(' help - Show this help'); + console.log(' quit - Exit the program'); +} +async function commandLoop() { + await new Promise(resolve => { + if (!isProcessingElicitations) { + resolve(); + } + else { + elicitationsCompleteSignal = resolve; + } + }); + readline.question('\n> ', { signal: abortCommand.signal }, async (input) => { + var _a; + isProcessingCommand = true; + const args = input.trim().split(/\s+/); + const command = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + try { + switch (command) { + case 'connect': + await connect(args[1]); + break; + case 'disconnect': + await disconnect(); + break; + case 'terminate-session': + await terminateSession(); + break; + case 'reconnect': + await reconnect(); + break; + case 'list-tools': + await listTools(); + break; + case 'call-tool': + if (args.length < 2) { + console.log('Usage: call-tool [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_b) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callTool(toolName, toolArgs); + } + break; + case 'payment-confirm': + await callPaymentConfirmTool(); + break; + case 'third-party-auth': + await callThirdPartyAuthTool(); + break; + case 'help': + printHelp(); + break; + case 'quit': + case 'exit': + await cleanup(); + return; + default: + if (command) { + console.log(`Unknown command: ${command}`); + } + break; + } + } + catch (error) { + console.error(`Error executing command: ${error}`); + } + finally { + isProcessingCommand = false; + } + // Process another command after we've processed the this one + await commandLoop(); + }); +} +async function elicitationLoop() { + while (true) { + // Wait until we have elicitations to process + await new Promise(resolve => { + if (elicitationQueue.length > 0) { + resolve(); + } + else { + elicitationQueueSignal = resolve; + } + }); + isProcessingElicitations = true; + abortCommand.abort(); // Abort the command loop if it's running + // Process all queued elicitations + while (elicitationQueue.length > 0) { + const queued = elicitationQueue.shift(); + console.log(`📤 Processing queued elicitation (${elicitationQueue.length} remaining)`); + try { + const result = await handleElicitationRequest(queued.request); + queued.resolve(result); + } + catch (error) { + queued.reject(error instanceof Error ? error : new Error(String(error))); + } + } + console.log('✅ All queued elicitations processed. Resuming command loop...\n'); + isProcessingElicitations = false; + // Reset the abort controller for the next command loop + abortCommand = new AbortController(); + // Resume the command loop + if (elicitationsCompleteSignal) { + elicitationsCompleteSignal(); + elicitationsCompleteSignal = null; + } + } +} +async function openBrowser(url) { + const command = `open "${url}"`; + exec(command, error => { + if (error) { + console.error(`Failed to open browser: ${error.message}`); + console.log(`Please manually open: ${url}`); + } + }); +} +/** + * Enqueues an elicitation request and returns the result. + * + * This function is used so that our CLI (which can only handle one input request at a time) + * can handle elicitation requests and the command loop. + * + * @param request - The elicitation request to be handled + * @returns The elicitation result + */ +async function elicitationRequestHandler(request) { + // If we are processing a command, handle this elicitation immediately + if (isProcessingCommand) { + console.log('📋 Processing elicitation immediately (during command execution)'); + return await handleElicitationRequest(request); + } + // Otherwise, queue the request to be handled by the elicitation loop + console.log(`📥 Queueing elicitation request (queue size will be: ${elicitationQueue.length + 1})`); + return new Promise((resolve, reject) => { + elicitationQueue.push({ + request, + resolve, + reject + }); + // Signal the elicitation loop that there's work to do + if (elicitationQueueSignal) { + elicitationQueueSignal(); + elicitationQueueSignal = null; + } + }); +} +/** + * Handles an elicitation request. + * + * This function is used to handle the elicitation request and return the result. + * + * @param request - The elicitation request to be handled + * @returns The elicitation result + */ +async function handleElicitationRequest(request) { + const mode = request.params.mode; + console.log('\n🔔 Elicitation Request Received:'); + console.log(`Mode: ${mode}`); + if (mode === 'url') { + return { + action: await handleURLElicitation(request.params) + }; + } + else { + // Should not happen because the client declares its capabilities to the server, + // but being defensive is a good practice: + throw new McpError(ErrorCode.InvalidParams, `Unsupported elicitation mode: ${mode}`); + } +} +/** + * Handles a URL elicitation by opening the URL in the browser. + * + * Note: This is a shared code for both request handlers and error handlers. + * As a result of sharing schema, there is no big forking of logic for the client. + * + * @param params - The URL elicitation request parameters + * @returns The action to take (accept, cancel, or decline) + */ +async function handleURLElicitation(params) { + const url = params.url; + const elicitationId = params.elicitationId; + const message = params.message; + console.log(`🆔 Elicitation ID: ${elicitationId}`); // Print for illustration + // Parse URL to show domain for security + let domain = 'unknown domain'; + try { + const parsedUrl = new URL(url); + domain = parsedUrl.hostname; + } + catch (_a) { + console.error('Invalid URL provided by server'); + return 'decline'; + } + // Example security warning to help prevent phishing attacks + console.log('\n⚠️ \x1b[33mSECURITY WARNING\x1b[0m ⚠️'); + console.log('\x1b[33mThe server is requesting you to open an external URL.\x1b[0m'); + console.log('\x1b[33mOnly proceed if you trust this server and understand why it needs this.\x1b[0m\n'); + console.log(`🌐 Target domain: \x1b[36m${domain}\x1b[0m`); + console.log(`🔗 Full URL: \x1b[36m${url}\x1b[0m`); + console.log(`\nℹ️ Server's reason:\n\n\x1b[36m${message}\x1b[0m\n`); + // 1. Ask for user consent to open the URL + const consent = await new Promise(resolve => { + readline.question('\nDo you want to open this URL in your browser? (y/n): ', input => { + resolve(input.trim().toLowerCase()); + }); + }); + // 2. If user did not consent, return appropriate result + if (consent === 'no' || consent === 'n') { + console.log('❌ URL navigation declined.'); + return 'decline'; + } + else if (consent !== 'yes' && consent !== 'y') { + console.log('🚫 Invalid response. Cancelling elicitation.'); + return 'cancel'; + } + // 3. Wait for completion notification in the background + const completionPromise = new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + pendingURLElicitations.delete(elicitationId); + console.log(`\x1b[31m❌ Elicitation ${elicitationId} timed out waiting for completion.\x1b[0m`); + reject(new Error('Elicitation completion timeout')); + }, 5 * 60 * 1000); // 5 minute timeout + pendingURLElicitations.set(elicitationId, { + resolve: () => { + clearTimeout(timeout); + resolve(); + }, + reject, + timeout + }); + }); + completionPromise.catch(error => { + console.error('Background completion wait failed:', error); + }); + // 4. Open the URL in the browser + console.log(`\n🚀 Opening browser to: ${url}`); + await openBrowser(url); + console.log('\n⏳ Waiting for you to complete the interaction in your browser...'); + console.log(' The server will send a notification once you complete the action.'); + // 5. Acknowledge the user accepted the elicitation + return 'accept'; +} +/** + * Example OAuth callback handler - in production, use a more robust approach + * for handling callbacks and storing tokens + */ +/** + * Starts a temporary HTTP server to receive the OAuth callback + */ +async function waitForOAuthCallback() { + return new Promise((resolve, reject) => { + const server = createServer((req, res) => { + // Ignore favicon requests + if (req.url === '/favicon.ico') { + res.writeHead(404); + res.end(); + return; + } + console.log(`📥 Received callback: ${req.url}`); + const parsedUrl = new URL(req.url || '', 'http://localhost'); + const code = parsedUrl.searchParams.get('code'); + const error = parsedUrl.searchParams.get('error'); + if (code) { + console.log(`✅ Authorization code received: ${code === null || code === void 0 ? void 0 : code.substring(0, 10)}...`); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Successful!

+

This simulates successful authorization of the MCP client, which now has an access token for the MCP server.

+

This window will close automatically in 10 seconds.

+ + + + `); + resolve(code); + setTimeout(() => server.close(), 15000); + } + else if (error) { + console.log(`❌ Authorization error: ${error}`); + res.writeHead(400, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Failed

+

Error: ${error}

+ + + `); + reject(new Error(`OAuth authorization failed: ${error}`)); + } + else { + console.log(`❌ No authorization code or error in callback`); + res.writeHead(400); + res.end('Bad request'); + reject(new Error('No authorization code provided')); + } + }); + server.listen(OAUTH_CALLBACK_PORT, () => { + console.log(`OAuth callback server started on http://localhost:${OAUTH_CALLBACK_PORT}`); + }); + }); +} +/** + * Attempts to connect to the MCP server with OAuth authentication. + * Handles OAuth flow recursively if authorization is required. + */ +async function attemptConnection(oauthProvider) { + console.log('🚢 Creating transport with OAuth provider...'); + const baseUrl = new URL(serverUrl); + transport = new StreamableHTTPClientTransport(baseUrl, { + sessionId: sessionId, + authProvider: oauthProvider + }); + console.log('🚢 Transport created'); + try { + console.log('🔌 Attempting connection (this will trigger OAuth redirect if needed)...'); + await client.connect(transport); + sessionId = transport.sessionId; + console.log('Transport created with session ID:', sessionId); + console.log('✅ Connected successfully'); + } + catch (error) { + if (error instanceof UnauthorizedError) { + console.log('🔐 OAuth required - waiting for authorization...'); + const callbackPromise = waitForOAuthCallback(); + const authCode = await callbackPromise; + await transport.finishAuth(authCode); + console.log('🔐 Authorization code received:', authCode); + console.log('🔌 Reconnecting with authenticated transport...'); + // Recursively retry connection after OAuth completion + await attemptConnection(oauthProvider); + } + else { + console.error('❌ Connection failed with non-auth error:', error); + throw error; + } + } +} +async function connect(url) { + if (client) { + console.log('Already connected. Disconnect first.'); + return; + } + if (url) { + serverUrl = url; + } + console.log(`🔗 Attempting to connect to ${serverUrl}...`); + // Create a new client with elicitation capability + console.log('👤 Creating MCP client...'); + client = new Client({ + name: 'example-client', + version: '1.0.0' + }, { + capabilities: { + elicitation: { + // Only URL elicitation is supported in this demo + // (see server/elicitationExample.ts for a demo of form mode elicitation) + url: {} + } + } + }); + console.log('👤 Client created'); + // Set up elicitation request handler with proper validation + client.setRequestHandler(ElicitRequestSchema, elicitationRequestHandler); + // Set up notification handler for elicitation completion + client.setNotificationHandler(ElicitationCompleteNotificationSchema, notification => { + const { elicitationId } = notification.params; + const pending = pendingURLElicitations.get(elicitationId); + if (pending) { + clearTimeout(pending.timeout); + pendingURLElicitations.delete(elicitationId); + console.log(`\x1b[32m✅ Elicitation ${elicitationId} completed!\x1b[0m`); + pending.resolve(); + } + else { + // Shouldn't happen - discard it! + console.warn(`Received completion notification for unknown elicitation: ${elicitationId}`); + } + }); + try { + console.log('🔐 Starting OAuth flow...'); + await attemptConnection(oauthProvider); + console.log('Connected to MCP server'); + // Set up error handler after connection is established so we don't double log errors + client.onerror = error => { + console.error('\x1b[31mClient error:', error, '\x1b[0m'); + }; + } + catch (error) { + console.error('Failed to connect:', error); + client = null; + transport = null; + return; + } +} +async function disconnect() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + await transport.close(); + console.log('Disconnected from MCP server'); + client = null; + transport = null; + } + catch (error) { + console.error('Error disconnecting:', error); + } +} +async function terminateSession() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + console.log('Terminating session with ID:', transport.sessionId); + await transport.terminateSession(); + console.log('Session terminated successfully'); + // Check if sessionId was cleared after termination + if (!transport.sessionId) { + console.log('Session ID has been cleared'); + sessionId = undefined; + // Also close the transport and clear client objects + await transport.close(); + console.log('Transport closed after session termination'); + client = null; + transport = null; + } + else { + console.log('Server responded with 405 Method Not Allowed (session termination not supported)'); + console.log('Session ID is still active:', transport.sessionId); + } + } + catch (error) { + console.error('Error terminating session:', error); + } +} +async function reconnect() { + if (client) { + await disconnect(); + } + await connect(); +} +async function listTools() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - id: ${tool.name}, name: ${getDisplayName(tool)}, description: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server (${error})`); + } +} +async function callTool(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name, + arguments: args + } + }; + console.log(`Calling tool '${name}' with args:`, args); + const result = await client.request(request, CallToolResultSchema); + console.log('Tool result:'); + const resourceLinks = []; + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else if (item.type === 'resource_link') { + const resourceLink = item; + resourceLinks.push(resourceLink); + console.log(` 📁 Resource Link: ${resourceLink.name}`); + console.log(` URI: ${resourceLink.uri}`); + if (resourceLink.mimeType) { + console.log(` Type: ${resourceLink.mimeType}`); + } + if (resourceLink.description) { + console.log(` Description: ${resourceLink.description}`); + } + } + else if (item.type === 'resource') { + console.log(` [Embedded Resource: ${item.resource.uri}]`); + } + else if (item.type === 'image') { + console.log(` [Image: ${item.mimeType}]`); + } + else if (item.type === 'audio') { + console.log(` [Audio: ${item.mimeType}]`); + } + else { + console.log(` [Unknown content type]:`, item); + } + }); + // Offer to read resource links + if (resourceLinks.length > 0) { + console.log(`\nFound ${resourceLinks.length} resource link(s). Use 'read-resource ' to read their content.`); + } + } + catch (error) { + if (error instanceof UrlElicitationRequiredError) { + console.log('\n🔔 Elicitation Required Error Received:'); + console.log(`Message: ${error.message}`); + for (const e of error.elicitations) { + await handleURLElicitation(e); // For the error handler, we discard the action result because we don't respond to an error response + } + return; + } + console.log(`Error calling tool ${name}: ${error}`); + } +} +async function cleanup() { + if (client && transport) { + try { + // First try to terminate the session gracefully + if (transport.sessionId) { + try { + console.log('Terminating session before exit...'); + await transport.terminateSession(); + console.log('Session terminated successfully'); + } + catch (error) { + console.error('Error terminating session:', error); + } + } + // Then close the transport + await transport.close(); + } + catch (error) { + console.error('Error closing transport:', error); + } + } + process.stdin.setRawMode(false); + readline.close(); + console.log('\nGoodbye!'); + process.exit(0); +} +async function callPaymentConfirmTool() { + console.log('Calling payment-confirm tool...'); + await callTool('payment-confirm', { cartId: 'cart_123' }); +} +async function callThirdPartyAuthTool() { + console.log('Calling third-party-auth tool...'); + await callTool('third-party-auth', { param1: 'test' }); +} +// Set up raw mode for keyboard input to capture Escape key +process.stdin.setRawMode(true); +process.stdin.on('data', async (data) => { + // Check for Escape key (27) + if (data.length === 1 && data[0] === 27) { + console.log('\nESC key pressed. Disconnecting from server...'); + // Abort current operation and disconnect from server + if (client && transport) { + await disconnect(); + console.log('Disconnected. Press Enter to continue.'); + } + else { + console.log('Not connected to server.'); + } + // Re-display the prompt + process.stdout.write('> '); + } +}); +// Handle Ctrl+C +process.on('SIGINT', async () => { + console.log('\nReceived SIGINT. Cleaning up...'); + await cleanup(); +}); +// Start the interactive client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=elicitationUrlExample.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/elicitationUrlExample.js.map b/dist/esm/examples/client/elicitationUrlExample.js.map new file mode 100644 index 000000000..4b5916392 --- /dev/null +++ b/dist/esm/examples/client/elicitationUrlExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.js","sourceRoot":"","sources":["../../../../src/examples/client/elicitationUrlExample.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,mEAAmE;AACnE,gDAAgD;AAChD,uFAAuF;AAC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AAS,EAAE,CAAC;YACtB,MAAM,UAAU,EAAE,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC5C,CAAC;QAED,wBAAwB;QACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,gBAAgB;AAChB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,MAAM,OAAO,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,+BAA+B;AAC/B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/multipleClientsParallel.d.ts b/dist/esm/examples/client/multipleClientsParallel.d.ts new file mode 100644 index 000000000..0ac5af8e5 --- /dev/null +++ b/dist/esm/examples/client/multipleClientsParallel.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=multipleClientsParallel.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/multipleClientsParallel.d.ts.map b/dist/esm/examples/client/multipleClientsParallel.d.ts.map new file mode 100644 index 000000000..91051dc94 --- /dev/null +++ b/dist/esm/examples/client/multipleClientsParallel.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multipleClientsParallel.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/multipleClientsParallel.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/multipleClientsParallel.js b/dist/esm/examples/client/multipleClientsParallel.js new file mode 100644 index 000000000..426485673 --- /dev/null +++ b/dist/esm/examples/client/multipleClientsParallel.js @@ -0,0 +1,132 @@ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { CallToolResultSchema, LoggingMessageNotificationSchema } from '../../types.js'; +/** + * Multiple Clients MCP Example + * + * This client demonstrates how to: + * 1. Create multiple MCP clients in parallel + * 2. Each client calls a single tool + * 3. Track notifications from each client independently + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function createAndRunClient(config) { + console.log(`[${config.id}] Creating client: ${config.name}`); + const client = new Client({ + name: config.name, + version: '1.0.0' + }); + const transport = new StreamableHTTPClientTransport(new URL(serverUrl)); + // Set up client-specific error handler + client.onerror = error => { + console.error(`[${config.id}] Client error:`, error); + }; + // Set up client-specific notification handler + client.setNotificationHandler(LoggingMessageNotificationSchema, notification => { + console.log(`[${config.id}] Notification: ${notification.params.data}`); + }); + try { + // Connect to the server + await client.connect(transport); + console.log(`[${config.id}] Connected to MCP server`); + // Call the specified tool + console.log(`[${config.id}] Calling tool: ${config.toolName}`); + const toolRequest = { + method: 'tools/call', + params: { + name: config.toolName, + arguments: { + ...config.toolArguments, + // Add client ID to arguments for identification in notifications + caller: config.id + } + } + }; + const result = await client.request(toolRequest, CallToolResultSchema); + console.log(`[${config.id}] Tool call completed`); + // Keep the connection open for a bit to receive notifications + await new Promise(resolve => setTimeout(resolve, 5000)); + // Disconnect + await transport.close(); + console.log(`[${config.id}] Disconnected from MCP server`); + return { id: config.id, result }; + } + catch (error) { + console.error(`[${config.id}] Error:`, error); + throw error; + } +} +async function main() { + console.log('MCP Multiple Clients Example'); + console.log('============================'); + console.log(`Server URL: ${serverUrl}`); + console.log(''); + try { + // Define client configurations + const clientConfigs = [ + { + id: 'client1', + name: 'basic-client-1', + toolName: 'start-notification-stream', + toolArguments: { + interval: 3, // 1 second between notifications + count: 5 // Send 5 notifications + } + }, + { + id: 'client2', + name: 'basic-client-2', + toolName: 'start-notification-stream', + toolArguments: { + interval: 2, // 2 seconds between notifications + count: 3 // Send 3 notifications + } + }, + { + id: 'client3', + name: 'basic-client-3', + toolName: 'start-notification-stream', + toolArguments: { + interval: 1, // 0.5 second between notifications + count: 8 // Send 8 notifications + } + } + ]; + // Start all clients in parallel + console.log(`Starting ${clientConfigs.length} clients in parallel...`); + console.log(''); + const clientPromises = clientConfigs.map(config => createAndRunClient(config)); + const results = await Promise.all(clientPromises); + // Display results from all clients + console.log('\n=== Final Results ==='); + results.forEach(({ id, result }) => { + console.log(`\n[${id}] Tool result:`); + if (Array.isArray(result.content)) { + result.content.forEach((item) => { + if (item.type === 'text' && item.text) { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + else { + console.log(` Unexpected result format:`, result); + } + }); + console.log('\n=== All clients completed successfully ==='); + } + catch (error) { + console.error('Error running multiple clients:', error); + process.exit(1); + } +} +// Start the example +main().catch((error) => { + console.error('Error running MCP multiple clients example:', error); + process.exit(1); +}); +//# sourceMappingURL=multipleClientsParallel.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/multipleClientsParallel.js.map b/dist/esm/examples/client/multipleClientsParallel.js.map new file mode 100644 index 000000000..d02ce2280 --- /dev/null +++ b/dist/esm/examples/client/multipleClientsParallel.js.map @@ -0,0 +1 @@ +{"version":3,"file":"multipleClientsParallel.js","sourceRoot":"","sources":["../../../../src/examples/client/multipleClientsParallel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAmB,oBAAoB,EAAE,gCAAgC,EAAkB,MAAM,gBAAgB,CAAC;AAEzH;;;;;;;GAOG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;A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;yBAAM,CAAC;wBACJ,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,WAAW,EAAE,IAAI,CAAC,CAAC;oBACjD,CAAC;gBACL,CAAC,CAAC,CAAC;YACP,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC;YACvD,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,oBAAoB;AACpB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;IACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/parallelToolCallsClient.d.ts b/dist/esm/examples/client/parallelToolCallsClient.d.ts new file mode 100644 index 000000000..e93d4d69d --- /dev/null +++ b/dist/esm/examples/client/parallelToolCallsClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=parallelToolCallsClient.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/parallelToolCallsClient.d.ts.map b/dist/esm/examples/client/parallelToolCallsClient.d.ts.map new file mode 100644 index 000000000..25a3b820c --- /dev/null +++ b/dist/esm/examples/client/parallelToolCallsClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"parallelToolCallsClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/parallelToolCallsClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/parallelToolCallsClient.js b/dist/esm/examples/client/parallelToolCallsClient.js new file mode 100644 index 000000000..9d2a2e915 --- /dev/null +++ b/dist/esm/examples/client/parallelToolCallsClient.js @@ -0,0 +1,174 @@ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { ListToolsResultSchema, CallToolResultSchema, LoggingMessageNotificationSchema } from '../../types.js'; +/** + * Parallel Tool Calls MCP Client + * + * This client demonstrates how to: + * 1. Start multiple tool calls in parallel + * 2. Track notifications from each tool call using a caller parameter + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function main() { + console.log('MCP Parallel Tool Calls Client'); + console.log('=============================='); + console.log(`Connecting to server at: ${serverUrl}`); + let client; + let transport; + try { + // Create client with streamable HTTP transport + client = new Client({ + name: 'parallel-tool-calls-client', + version: '1.0.0' + }); + client.onerror = error => { + console.error('Client error:', error); + }; + // Connect to the server + transport = new StreamableHTTPClientTransport(new URL(serverUrl)); + await client.connect(transport); + console.log('Successfully connected to MCP server'); + // Set up notification handler with caller identification + client.setNotificationHandler(LoggingMessageNotificationSchema, notification => { + console.log(`Notification: ${notification.params.data}`); + }); + console.log('List tools'); + const toolsRequest = await listTools(client); + console.log('Tools: ', toolsRequest); + // 2. Start multiple notification tools in parallel + console.log('\n=== Starting Multiple Notification Streams in Parallel ==='); + const toolResults = await startParallelNotificationTools(client); + // Log the results from each tool call + for (const [caller, result] of Object.entries(toolResults)) { + console.log(`\n=== Tool result for ${caller} ===`); + result.content.forEach((item) => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + // 3. Wait for all notifications (10 seconds) + console.log('\n=== Waiting for all notifications ==='); + await new Promise(resolve => setTimeout(resolve, 10000)); + // 4. Disconnect + console.log('\n=== Disconnecting ==='); + await transport.close(); + console.log('Disconnected from MCP server'); + } + catch (error) { + console.error('Error running client:', error); + process.exit(1); + } +} +/** + * List available tools on the server + */ +async function listTools(client) { + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - ${tool.name}: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server: ${error}`); + } +} +/** + * Start multiple notification tools in parallel with different configurations + * Each tool call includes a caller parameter to identify its notifications + */ +async function startParallelNotificationTools(client) { + try { + // Define multiple tool calls with different configurations + const toolCalls = [ + { + caller: 'fast-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 2, // 0.5 second between notifications + count: 10, // Send 10 notifications + caller: 'fast-notifier' // Identify this tool call + } + } + } + }, + { + caller: 'slow-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 5, // 2 seconds between notifications + count: 5, // Send 5 notifications + caller: 'slow-notifier' // Identify this tool call + } + } + } + }, + { + caller: 'burst-notifier', + request: { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 1, // 0.1 second between notifications + count: 3, // Send just 3 notifications + caller: 'burst-notifier' // Identify this tool call + } + } + } + } + ]; + console.log(`Starting ${toolCalls.length} notification tools in parallel...`); + // Start all tool calls in parallel + const toolPromises = toolCalls.map(({ caller, request }) => { + console.log(`Starting tool call for ${caller}...`); + return client + .request(request, CallToolResultSchema) + .then(result => ({ caller, result })) + .catch(error => { + console.error(`Error in tool call for ${caller}:`, error); + throw error; + }); + }); + // Wait for all tool calls to complete + const results = await Promise.all(toolPromises); + // Organize results by caller + const resultsByTool = {}; + results.forEach(({ caller, result }) => { + resultsByTool[caller] = result; + }); + return resultsByTool; + } + catch (error) { + console.error(`Error starting parallel notification tools:`, error); + throw error; + } +} +// Start the client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=parallelToolCallsClient.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/parallelToolCallsClient.js.map b/dist/esm/examples/client/parallelToolCallsClient.js.map new file mode 100644 index 000000000..0a044818e --- /dev/null +++ b/dist/esm/examples/client/parallelToolCallsClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"parallelToolCallsClient.js","sourceRoot":"","sources":["../../../../src/examples/client/parallelToolCallsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAEH,qBAAqB,EACrB,oBAAoB,EACpB,gCAAgC,EAEnC,MAAM,gBAAgB,CAAC;AAExB;;;;;;GAMG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,2BAA2B,CAAC;AAEzD,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,EAAE,CAAC,CAAC;IAErD,IAAI,MAAc,CAAC;IACnB,IAAI,SAAwC,CAAC;IAE7C,IAAI,CAAC;QACD,+CAA+C;QAC/C,MAAM,GAAG,IAAI,MAAM,CAAC;YAChB,IAAI,EAAE,4BAA4B;YAClC,OAAO,EAAE,OAAO;SACnB,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE;YACrB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEF,wBAAwB;QACxB,SAAS,GAAG,IAAI,6BAA6B,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QAClE,MAAM,MAAM,CAAC,OAAO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E,MAAM,EAAE,CAAC,CAAC;iBACpC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,0BAA0B,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC1D,MAAM,KAAK,CAAC;YAChB,CAAC,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;QAEH,sCAAsC;QACtC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAEhD,6BAA6B;QAC7B,MAAM,aAAa,GAAmC,EAAE,CAAC;QACzD,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;YACnC,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;QACpE,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED,mBAAmB;AACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleClientCredentials.d.ts b/dist/esm/examples/client/simpleClientCredentials.d.ts new file mode 100644 index 000000000..876d25d3a --- /dev/null +++ b/dist/esm/examples/client/simpleClientCredentials.d.ts @@ -0,0 +1,20 @@ +#!/usr/bin/env node +/** + * Example demonstrating client_credentials grant for machine-to-machine authentication. + * + * Supports two authentication methods based on environment variables: + * + * 1. client_secret_basic (default): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_SECRET - OAuth client secret (required) + * + * 2. private_key_jwt (when MCP_CLIENT_PRIVATE_KEY_PEM is set): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_PRIVATE_KEY_PEM - PEM-encoded private key for JWT signing (required) + * MCP_CLIENT_ALGORITHM - Signing algorithm (default: RS256) + * + * Common: + * MCP_SERVER_URL - Server URL (default: http://localhost:3000/mcp) + */ +export {}; +//# sourceMappingURL=simpleClientCredentials.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleClientCredentials.d.ts.map b/dist/esm/examples/client/simpleClientCredentials.d.ts.map new file mode 100644 index 000000000..7a935db41 --- /dev/null +++ b/dist/esm/examples/client/simpleClientCredentials.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleClientCredentials.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleClientCredentials.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;GAgBG"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleClientCredentials.js b/dist/esm/examples/client/simpleClientCredentials.js new file mode 100644 index 000000000..7694badfa --- /dev/null +++ b/dist/esm/examples/client/simpleClientCredentials.js @@ -0,0 +1,68 @@ +#!/usr/bin/env node +/** + * Example demonstrating client_credentials grant for machine-to-machine authentication. + * + * Supports two authentication methods based on environment variables: + * + * 1. client_secret_basic (default): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_SECRET - OAuth client secret (required) + * + * 2. private_key_jwt (when MCP_CLIENT_PRIVATE_KEY_PEM is set): + * MCP_CLIENT_ID - OAuth client ID (required) + * MCP_CLIENT_PRIVATE_KEY_PEM - PEM-encoded private key for JWT signing (required) + * MCP_CLIENT_ALGORITHM - Signing algorithm (default: RS256) + * + * Common: + * MCP_SERVER_URL - Server URL (default: http://localhost:3000/mcp) + */ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { ClientCredentialsProvider, PrivateKeyJwtProvider } from '../../client/auth-extensions.js'; +const DEFAULT_SERVER_URL = process.env.MCP_SERVER_URL || 'http://localhost:3000/mcp'; +function createProvider() { + const clientId = process.env.MCP_CLIENT_ID; + if (!clientId) { + console.error('MCP_CLIENT_ID environment variable is required'); + process.exit(1); + } + // If private key is provided, use private_key_jwt authentication + const privateKeyPem = process.env.MCP_CLIENT_PRIVATE_KEY_PEM; + if (privateKeyPem) { + const algorithm = process.env.MCP_CLIENT_ALGORITHM || 'RS256'; + console.log('Using private_key_jwt authentication'); + return new PrivateKeyJwtProvider({ + clientId, + privateKey: privateKeyPem, + algorithm + }); + } + // Otherwise, use client_secret_basic authentication + const clientSecret = process.env.MCP_CLIENT_SECRET; + if (!clientSecret) { + console.error('MCP_CLIENT_SECRET or MCP_CLIENT_PRIVATE_KEY_PEM environment variable is required'); + process.exit(1); + } + console.log('Using client_secret_basic authentication'); + return new ClientCredentialsProvider({ + clientId, + clientSecret + }); +} +async function main() { + const provider = createProvider(); + const client = new Client({ name: 'client-credentials-example', version: '1.0.0' }, { capabilities: {} }); + const transport = new StreamableHTTPClientTransport(new URL(DEFAULT_SERVER_URL), { + authProvider: provider + }); + await client.connect(transport); + console.log('Connected successfully.'); + const tools = await client.listTools(); + console.log('Available tools:', tools.tools.map(t => t.name).join(', ') || '(none)'); + await transport.close(); +} +main().catch(err => { + console.error(err); + process.exit(1); +}); +//# sourceMappingURL=simpleClientCredentials.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleClientCredentials.js.map b/dist/esm/examples/client/simpleClientCredentials.js.map new file mode 100644 index 000000000..f6e7e2117 --- /dev/null +++ b/dist/esm/examples/client/simpleClientCredentials.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleClientCredentials.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleClientCredentials.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAA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E,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IAE1G,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,EAAE;QAC7E,YAAY,EAAE,QAAQ;KACzB,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC;IAErF,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClient.d.ts b/dist/esm/examples/client/simpleOAuthClient.d.ts new file mode 100644 index 000000000..e4b43dbc0 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClient.d.ts @@ -0,0 +1,3 @@ +#!/usr/bin/env node +export {}; +//# sourceMappingURL=simpleOAuthClient.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClient.d.ts.map b/dist/esm/examples/client/simpleOAuthClient.d.ts.map new file mode 100644 index 000000000..c09eef86e --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClient.js b/dist/esm/examples/client/simpleOAuthClient.js new file mode 100644 index 000000000..ad63365c0 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClient.js @@ -0,0 +1,411 @@ +#!/usr/bin/env node +import { createServer } from 'node:http'; +import { createInterface } from 'node:readline'; +import { URL } from 'node:url'; +import { exec } from 'node:child_process'; +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { CallToolResultSchema, ListToolsResultSchema } from '../../types.js'; +import { UnauthorizedError } from '../../client/auth.js'; +import { InMemoryOAuthClientProvider } from './simpleOAuthClientProvider.js'; +// Configuration +const DEFAULT_SERVER_URL = 'http://localhost:3000/mcp'; +const CALLBACK_PORT = 8090; // Use different port than auth server (3001) +const CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`; +/** + * Interactive MCP client with OAuth authentication + * Demonstrates the complete OAuth flow with browser-based authorization + */ +class InteractiveOAuthClient { + constructor(serverUrl, clientMetadataUrl) { + this.serverUrl = serverUrl; + this.clientMetadataUrl = clientMetadataUrl; + this.client = null; + this.rl = createInterface({ + input: process.stdin, + output: process.stdout + }); + } + /** + * Prompts user for input via readline + */ + async question(query) { + return new Promise(resolve => { + this.rl.question(query, resolve); + }); + } + /** + * Opens the authorization URL in the user's default browser + */ + async openBrowser(url) { + console.log(`🌐 Opening browser for authorization: ${url}`); + const command = `open "${url}"`; + exec(command, error => { + if (error) { + console.error(`Failed to open browser: ${error.message}`); + console.log(`Please manually open: ${url}`); + } + }); + } + /** + * Example OAuth callback handler - in production, use a more robust approach + * for handling callbacks and storing tokens + */ + /** + * Starts a temporary HTTP server to receive the OAuth callback + */ + async waitForOAuthCallback() { + return new Promise((resolve, reject) => { + const server = createServer((req, res) => { + // Ignore favicon requests + if (req.url === '/favicon.ico') { + res.writeHead(404); + res.end(); + return; + } + console.log(`📥 Received callback: ${req.url}`); + const parsedUrl = new URL(req.url || '', 'http://localhost'); + const code = parsedUrl.searchParams.get('code'); + const error = parsedUrl.searchParams.get('error'); + if (code) { + console.log(`✅ Authorization code received: ${code === null || code === void 0 ? void 0 : code.substring(0, 10)}...`); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Successful!

+

You can close this window and return to the terminal.

+ + + + `); + resolve(code); + setTimeout(() => server.close(), 3000); + } + else if (error) { + console.log(`❌ Authorization error: ${error}`); + res.writeHead(400, { 'Content-Type': 'text/html' }); + res.end(` + + +

Authorization Failed

+

Error: ${error}

+ + + `); + reject(new Error(`OAuth authorization failed: ${error}`)); + } + else { + console.log(`❌ No authorization code or error in callback`); + res.writeHead(400); + res.end('Bad request'); + reject(new Error('No authorization code provided')); + } + }); + server.listen(CALLBACK_PORT, () => { + console.log(`OAuth callback server started on http://localhost:${CALLBACK_PORT}`); + }); + }); + } + async attemptConnection(oauthProvider) { + console.log('🚢 Creating transport with OAuth provider...'); + const baseUrl = new URL(this.serverUrl); + const transport = new StreamableHTTPClientTransport(baseUrl, { + authProvider: oauthProvider + }); + console.log('🚢 Transport created'); + try { + console.log('🔌 Attempting connection (this will trigger OAuth redirect)...'); + await this.client.connect(transport); + console.log('✅ Connected successfully'); + } + catch (error) { + if (error instanceof UnauthorizedError) { + console.log('🔐 OAuth required - waiting for authorization...'); + const callbackPromise = this.waitForOAuthCallback(); + const authCode = await callbackPromise; + await transport.finishAuth(authCode); + console.log('🔐 Authorization code received:', authCode); + console.log('🔌 Reconnecting with authenticated transport...'); + await this.attemptConnection(oauthProvider); + } + else { + console.error('❌ Connection failed with non-auth error:', error); + throw error; + } + } + } + /** + * Establishes connection to the MCP server with OAuth authentication + */ + async connect() { + console.log(`🔗 Attempting to connect to ${this.serverUrl}...`); + const clientMetadata = { + client_name: 'Simple OAuth MCP Client', + redirect_uris: [CALLBACK_URL], + grant_types: ['authorization_code', 'refresh_token'], + response_types: ['code'], + token_endpoint_auth_method: 'client_secret_post' + }; + console.log('🔐 Creating OAuth provider...'); + const oauthProvider = new InMemoryOAuthClientProvider(CALLBACK_URL, clientMetadata, (redirectUrl) => { + console.log(`📌 OAuth redirect handler called - opening browser`); + console.log(`Opening browser to: ${redirectUrl.toString()}`); + this.openBrowser(redirectUrl.toString()); + }, this.clientMetadataUrl); + console.log('🔐 OAuth provider created'); + console.log('👤 Creating MCP client...'); + this.client = new Client({ + name: 'simple-oauth-client', + version: '1.0.0' + }, { capabilities: {} }); + console.log('👤 Client created'); + console.log('🔐 Starting OAuth flow...'); + await this.attemptConnection(oauthProvider); + // Start interactive loop + await this.interactiveLoop(); + } + /** + * Main interactive loop for user commands + */ + async interactiveLoop() { + console.log('\n🎯 Interactive MCP Client with OAuth'); + console.log('Commands:'); + console.log(' list - List available tools'); + console.log(' call [args] - Call a tool'); + console.log(' stream [args] - Call a tool with streaming (shows task status)'); + console.log(' quit - Exit the client'); + console.log(); + while (true) { + try { + const command = await this.question('mcp> '); + if (!command.trim()) { + continue; + } + if (command === 'quit') { + console.log('\n👋 Goodbye!'); + this.close(); + process.exit(0); + } + else if (command === 'list') { + await this.listTools(); + } + else if (command.startsWith('call ')) { + await this.handleCallTool(command); + } + else if (command.startsWith('stream ')) { + await this.handleStreamTool(command); + } + else { + console.log("❌ Unknown command. Try 'list', 'call ', 'stream ', or 'quit'"); + } + } + catch (error) { + if (error instanceof Error && error.message === 'SIGINT') { + console.log('\n\n👋 Goodbye!'); + break; + } + console.error('❌ Error:', error); + } + } + } + async listTools() { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + const request = { + method: 'tools/list', + params: {} + }; + const result = await this.client.request(request, ListToolsResultSchema); + if (result.tools && result.tools.length > 0) { + console.log('\n📋 Available tools:'); + result.tools.forEach((tool, index) => { + console.log(`${index + 1}. ${tool.name}`); + if (tool.description) { + console.log(` Description: ${tool.description}`); + } + console.log(); + }); + } + else { + console.log('No tools available'); + } + } + catch (error) { + console.error('❌ Failed to list tools:', error); + } + } + async handleCallTool(command) { + const parts = command.split(/\s+/); + const toolName = parts[1]; + if (!toolName) { + console.log('❌ Please specify a tool name'); + return; + } + // Parse arguments (simple JSON-like format) + let toolArgs = {}; + if (parts.length > 2) { + const argsString = parts.slice(2).join(' '); + try { + toolArgs = JSON.parse(argsString); + } + catch (_a) { + console.log('❌ Invalid arguments format (expected JSON)'); + return; + } + } + await this.callTool(toolName, toolArgs); + } + async callTool(toolName, toolArgs) { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name: toolName, + arguments: toolArgs + } + }; + const result = await this.client.request(request, CallToolResultSchema); + console.log(`\n🔧 Tool '${toolName}' result:`); + if (result.content) { + result.content.forEach(content => { + if (content.type === 'text') { + console.log(content.text); + } + else { + console.log(content); + } + }); + } + else { + console.log(result); + } + } + catch (error) { + console.error(`❌ Failed to call tool '${toolName}':`, error); + } + } + async handleStreamTool(command) { + const parts = command.split(/\s+/); + const toolName = parts[1]; + if (!toolName) { + console.log('❌ Please specify a tool name'); + return; + } + // Parse arguments (simple JSON-like format) + let toolArgs = {}; + if (parts.length > 2) { + const argsString = parts.slice(2).join(' '); + try { + toolArgs = JSON.parse(argsString); + } + catch (_a) { + console.log('❌ Invalid arguments format (expected JSON)'); + return; + } + } + await this.streamTool(toolName, toolArgs); + } + async streamTool(toolName, toolArgs) { + if (!this.client) { + console.log('❌ Not connected to server'); + return; + } + try { + // Using the experimental tasks API - WARNING: may change without notice + console.log(`\n🔧 Streaming tool '${toolName}'...`); + const stream = this.client.experimental.tasks.callToolStream({ + name: toolName, + arguments: toolArgs + }, CallToolResultSchema, { + task: { + taskId: `task-${Date.now()}`, + ttl: 60000 + } + }); + // Iterate through all messages yielded by the generator + for await (const message of stream) { + switch (message.type) { + case 'taskCreated': + console.log(`✓ Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`⟳ Status: ${message.task.status}`); + if (message.task.statusMessage) { + console.log(` ${message.task.statusMessage}`); + } + break; + case 'result': + console.log('✓ Completed!'); + message.result.content.forEach(content => { + if (content.type === 'text') { + console.log(content.text); + } + else { + console.log(content); + } + }); + break; + case 'error': + console.log('✗ Error:'); + console.log(` ${message.error.message}`); + break; + } + } + } + catch (error) { + console.error(`❌ Failed to stream tool '${toolName}':`, error); + } + } + close() { + this.rl.close(); + if (this.client) { + // Note: Client doesn't have a close method in the current implementation + // This would typically close the transport connection + } + } +} +/** + * Main entry point + */ +async function main() { + const args = process.argv.slice(2); + const serverUrl = args[0] || DEFAULT_SERVER_URL; + const clientMetadataUrl = args[1]; + console.log('🚀 Simple MCP OAuth Client'); + console.log(`Connecting to: ${serverUrl}`); + if (clientMetadataUrl) { + console.log(`Client Metadata URL: ${clientMetadataUrl}`); + } + console.log(); + const client = new InteractiveOAuthClient(serverUrl, clientMetadataUrl); + // Handle graceful shutdown + process.on('SIGINT', () => { + console.log('\n\n👋 Goodbye!'); + client.close(); + process.exit(0); + }); + try { + await client.connect(); + } + catch (error) { + console.error('Failed to start client:', error); + process.exit(1); + } + finally { + client.close(); + } +} +// Run if this file is executed directly +main().catch(error => { + console.error('Unhandled error:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleOAuthClient.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClient.js.map b/dist/esm/examples/client/simpleOAuthClient.js.map new file mode 100644 index 000000000..c2e2f8cee --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClient.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClient.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EA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,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;AACL,CAAC;AAED,wCAAwC;AACxC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClientProvider.d.ts b/dist/esm/examples/client/simpleOAuthClientProvider.d.ts new file mode 100644 index 000000000..092616cf5 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClientProvider.d.ts @@ -0,0 +1,26 @@ +import { OAuthClientProvider } from '../../client/auth.js'; +import { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from '../../shared/auth.js'; +/** + * In-memory OAuth client provider for demonstration purposes + * In production, you should persist tokens securely + */ +export declare class InMemoryOAuthClientProvider implements OAuthClientProvider { + private readonly _redirectUrl; + private readonly _clientMetadata; + readonly clientMetadataUrl?: string | undefined; + private _clientInformation?; + private _tokens?; + private _codeVerifier?; + constructor(_redirectUrl: string | URL, _clientMetadata: OAuthClientMetadata, onRedirect?: (url: URL) => void, clientMetadataUrl?: string | undefined); + private _onRedirect; + get redirectUrl(): string | URL; + get clientMetadata(): OAuthClientMetadata; + clientInformation(): OAuthClientInformationMixed | undefined; + saveClientInformation(clientInformation: OAuthClientInformationMixed): void; + tokens(): OAuthTokens | undefined; + saveTokens(tokens: OAuthTokens): void; + redirectToAuthorization(authorizationUrl: URL): void; + saveCodeVerifier(codeVerifier: string): void; + codeVerifier(): string; +} +//# sourceMappingURL=simpleOAuthClientProvider.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClientProvider.d.ts.map b/dist/esm/examples/client/simpleOAuthClientProvider.d.ts.map new file mode 100644 index 000000000..21efe9444 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClientProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClientProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAErG;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IAM/D,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe;aAEhB,iBAAiB,CAAC,EAAE,MAAM;IAR9C,OAAO,CAAC,kBAAkB,CAAC,CAA8B;IACzD,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAS;gBAGV,YAAY,EAAE,MAAM,GAAG,GAAG,EAC1B,eAAe,EAAE,mBAAmB,EACrD,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,EACf,iBAAiB,CAAC,EAAE,MAAM,YAAA;IAS9C,OAAO,CAAC,WAAW,CAAqB;IAExC,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,CAE9B;IAED,IAAI,cAAc,IAAI,mBAAmB,CAExC;IAED,iBAAiB,IAAI,2BAA2B,GAAG,SAAS;IAI5D,qBAAqB,CAAC,iBAAiB,EAAE,2BAA2B,GAAG,IAAI;IAI3E,MAAM,IAAI,WAAW,GAAG,SAAS;IAIjC,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIrC,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,IAAI;IAIpD,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAI5C,YAAY,IAAI,MAAM;CAMzB"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClientProvider.js b/dist/esm/examples/client/simpleOAuthClientProvider.js new file mode 100644 index 000000000..7c350d131 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClientProvider.js @@ -0,0 +1,47 @@ +/** + * In-memory OAuth client provider for demonstration purposes + * In production, you should persist tokens securely + */ +export class InMemoryOAuthClientProvider { + constructor(_redirectUrl, _clientMetadata, onRedirect, clientMetadataUrl) { + this._redirectUrl = _redirectUrl; + this._clientMetadata = _clientMetadata; + this.clientMetadataUrl = clientMetadataUrl; + this._onRedirect = + onRedirect || + (url => { + console.log(`Redirect to: ${url.toString()}`); + }); + } + get redirectUrl() { + return this._redirectUrl; + } + get clientMetadata() { + return this._clientMetadata; + } + clientInformation() { + return this._clientInformation; + } + saveClientInformation(clientInformation) { + this._clientInformation = clientInformation; + } + tokens() { + return this._tokens; + } + saveTokens(tokens) { + this._tokens = tokens; + } + redirectToAuthorization(authorizationUrl) { + this._onRedirect(authorizationUrl); + } + saveCodeVerifier(codeVerifier) { + this._codeVerifier = codeVerifier; + } + codeVerifier() { + if (!this._codeVerifier) { + throw new Error('No code verifier saved'); + } + return this._codeVerifier; + } +} +//# sourceMappingURL=simpleOAuthClientProvider.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleOAuthClientProvider.js.map b/dist/esm/examples/client/simpleOAuthClientProvider.js.map new file mode 100644 index 000000000..88f15cde5 --- /dev/null +++ b/dist/esm/examples/client/simpleOAuthClientProvider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleOAuthClientProvider.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleOAuthClientProvider.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,OAAO,2BAA2B;IAKpC,YACqB,YAA0B,EAC1B,eAAoC,EACrD,UAA+B,EACf,iBAA0B;QAHzB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,oBAAe,GAAf,eAAe,CAAqB;QAErC,sBAAiB,GAAjB,iBAAiB,CAAS;QAE1C,IAAI,CAAC,WAAW;YACZ,UAAU;gBACV,CAAC,GAAG,CAAC,EAAE;oBACH,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAClD,CAAC,CAAC,CAAC;IACX,CAAC;IAID,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED,qBAAqB,CAAC,iBAA8C;QAChE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChD,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,MAAmB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,uBAAuB,CAAC,gBAAqB;QACzC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB,CAAC,YAAoB;QACjC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACtC,CAAC;IAED,YAAY;QACR,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleStreamableHttp.d.ts b/dist/esm/examples/client/simpleStreamableHttp.d.ts new file mode 100644 index 000000000..a20be42ca --- /dev/null +++ b/dist/esm/examples/client/simpleStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleStreamableHttp.d.ts.map b/dist/esm/examples/client/simpleStreamableHttp.d.ts.map new file mode 100644 index 000000000..28406b0c1 --- /dev/null +++ b/dist/esm/examples/client/simpleStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleStreamableHttp.js b/dist/esm/examples/client/simpleStreamableHttp.js new file mode 100644 index 000000000..2f501ef47 --- /dev/null +++ b/dist/esm/examples/client/simpleStreamableHttp.js @@ -0,0 +1,818 @@ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { createInterface } from 'node:readline'; +import { ListToolsResultSchema, CallToolResultSchema, ListPromptsResultSchema, GetPromptResultSchema, ListResourcesResultSchema, LoggingMessageNotificationSchema, ResourceListChangedNotificationSchema, ElicitRequestSchema, ReadResourceResultSchema, RELATED_TASK_META_KEY, ErrorCode, McpError } from '../../types.js'; +import { getDisplayName } from '../../shared/metadataUtils.js'; +import { Ajv } from 'ajv'; +// Create readline interface for user input +const readline = createInterface({ + input: process.stdin, + output: process.stdout +}); +// Track received notifications for debugging resumability +let notificationCount = 0; +// Global client and transport for interactive commands +let client = null; +let transport = null; +let serverUrl = 'http://localhost:3000/mcp'; +let notificationsToolLastEventId = undefined; +let sessionId = undefined; +async function main() { + console.log('MCP Interactive Client'); + console.log('====================='); + // Connect to server immediately with default settings + await connect(); + // Print help and start the command loop + printHelp(); + commandLoop(); +} +function printHelp() { + console.log('\nAvailable commands:'); + console.log(' connect [url] - Connect to MCP server (default: http://localhost:3000/mcp)'); + console.log(' disconnect - Disconnect from server'); + console.log(' terminate-session - Terminate the current session'); + console.log(' reconnect - Reconnect to the server'); + console.log(' list-tools - List available tools'); + console.log(' call-tool [args] - Call a tool with optional JSON arguments'); + console.log(' call-tool-task [args] - Call a tool with task-based execution (example: call-tool-task delay {"duration":3000})'); + console.log(' greet [name] - Call the greet tool'); + console.log(' multi-greet [name] - Call the multi-greet tool with notifications'); + console.log(' collect-info [type] - Test form elicitation with collect-user-info tool (contact/preferences/feedback)'); + console.log(' start-notifications [interval] [count] - Start periodic notifications'); + console.log(' run-notifications-tool-with-resumability [interval] [count] - Run notification tool with resumability'); + console.log(' list-prompts - List available prompts'); + console.log(' get-prompt [name] [args] - Get a prompt with optional JSON arguments'); + console.log(' list-resources - List available resources'); + console.log(' read-resource - Read a specific resource by URI'); + console.log(' help - Show this help'); + console.log(' quit - Exit the program'); +} +function commandLoop() { + readline.question('\n> ', async (input) => { + var _a; + const args = input.trim().split(/\s+/); + const command = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase(); + try { + switch (command) { + case 'connect': + await connect(args[1]); + break; + case 'disconnect': + await disconnect(); + break; + case 'terminate-session': + await terminateSession(); + break; + case 'reconnect': + await reconnect(); + break; + case 'list-tools': + await listTools(); + break; + case 'call-tool': + if (args.length < 2) { + console.log('Usage: call-tool [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_b) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callTool(toolName, toolArgs); + } + break; + case 'greet': + await callGreetTool(args[1] || 'MCP User'); + break; + case 'multi-greet': + await callMultiGreetTool(args[1] || 'MCP User'); + break; + case 'collect-info': + await callCollectInfoTool(args[1] || 'contact'); + break; + case 'start-notifications': { + const interval = args[1] ? parseInt(args[1], 10) : 2000; + const count = args[2] ? parseInt(args[2], 10) : 10; + await startNotifications(interval, count); + break; + } + case 'run-notifications-tool-with-resumability': { + const interval = args[1] ? parseInt(args[1], 10) : 2000; + const count = args[2] ? parseInt(args[2], 10) : 10; + await runNotificationsToolWithResumability(interval, count); + break; + } + case 'call-tool-task': + if (args.length < 2) { + console.log('Usage: call-tool-task [args]'); + } + else { + const toolName = args[1]; + let toolArgs = {}; + if (args.length > 2) { + try { + toolArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_c) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await callToolTask(toolName, toolArgs); + } + break; + case 'list-prompts': + await listPrompts(); + break; + case 'get-prompt': + if (args.length < 2) { + console.log('Usage: get-prompt [args]'); + } + else { + const promptName = args[1]; + let promptArgs = {}; + if (args.length > 2) { + try { + promptArgs = JSON.parse(args.slice(2).join(' ')); + } + catch (_d) { + console.log('Invalid JSON arguments. Using empty args.'); + } + } + await getPrompt(promptName, promptArgs); + } + break; + case 'list-resources': + await listResources(); + break; + case 'read-resource': + if (args.length < 2) { + console.log('Usage: read-resource '); + } + else { + await readResource(args[1]); + } + break; + case 'help': + printHelp(); + break; + case 'quit': + case 'exit': + await cleanup(); + return; + default: + if (command) { + console.log(`Unknown command: ${command}`); + } + break; + } + } + catch (error) { + console.error(`Error executing command: ${error}`); + } + // Continue the command loop + commandLoop(); + }); +} +async function connect(url) { + if (client) { + console.log('Already connected. Disconnect first.'); + return; + } + if (url) { + serverUrl = url; + } + console.log(`Connecting to ${serverUrl}...`); + try { + // Create a new client with form elicitation capability + client = new Client({ + name: 'example-client', + version: '1.0.0' + }, { + capabilities: { + elicitation: { + form: {} + } + } + }); + client.onerror = error => { + console.error('\x1b[31mClient error:', error, '\x1b[0m'); + }; + // Set up elicitation request handler with proper validation + client.setRequestHandler(ElicitRequestSchema, async (request) => { + var _a, _b, _c; + if (request.params.mode !== 'form') { + throw new McpError(ErrorCode.InvalidParams, `Unsupported elicitation mode: ${request.params.mode}`); + } + console.log('\n🔔 Elicitation (form) Request Received:'); + console.log(`Message: ${request.params.message}`); + console.log(`Related Task: ${(_b = (_a = request.params._meta) === null || _a === void 0 ? void 0 : _a[RELATED_TASK_META_KEY]) === null || _b === void 0 ? void 0 : _b.taskId}`); + console.log('Requested Schema:'); + console.log(JSON.stringify(request.params.requestedSchema, null, 2)); + const schema = request.params.requestedSchema; + const properties = schema.properties; + const required = schema.required || []; + // Set up AJV validator for the requested schema + const ajv = new Ajv(); + const validate = ajv.compile(schema); + let attempts = 0; + const maxAttempts = 3; + while (attempts < maxAttempts) { + attempts++; + console.log(`\nPlease provide the following information (attempt ${attempts}/${maxAttempts}):`); + const content = {}; + let inputCancelled = false; + // Collect input for each field + for (const [fieldName, fieldSchema] of Object.entries(properties)) { + const field = fieldSchema; + const isRequired = required.includes(fieldName); + let prompt = `${field.title || fieldName}`; + // Add helpful information to the prompt + if (field.description) { + prompt += ` (${field.description})`; + } + if (field.enum) { + prompt += ` [options: ${field.enum.join(', ')}]`; + } + if (field.type === 'number' || field.type === 'integer') { + if (field.minimum !== undefined && field.maximum !== undefined) { + prompt += ` [${field.minimum}-${field.maximum}]`; + } + else if (field.minimum !== undefined) { + prompt += ` [min: ${field.minimum}]`; + } + else if (field.maximum !== undefined) { + prompt += ` [max: ${field.maximum}]`; + } + } + if (field.type === 'string' && field.format) { + prompt += ` [format: ${field.format}]`; + } + if (isRequired) { + prompt += ' *required*'; + } + if (field.default !== undefined) { + prompt += ` [default: ${field.default}]`; + } + prompt += ': '; + const answer = await new Promise(resolve => { + readline.question(prompt, input => { + resolve(input.trim()); + }); + }); + // Check for cancellation + if (answer.toLowerCase() === 'cancel' || answer.toLowerCase() === 'c') { + inputCancelled = true; + break; + } + // Parse and validate the input + try { + if (answer === '' && field.default !== undefined) { + content[fieldName] = field.default; + } + else if (answer === '' && !isRequired) { + // Skip optional empty fields + continue; + } + else if (answer === '') { + throw new Error(`${fieldName} is required`); + } + else { + // Parse the value based on type + let parsedValue; + if (field.type === 'boolean') { + parsedValue = answer.toLowerCase() === 'true' || answer.toLowerCase() === 'yes' || answer === '1'; + } + else if (field.type === 'number') { + parsedValue = parseFloat(answer); + if (isNaN(parsedValue)) { + throw new Error(`${fieldName} must be a valid number`); + } + } + else if (field.type === 'integer') { + parsedValue = parseInt(answer, 10); + if (isNaN(parsedValue)) { + throw new Error(`${fieldName} must be a valid integer`); + } + } + else if (field.enum) { + if (!field.enum.includes(answer)) { + throw new Error(`${fieldName} must be one of: ${field.enum.join(', ')}`); + } + parsedValue = answer; + } + else { + parsedValue = answer; + } + content[fieldName] = parsedValue; + } + } + catch (error) { + console.log(`❌ Error: ${error}`); + // Continue to next attempt + break; + } + } + if (inputCancelled) { + return { action: 'cancel' }; + } + // If we didn't complete all fields due to an error, try again + if (Object.keys(content).length !== + Object.keys(properties).filter(name => required.includes(name) || content[name] !== undefined).length) { + if (attempts < maxAttempts) { + console.log('Please try again...'); + continue; + } + else { + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + } + } + // Validate the complete object against the schema + const isValid = validate(content); + if (!isValid) { + console.log('❌ Validation errors:'); + (_c = validate.errors) === null || _c === void 0 ? void 0 : _c.forEach(error => { + console.log(` - ${error.instancePath || 'root'}: ${error.message}`); + }); + if (attempts < maxAttempts) { + console.log('Please correct the errors and try again...'); + continue; + } + else { + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + } + } + // Show the collected data and ask for confirmation + console.log('\n✅ Collected data:'); + console.log(JSON.stringify(content, null, 2)); + const confirmAnswer = await new Promise(resolve => { + readline.question('\nSubmit this information? (yes/no/cancel): ', input => { + resolve(input.trim().toLowerCase()); + }); + }); + if (confirmAnswer === 'yes' || confirmAnswer === 'y') { + return { + action: 'accept', + content + }; + } + else if (confirmAnswer === 'cancel' || confirmAnswer === 'c') { + return { action: 'cancel' }; + } + else if (confirmAnswer === 'no' || confirmAnswer === 'n') { + if (attempts < maxAttempts) { + console.log('Please re-enter the information...'); + continue; + } + else { + return { action: 'decline' }; + } + } + } + console.log('Maximum attempts reached. Declining request.'); + return { action: 'decline' }; + }); + transport = new StreamableHTTPClientTransport(new URL(serverUrl), { + sessionId: sessionId + }); + // Set up notification handlers + client.setNotificationHandler(LoggingMessageNotificationSchema, notification => { + notificationCount++; + console.log(`\nNotification #${notificationCount}: ${notification.params.level} - ${notification.params.data}`); + // Re-display the prompt + process.stdout.write('> '); + }); + client.setNotificationHandler(ResourceListChangedNotificationSchema, async (_) => { + console.log(`\nResource list changed notification received!`); + try { + if (!client) { + console.log('Client disconnected, cannot fetch resources'); + return; + } + const resourcesResult = await client.request({ + method: 'resources/list', + params: {} + }, ListResourcesResultSchema); + console.log('Available resources count:', resourcesResult.resources.length); + } + catch (_a) { + console.log('Failed to list resources after change notification'); + } + // Re-display the prompt + process.stdout.write('> '); + }); + // Connect the client + await client.connect(transport); + sessionId = transport.sessionId; + console.log('Transport created with session ID:', sessionId); + console.log('Connected to MCP server'); + } + catch (error) { + console.error('Failed to connect:', error); + client = null; + transport = null; + } +} +async function disconnect() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + await transport.close(); + console.log('Disconnected from MCP server'); + client = null; + transport = null; + } + catch (error) { + console.error('Error disconnecting:', error); + } +} +async function terminateSession() { + if (!client || !transport) { + console.log('Not connected.'); + return; + } + try { + console.log('Terminating session with ID:', transport.sessionId); + await transport.terminateSession(); + console.log('Session terminated successfully'); + // Check if sessionId was cleared after termination + if (!transport.sessionId) { + console.log('Session ID has been cleared'); + sessionId = undefined; + // Also close the transport and clear client objects + await transport.close(); + console.log('Transport closed after session termination'); + client = null; + transport = null; + } + else { + console.log('Server responded with 405 Method Not Allowed (session termination not supported)'); + console.log('Session ID is still active:', transport.sessionId); + } + } + catch (error) { + console.error('Error terminating session:', error); + } +} +async function reconnect() { + if (client) { + await disconnect(); + } + await connect(); +} +async function listTools() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - id: ${tool.name}, name: ${getDisplayName(tool)}, description: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server (${error})`); + } +} +async function callTool(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'tools/call', + params: { + name, + arguments: args + } + }; + console.log(`Calling tool '${name}' with args:`, args); + const result = await client.request(request, CallToolResultSchema); + console.log('Tool result:'); + const resourceLinks = []; + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else if (item.type === 'resource_link') { + const resourceLink = item; + resourceLinks.push(resourceLink); + console.log(` 📁 Resource Link: ${resourceLink.name}`); + console.log(` URI: ${resourceLink.uri}`); + if (resourceLink.mimeType) { + console.log(` Type: ${resourceLink.mimeType}`); + } + if (resourceLink.description) { + console.log(` Description: ${resourceLink.description}`); + } + } + else if (item.type === 'resource') { + console.log(` [Embedded Resource: ${item.resource.uri}]`); + } + else if (item.type === 'image') { + console.log(` [Image: ${item.mimeType}]`); + } + else if (item.type === 'audio') { + console.log(` [Audio: ${item.mimeType}]`); + } + else { + console.log(` [Unknown content type]:`, item); + } + }); + // Offer to read resource links + if (resourceLinks.length > 0) { + console.log(`\nFound ${resourceLinks.length} resource link(s). Use 'read-resource ' to read their content.`); + } + } + catch (error) { + console.log(`Error calling tool ${name}: ${error}`); + } +} +async function callGreetTool(name) { + await callTool('greet', { name }); +} +async function callMultiGreetTool(name) { + console.log('Calling multi-greet tool with notifications...'); + await callTool('multi-greet', { name }); +} +async function callCollectInfoTool(infoType) { + console.log(`Testing form elicitation with collect-user-info tool (${infoType})...`); + await callTool('collect-user-info', { infoType }); +} +async function startNotifications(interval, count) { + console.log(`Starting notification stream: interval=${interval}ms, count=${count || 'unlimited'}`); + await callTool('start-notification-stream', { interval, count }); +} +async function runNotificationsToolWithResumability(interval, count) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + console.log(`Starting notification stream with resumability: interval=${interval}ms, count=${count || 'unlimited'}`); + console.log(`Using resumption token: ${notificationsToolLastEventId || 'none'}`); + const request = { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { interval, count } + } + }; + const onLastEventIdUpdate = (event) => { + notificationsToolLastEventId = event; + console.log(`Updated resumption token: ${event}`); + }; + const result = await client.request(request, CallToolResultSchema, { + resumptionToken: notificationsToolLastEventId, + onresumptiontoken: onLastEventIdUpdate + }); + console.log('Tool result:'); + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + catch (error) { + console.log(`Error starting notification stream: ${error}`); + } +} +async function listPrompts() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const promptsRequest = { + method: 'prompts/list', + params: {} + }; + const promptsResult = await client.request(promptsRequest, ListPromptsResultSchema); + console.log('Available prompts:'); + if (promptsResult.prompts.length === 0) { + console.log(' No prompts available'); + } + else { + for (const prompt of promptsResult.prompts) { + console.log(` - id: ${prompt.name}, name: ${getDisplayName(prompt)}, description: ${prompt.description}`); + } + } + } + catch (error) { + console.log(`Prompts not supported by this server (${error})`); + } +} +async function getPrompt(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const promptRequest = { + method: 'prompts/get', + params: { + name, + arguments: args + } + }; + const promptResult = await client.request(promptRequest, GetPromptResultSchema); + console.log('Prompt template:'); + promptResult.messages.forEach((msg, index) => { + console.log(` [${index + 1}] ${msg.role}: ${msg.content.type === 'text' ? msg.content.text : JSON.stringify(msg.content)}`); + }); + } + catch (error) { + console.log(`Error getting prompt ${name}: ${error}`); + } +} +async function listResources() { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const resourcesRequest = { + method: 'resources/list', + params: {} + }; + const resourcesResult = await client.request(resourcesRequest, ListResourcesResultSchema); + console.log('Available resources:'); + if (resourcesResult.resources.length === 0) { + console.log(' No resources available'); + } + else { + for (const resource of resourcesResult.resources) { + console.log(` - id: ${resource.name}, name: ${getDisplayName(resource)}, description: ${resource.uri}`); + } + } + } + catch (error) { + console.log(`Resources not supported by this server (${error})`); + } +} +async function readResource(uri) { + if (!client) { + console.log('Not connected to server.'); + return; + } + try { + const request = { + method: 'resources/read', + params: { uri } + }; + console.log(`Reading resource: ${uri}`); + const result = await client.request(request, ReadResourceResultSchema); + console.log('Resource contents:'); + for (const content of result.contents) { + console.log(` URI: ${content.uri}`); + if (content.mimeType) { + console.log(` Type: ${content.mimeType}`); + } + if ('text' in content && typeof content.text === 'string') { + console.log(' Content:'); + console.log(' ---'); + console.log(content.text + .split('\n') + .map((line) => ' ' + line) + .join('\n')); + console.log(' ---'); + } + else if ('blob' in content && typeof content.blob === 'string') { + console.log(` [Binary data: ${content.blob.length} bytes]`); + } + } + } + catch (error) { + console.log(`Error reading resource ${uri}: ${error}`); + } +} +async function callToolTask(name, args) { + if (!client) { + console.log('Not connected to server.'); + return; + } + console.log(`Calling tool '${name}' with task-based execution...`); + console.log('Arguments:', args); + // Use task-based execution - call now, fetch later + // Using the experimental tasks API - WARNING: may change without notice + console.log('This will return immediately while processing continues in the background...'); + try { + // Call the tool with task metadata using streaming API + const stream = client.experimental.tasks.callToolStream({ + name, + arguments: args + }, CallToolResultSchema, { + task: { + ttl: 60000 // Keep results for 60 seconds + } + }); + console.log('Waiting for task completion...'); + let lastStatus = ''; + for await (const message of stream) { + switch (message.type) { + case 'taskCreated': + console.log('Task created successfully with ID:', message.task.taskId); + break; + case 'taskStatus': + if (lastStatus !== message.task.status) { + console.log(` ${message.task.status}${message.task.statusMessage ? ` - ${message.task.statusMessage}` : ''}`); + } + lastStatus = message.task.status; + break; + case 'result': + console.log('Task completed!'); + console.log('Tool result:'); + message.result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + }); + break; + case 'error': + throw message.error; + } + } + } + catch (error) { + console.log(`Error with task-based execution: ${error}`); + } +} +async function cleanup() { + if (client && transport) { + try { + // First try to terminate the session gracefully + if (transport.sessionId) { + try { + console.log('Terminating session before exit...'); + await transport.terminateSession(); + console.log('Session terminated successfully'); + } + catch (error) { + console.error('Error terminating session:', error); + } + } + // Then close the transport + await transport.close(); + } + catch (error) { + console.error('Error closing transport:', error); + } + } + process.stdin.setRawMode(false); + readline.close(); + console.log('\nGoodbye!'); + process.exit(0); +} +// Set up raw mode for keyboard input to capture Escape key +process.stdin.setRawMode(true); +process.stdin.on('data', async (data) => { + // Check for Escape key (27) + if (data.length === 1 && data[0] === 27) { + console.log('\nESC key pressed. Disconnecting from server...'); + // Abort current operation and disconnect from server + if (client && transport) { + await disconnect(); + console.log('Disconnected. Press Enter to continue.'); + } + else { + console.log('Not connected to server.'); + } + // Re-display the prompt + process.stdout.write('> '); + } +}); +// Handle Ctrl+C +process.on('SIGINT', async () => { + console.log('\nReceived SIGINT. Cleaning up...'); + await cleanup(); +}); +// Start the interactive client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleStreamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleStreamableHttp.js.map b/dist/esm/examples/client/simpleStreamableHttp.js.map new file mode 100644 index 000000000..24df4b107 --- /dev/null +++ b/dist/esm/examples/client/simpleStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleStreamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAEH,qBAAqB,EAErB,oBAAoB,EAEpB,uBAAuB,EAEvB,qBAAqB,EAErB,yBAAyB,EACzB,gCAAgC,EAChC,qCAAqC,EACrC,mBAAmB,EAGnB,wBAAwB,EACxB,qBAAqB,EACrB,SAAS,EACT,QAAQ,EACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,2CAA2C;AAC3C,MAAM,QAAQ,GAAG,eAAe,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAA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CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC5C,CAAC;QAED,wBAAwB;QACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,gBAAgB;AAChB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,MAAM,OAAO,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,+BAA+B;AAC/B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts b/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts new file mode 100644 index 000000000..c79406602 --- /dev/null +++ b/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts @@ -0,0 +1,10 @@ +/** + * Simple interactive task client demonstrating elicitation and sampling responses. + * + * This client connects to simpleTaskInteractive.ts server and demonstrates: + * - Handling elicitation requests (y/n confirmation) + * - Handling sampling requests (returns a hardcoded haiku) + * - Using task-based tool execution with streaming + */ +export {}; +//# sourceMappingURL=simpleTaskInteractiveClient.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts.map b/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts.map new file mode 100644 index 000000000..89b73386e --- /dev/null +++ b/dist/esm/examples/client/simpleTaskInteractiveClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractiveClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/simpleTaskInteractiveClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"} \ No newline at end of file diff --git a/dist/esm/examples/client/simpleTaskInteractiveClient.js b/dist/esm/examples/client/simpleTaskInteractiveClient.js new file mode 100644 index 000000000..c1072a597 --- /dev/null +++ b/dist/esm/examples/client/simpleTaskInteractiveClient.js @@ -0,0 +1,156 @@ +/** + * Simple interactive task client demonstrating elicitation and sampling responses. + * + * This client connects to simpleTaskInteractive.ts server and demonstrates: + * - Handling elicitation requests (y/n confirmation) + * - Handling sampling requests (returns a hardcoded haiku) + * - Using task-based tool execution with streaming + */ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { createInterface } from 'node:readline'; +import { CallToolResultSchema, ElicitRequestSchema, CreateMessageRequestSchema, ErrorCode, McpError } from '../../types.js'; +// Create readline interface for user input +const readline = createInterface({ + input: process.stdin, + output: process.stdout +}); +function question(prompt) { + return new Promise(resolve => { + readline.question(prompt, answer => { + resolve(answer.trim()); + }); + }); +} +function getTextContent(result) { + var _a; + const textContent = result.content.find((c) => c.type === 'text'); + return (_a = textContent === null || textContent === void 0 ? void 0 : textContent.text) !== null && _a !== void 0 ? _a : '(no text)'; +} +async function elicitationCallback(params) { + console.log(`\n[Elicitation] Server asks: ${params.message}`); + // Simple terminal prompt for y/n + const response = await question('Your response (y/n): '); + const confirmed = ['y', 'yes', 'true', '1'].includes(response.toLowerCase()); + console.log(`[Elicitation] Responding with: confirm=${confirmed}`); + return { action: 'accept', content: { confirm: confirmed } }; +} +async function samplingCallback(params) { + // Get the prompt from the first message + let prompt = 'unknown'; + if (params.messages && params.messages.length > 0) { + const firstMessage = params.messages[0]; + const content = firstMessage.content; + if (typeof content === 'object' && !Array.isArray(content) && content.type === 'text' && 'text' in content) { + prompt = content.text; + } + else if (Array.isArray(content)) { + const textPart = content.find(c => c.type === 'text' && 'text' in c); + if (textPart && 'text' in textPart) { + prompt = textPart.text; + } + } + } + console.log(`\n[Sampling] Server requests LLM completion for: ${prompt}`); + // Return a hardcoded haiku (in real use, call your LLM here) + const haiku = `Cherry blossoms fall +Softly on the quiet pond +Spring whispers goodbye`; + console.log('[Sampling] Responding with haiku'); + return { + model: 'mock-haiku-model', + role: 'assistant', + content: { type: 'text', text: haiku } + }; +} +async function run(url) { + console.log('Simple Task Interactive Client'); + console.log('=============================='); + console.log(`Connecting to ${url}...`); + // Create client with elicitation and sampling capabilities + const client = new Client({ name: 'simple-task-interactive-client', version: '1.0.0' }, { + capabilities: { + elicitation: { form: {} }, + sampling: {} + } + }); + // Set up elicitation request handler + client.setRequestHandler(ElicitRequestSchema, async (request) => { + if (request.params.mode && request.params.mode !== 'form') { + throw new McpError(ErrorCode.InvalidParams, `Unsupported elicitation mode: ${request.params.mode}`); + } + return elicitationCallback(request.params); + }); + // Set up sampling request handler + client.setRequestHandler(CreateMessageRequestSchema, async (request) => { + return samplingCallback(request.params); + }); + // Connect to server + const transport = new StreamableHTTPClientTransport(new URL(url)); + await client.connect(transport); + console.log('Connected!\n'); + // List tools + const toolsResult = await client.listTools(); + console.log(`Available tools: ${toolsResult.tools.map(t => t.name).join(', ')}`); + // Demo 1: Elicitation (confirm_delete) + console.log('\n--- Demo 1: Elicitation ---'); + console.log('Calling confirm_delete tool...'); + const confirmStream = client.experimental.tasks.callToolStream({ name: 'confirm_delete', arguments: { filename: 'important.txt' } }, CallToolResultSchema, { task: { ttl: 60000 } }); + for await (const message of confirmStream) { + switch (message.type) { + case 'taskCreated': + console.log(`Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`Task status: ${message.task.status}`); + break; + case 'result': + console.log(`Result: ${getTextContent(message.result)}`); + break; + case 'error': + console.error(`Error: ${message.error}`); + break; + } + } + // Demo 2: Sampling (write_haiku) + console.log('\n--- Demo 2: Sampling ---'); + console.log('Calling write_haiku tool...'); + const haikuStream = client.experimental.tasks.callToolStream({ name: 'write_haiku', arguments: { topic: 'autumn leaves' } }, CallToolResultSchema, { + task: { ttl: 60000 } + }); + for await (const message of haikuStream) { + switch (message.type) { + case 'taskCreated': + console.log(`Task created: ${message.task.taskId}`); + break; + case 'taskStatus': + console.log(`Task status: ${message.task.status}`); + break; + case 'result': + console.log(`Result:\n${getTextContent(message.result)}`); + break; + case 'error': + console.error(`Error: ${message.error}`); + break; + } + } + // Cleanup + console.log('\nDemo complete. Closing connection...'); + await transport.close(); + readline.close(); +} +// Parse command line arguments +const args = process.argv.slice(2); +let url = 'http://localhost:8000/mcp'; +for (let i = 0; i < args.length; i++) { + if (args[i] === '--url' && args[i + 1]) { + url = args[i + 1]; + i++; + } +} +// Run the client +run(url).catch(error => { + console.error('Error running client:', error); + process.exit(1); +}); +//# sourceMappingURL=simpleTaskInteractiveClient.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/simpleTaskInteractiveClient.js.map b/dist/esm/examples/client/simpleTaskInteractiveClient.js.map new file mode 100644 index 000000000..05d1ae37b --- /dev/null +++ b/dist/esm/examples/client/simpleTaskInteractiveClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractiveClient.js","sourceRoot":"","sources":["../../../../src/examples/client/simpleTaskInteractiveClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACH,oBAAoB,EAEpB,mBAAmB,EACnB,0BAA0B,EAG1B,SAAS,EACT,QAAQ,EACX,MAAM,gBAAgB,CAAC;AAExB,2CAA2C;AAC3C,MAAM,QAAQ,GAAG,eAAe,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACzB,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,MAAc;IAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACzB,QAAQ,CAAC,QAA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C;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/ssePollingClient.d.ts b/dist/esm/examples/client/ssePollingClient.d.ts new file mode 100644 index 000000000..134b4b0cf --- /dev/null +++ b/dist/esm/examples/client/ssePollingClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=ssePollingClient.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/ssePollingClient.d.ts.map b/dist/esm/examples/client/ssePollingClient.d.ts.map new file mode 100644 index 000000000..59e4153d2 --- /dev/null +++ b/dist/esm/examples/client/ssePollingClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/ssePollingClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/ssePollingClient.js b/dist/esm/examples/client/ssePollingClient.js new file mode 100644 index 000000000..6bd93a932 --- /dev/null +++ b/dist/esm/examples/client/ssePollingClient.js @@ -0,0 +1,93 @@ +/** + * SSE Polling Example Client (SEP-1699) + * + * This example demonstrates client-side behavior during server-initiated + * SSE stream disconnection and automatic reconnection. + * + * Key features demonstrated: + * - Automatic reconnection when server closes SSE stream + * - Event replay via Last-Event-ID header + * - Resumption token tracking via onresumptiontoken callback + * + * Run with: npx tsx src/examples/client/ssePollingClient.ts + * Requires: ssePollingExample.ts server running on port 3001 + */ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { CallToolResultSchema, LoggingMessageNotificationSchema } from '../../types.js'; +const SERVER_URL = 'http://localhost:3001/mcp'; +async function main() { + console.log('SSE Polling Example Client'); + console.log('=========================='); + console.log(`Connecting to ${SERVER_URL}...`); + console.log(''); + // Create transport with reconnection options + const transport = new StreamableHTTPClientTransport(new URL(SERVER_URL), { + // Use default reconnection options - SDK handles automatic reconnection + }); + // Track the last event ID for debugging + let lastEventId; + // Set up transport error handler to observe disconnections + // Filter out expected errors from SSE reconnection + transport.onerror = error => { + // Skip abort errors during intentional close + if (error.message.includes('AbortError')) + return; + // Show SSE disconnect (expected when server closes stream) + if (error.message.includes('Unexpected end of JSON')) { + console.log('[Transport] SSE stream disconnected - client will auto-reconnect'); + return; + } + console.log(`[Transport] Error: ${error.message}`); + }; + // Set up transport close handler + transport.onclose = () => { + console.log('[Transport] Connection closed'); + }; + // Create and connect client + const client = new Client({ + name: 'sse-polling-client', + version: '1.0.0' + }); + // Set up notification handler to receive progress updates + client.setNotificationHandler(LoggingMessageNotificationSchema, notification => { + const data = notification.params.data; + console.log(`[Notification] ${data}`); + }); + try { + await client.connect(transport); + console.log('[Client] Connected successfully'); + console.log(''); + // Call the long-task tool + console.log('[Client] Calling long-task tool...'); + console.log('[Client] Server will disconnect mid-task to demonstrate polling'); + console.log(''); + const result = await client.request({ + method: 'tools/call', + params: { + name: 'long-task', + arguments: {} + } + }, CallToolResultSchema, { + // Track resumption tokens for debugging + onresumptiontoken: token => { + lastEventId = token; + console.log(`[Event ID] ${token}`); + } + }); + console.log(''); + console.log('[Client] Tool completed!'); + console.log(`[Result] ${JSON.stringify(result.content, null, 2)}`); + console.log(''); + console.log(`[Debug] Final event ID: ${lastEventId}`); + } + catch (error) { + console.error('[Error]', error); + } + finally { + await transport.close(); + console.log('[Client] Disconnected'); + } +} +main().catch(console.error); +//# sourceMappingURL=ssePollingClient.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/ssePollingClient.js.map b/dist/esm/examples/client/ssePollingClient.js.map new file mode 100644 index 000000000..c41b4332a --- /dev/null +++ b/dist/esm/examples/client/ssePollingClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingClient.js","sourceRoot":"","sources":["../../../../src/examples/client/ssePollingClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAA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,WAAW,EAAE,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;YAAS,CAAC;QACP,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACzC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts new file mode 100644 index 000000000..c2679e669 --- /dev/null +++ b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=streamableHttpWithSseFallbackClient.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts.map b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts.map new file mode 100644 index 000000000..b79ae2a72 --- /dev/null +++ b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttpWithSseFallbackClient.d.ts","sourceRoot":"","sources":["../../../../src/examples/client/streamableHttpWithSseFallbackClient.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js new file mode 100644 index 000000000..1bea76828 --- /dev/null +++ b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js @@ -0,0 +1,166 @@ +import { Client } from '../../client/index.js'; +import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js'; +import { SSEClientTransport } from '../../client/sse.js'; +import { ListToolsResultSchema, CallToolResultSchema, LoggingMessageNotificationSchema } from '../../types.js'; +/** + * Simplified Backwards Compatible MCP Client + * + * This client demonstrates backward compatibility with both: + * 1. Modern servers using Streamable HTTP transport (protocol version 2025-03-26) + * 2. Older servers using HTTP+SSE transport (protocol version 2024-11-05) + * + * Following the MCP specification for backwards compatibility: + * - Attempts to POST an initialize request to the server URL first (modern transport) + * - If that fails with 4xx status, falls back to GET request for SSE stream (older transport) + */ +// Command line args processing +const args = process.argv.slice(2); +const serverUrl = args[0] || 'http://localhost:3000/mcp'; +async function main() { + console.log('MCP Backwards Compatible Client'); + console.log('==============================='); + console.log(`Connecting to server at: ${serverUrl}`); + let client; + let transport; + try { + // Try connecting with automatic transport detection + const connection = await connectWithBackwardsCompatibility(serverUrl); + client = connection.client; + transport = connection.transport; + // Set up notification handler + client.setNotificationHandler(LoggingMessageNotificationSchema, notification => { + console.log(`Notification: ${notification.params.level} - ${notification.params.data}`); + }); + // DEMO WORKFLOW: + // 1. List available tools + console.log('\n=== Listing Available Tools ==='); + await listTools(client); + // 2. Call the notification tool + console.log('\n=== Starting Notification Stream ==='); + await startNotificationTool(client); + // 3. Wait for all notifications (5 seconds) + console.log('\n=== Waiting for all notifications ==='); + await new Promise(resolve => setTimeout(resolve, 5000)); + // 4. Disconnect + console.log('\n=== Disconnecting ==='); + await transport.close(); + console.log('Disconnected from MCP server'); + } + catch (error) { + console.error('Error running client:', error); + process.exit(1); + } +} +/** + * Connect to an MCP server with backwards compatibility + * Following the spec for client backward compatibility + */ +async function connectWithBackwardsCompatibility(url) { + console.log('1. Trying Streamable HTTP transport first...'); + // Step 1: Try Streamable HTTP transport first + const client = new Client({ + name: 'backwards-compatible-client', + version: '1.0.0' + }); + client.onerror = error => { + console.error('Client error:', error); + }; + const baseUrl = new URL(url); + try { + // Create modern transport + const streamableTransport = new StreamableHTTPClientTransport(baseUrl); + await client.connect(streamableTransport); + console.log('Successfully connected using modern Streamable HTTP transport.'); + return { + client, + transport: streamableTransport, + transportType: 'streamable-http' + }; + } + catch (error) { + // Step 2: If transport fails, try the older SSE transport + console.log(`StreamableHttp transport connection failed: ${error}`); + console.log('2. Falling back to deprecated HTTP+SSE transport...'); + try { + // Create SSE transport pointing to /sse endpoint + const sseTransport = new SSEClientTransport(baseUrl); + const sseClient = new Client({ + name: 'backwards-compatible-client', + version: '1.0.0' + }); + await sseClient.connect(sseTransport); + console.log('Successfully connected using deprecated HTTP+SSE transport.'); + return { + client: sseClient, + transport: sseTransport, + transportType: 'sse' + }; + } + catch (sseError) { + console.error(`Failed to connect with either transport method:\n1. Streamable HTTP error: ${error}\n2. SSE error: ${sseError}`); + throw new Error('Could not connect to server with any available transport'); + } + } +} +/** + * List available tools on the server + */ +async function listTools(client) { + try { + const toolsRequest = { + method: 'tools/list', + params: {} + }; + const toolsResult = await client.request(toolsRequest, ListToolsResultSchema); + console.log('Available tools:'); + if (toolsResult.tools.length === 0) { + console.log(' No tools available'); + } + else { + for (const tool of toolsResult.tools) { + console.log(` - ${tool.name}: ${tool.description}`); + } + } + } + catch (error) { + console.log(`Tools not supported by this server: ${error}`); + } +} +/** + * Start a notification stream by calling the notification tool + */ +async function startNotificationTool(client) { + try { + // Call the notification tool using reasonable defaults + const request = { + method: 'tools/call', + params: { + name: 'start-notification-stream', + arguments: { + interval: 1000, // 1 second between notifications + count: 5 // Send 5 notifications + } + } + }; + console.log('Calling notification tool...'); + const result = await client.request(request, CallToolResultSchema); + console.log('Tool result:'); + result.content.forEach(item => { + if (item.type === 'text') { + console.log(` ${item.text}`); + } + else { + console.log(` ${item.type} content:`, item); + } + }); + } + catch (error) { + console.log(`Error calling notification tool: ${error}`); + } +} +// Start the client +main().catch((error) => { + console.error('Error running MCP client:', error); + process.exit(1); +}); +//# sourceMappingURL=streamableHttpWithSseFallbackClient.js.map \ No newline at end of file diff --git a/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js.map b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js.map new file mode 100644 index 000000000..0d9399dc9 --- /dev/null +++ b/dist/esm/examples/client/streamableHttpWithSseFallbackClient.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttpWithSseFallbackClient.js","sourceRoot":"","sources":["../../../../src/examples/client/streamableHttpWithSseFallbackClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAEH,qBAAqB,EAErB,oBAAoB,EACpB,gCAAgC,EACnC,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;GAUG;AAEH,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,2BAA2B,CAAC;AAEzD,KAAK,UAAU,IAAI;IACf,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,EAAE,CAAC,CAAC;IAErD,IAAI,MAAc,CAAC;IACnB,IAAI,SAA6D,CAAC;IAElE,IAAI,CAAC;QACD,oDAAoD;QACpD,MAAM,UAAU,GAAG,MAAM,iCAAiC,CAAC,SAAS,CAAC,CAAC;QACtE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAC3B,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QAEjC,8BAA8B;QAC9B,MAAM,CAAC,sBAAsB,CAAC,gCAAgC,EAAE,YAAY,CAAC,EAAE;YAC3E,OAAO,CAAC,GAAG,CAAC,iBAAiB,YAAY,CAAC,MAAM,CAAC,KAAK,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5F,CAAC,CAAC,CAAC;QAEH,iBAAiB;QACjB,0BAA0B;QAC1B,OAAO,CAA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,CAAC,CAAC;YACjD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,oCAAoC,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;AACL,CAAC;AAED,mBAAmB;AACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts b/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts new file mode 100644 index 000000000..218aeac8b --- /dev/null +++ b/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts @@ -0,0 +1,78 @@ +import { AuthorizationParams, OAuthServerProvider } from '../../server/auth/provider.js'; +import { OAuthRegisteredClientsStore } from '../../server/auth/clients.js'; +import { OAuthClientInformationFull, OAuthMetadata, OAuthTokens } from '../../shared/auth.js'; +import { Response } from 'express'; +import { AuthInfo } from '../../server/auth/types.js'; +export declare class DemoInMemoryClientsStore implements OAuthRegisteredClientsStore { + private clients; + getClient(clientId: string): Promise<{ + redirect_uris: string[]; + client_id: string; + token_endpoint_auth_method?: string | undefined; + grant_types?: string[] | undefined; + response_types?: string[] | undefined; + client_name?: string | undefined; + client_uri?: string | undefined; + logo_uri?: string | undefined; + scope?: string | undefined; + contacts?: string[] | undefined; + tos_uri?: string | undefined; + policy_uri?: string | undefined; + jwks_uri?: string | undefined; + jwks?: any; + software_id?: string | undefined; + software_version?: string | undefined; + software_statement?: string | undefined; + client_secret?: string | undefined; + client_id_issued_at?: number | undefined; + client_secret_expires_at?: number | undefined; + } | undefined>; + registerClient(clientMetadata: OAuthClientInformationFull): Promise<{ + redirect_uris: string[]; + client_id: string; + token_endpoint_auth_method?: string | undefined; + grant_types?: string[] | undefined; + response_types?: string[] | undefined; + client_name?: string | undefined; + client_uri?: string | undefined; + logo_uri?: string | undefined; + scope?: string | undefined; + contacts?: string[] | undefined; + tos_uri?: string | undefined; + policy_uri?: string | undefined; + jwks_uri?: string | undefined; + jwks?: any; + software_id?: string | undefined; + software_version?: string | undefined; + software_statement?: string | undefined; + client_secret?: string | undefined; + client_id_issued_at?: number | undefined; + client_secret_expires_at?: number | undefined; + }>; +} +/** + * 🚨 DEMO ONLY - NOT FOR PRODUCTION + * + * This example demonstrates MCP OAuth flow but lacks some of the features required for production use, + * for example: + * - Persistent token storage + * - Rate limiting + */ +export declare class DemoInMemoryAuthProvider implements OAuthServerProvider { + private validateResource?; + clientsStore: DemoInMemoryClientsStore; + private codes; + private tokens; + constructor(validateResource?: ((resource?: URL) => boolean) | undefined); + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise; + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, _codeVerifier?: string): Promise; + exchangeRefreshToken(_client: OAuthClientInformationFull, _refreshToken: string, _scopes?: string[], _resource?: URL): Promise; + verifyAccessToken(token: string): Promise; +} +export declare const setupAuthServer: ({ authServerUrl, mcpServerUrl, strictResource }: { + authServerUrl: URL; + mcpServerUrl: URL; + strictResource: boolean; +}) => OAuthMetadata; +//# sourceMappingURL=demoInMemoryOAuthProvider.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts.map b/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts.map new file mode 100644 index 000000000..8a4a43fe8 --- /dev/null +++ b/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"demoInMemoryOAuthProvider.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/demoInMemoryOAuthProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mB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,CAAC,WAAW,CAAC;IAIjB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAc5D;AAED,eAAO,MAAM,eAAe,oDAIzB;IACC,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;CAC3B,KAAG,aA+EH,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/demoInMemoryOAuthProvider.js b/dist/esm/examples/server/demoInMemoryOAuthProvider.js new file mode 100644 index 000000000..45bde7043 --- /dev/null +++ b/dist/esm/examples/server/demoInMemoryOAuthProvider.js @@ -0,0 +1,196 @@ +import { randomUUID } from 'node:crypto'; +import express from 'express'; +import { createOAuthMetadata, mcpAuthRouter } from '../../server/auth/router.js'; +import { resourceUrlFromServerUrl } from '../../shared/auth-utils.js'; +import { InvalidRequestError } from '../../server/auth/errors.js'; +export class DemoInMemoryClientsStore { + constructor() { + this.clients = new Map(); + } + async getClient(clientId) { + return this.clients.get(clientId); + } + async registerClient(clientMetadata) { + this.clients.set(clientMetadata.client_id, clientMetadata); + return clientMetadata; + } +} +/** + * 🚨 DEMO ONLY - NOT FOR PRODUCTION + * + * This example demonstrates MCP OAuth flow but lacks some of the features required for production use, + * for example: + * - Persistent token storage + * - Rate limiting + */ +export class DemoInMemoryAuthProvider { + constructor(validateResource) { + this.validateResource = validateResource; + this.clientsStore = new DemoInMemoryClientsStore(); + this.codes = new Map(); + this.tokens = new Map(); + } + async authorize(client, params, res) { + const code = randomUUID(); + const searchParams = new URLSearchParams({ + code + }); + if (params.state !== undefined) { + searchParams.set('state', params.state); + } + this.codes.set(code, { + client, + params + }); + // Simulate a user login + // Set a secure HTTP-only session cookie with authorization info + if (res.cookie) { + const authCookieData = { + userId: 'demo_user', + name: 'Demo User', + timestamp: Date.now() + }; + res.cookie('demo_session', JSON.stringify(authCookieData), { + httpOnly: true, + secure: false, // In production, this should be true + sameSite: 'lax', + maxAge: 24 * 60 * 60 * 1000, // 24 hours - for demo purposes + path: '/' // Available to all routes + }); + } + if (!client.redirect_uris.includes(params.redirectUri)) { + throw new InvalidRequestError('Unregistered redirect_uri'); + } + const targetUrl = new URL(params.redirectUri); + targetUrl.search = searchParams.toString(); + res.redirect(targetUrl.toString()); + } + async challengeForAuthorizationCode(client, authorizationCode) { + // Store the challenge with the code data + const codeData = this.codes.get(authorizationCode); + if (!codeData) { + throw new Error('Invalid authorization code'); + } + return codeData.params.codeChallenge; + } + async exchangeAuthorizationCode(client, authorizationCode, + // Note: code verifier is checked in token.ts by default + // it's unused here for that reason. + _codeVerifier) { + const codeData = this.codes.get(authorizationCode); + if (!codeData) { + throw new Error('Invalid authorization code'); + } + if (codeData.client.client_id !== client.client_id) { + throw new Error(`Authorization code was not issued to this client, ${codeData.client.client_id} != ${client.client_id}`); + } + if (this.validateResource && !this.validateResource(codeData.params.resource)) { + throw new Error(`Invalid resource: ${codeData.params.resource}`); + } + this.codes.delete(authorizationCode); + const token = randomUUID(); + const tokenData = { + token, + clientId: client.client_id, + scopes: codeData.params.scopes || [], + expiresAt: Date.now() + 3600000, // 1 hour + resource: codeData.params.resource, + type: 'access' + }; + this.tokens.set(token, tokenData); + return { + access_token: token, + token_type: 'bearer', + expires_in: 3600, + scope: (codeData.params.scopes || []).join(' ') + }; + } + async exchangeRefreshToken(_client, _refreshToken, _scopes, _resource) { + throw new Error('Not implemented for example demo'); + } + async verifyAccessToken(token) { + const tokenData = this.tokens.get(token); + if (!tokenData || !tokenData.expiresAt || tokenData.expiresAt < Date.now()) { + throw new Error('Invalid or expired token'); + } + return { + token, + clientId: tokenData.clientId, + scopes: tokenData.scopes, + expiresAt: Math.floor(tokenData.expiresAt / 1000), + resource: tokenData.resource + }; + } +} +export const setupAuthServer = ({ authServerUrl, mcpServerUrl, strictResource }) => { + // Create separate auth server app + // NOTE: This is a separate app on a separate port to illustrate + // how to separate an OAuth Authorization Server from a Resource + // server in the SDK. The SDK is not intended to be provide a standalone + // authorization server. + const validateResource = strictResource + ? (resource) => { + if (!resource) + return false; + const expectedResource = resourceUrlFromServerUrl(mcpServerUrl); + return resource.toString() === expectedResource.toString(); + } + : undefined; + const provider = new DemoInMemoryAuthProvider(validateResource); + const authApp = express(); + authApp.use(express.json()); + // For introspection requests + authApp.use(express.urlencoded()); + // Add OAuth routes to the auth server + // NOTE: this will also add a protected resource metadata route, + // but it won't be used, so leave it. + authApp.use(mcpAuthRouter({ + provider, + issuerUrl: authServerUrl, + scopesSupported: ['mcp:tools'] + })); + authApp.post('/introspect', async (req, res) => { + try { + const { token } = req.body; + if (!token) { + res.status(400).json({ error: 'Token is required' }); + return; + } + const tokenInfo = await provider.verifyAccessToken(token); + res.json({ + active: true, + client_id: tokenInfo.clientId, + scope: tokenInfo.scopes.join(' '), + exp: tokenInfo.expiresAt, + aud: tokenInfo.resource + }); + return; + } + catch (error) { + res.status(401).json({ + active: false, + error: 'Unauthorized', + error_description: `Invalid token: ${error}` + }); + } + }); + const auth_port = authServerUrl.port; + // Start the auth server + authApp.listen(auth_port, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`OAuth Authorization Server listening on port ${auth_port}`); + }); + // Note: we could fetch this from the server, but then we end up + // with some top level async which gets annoying. + const oauthMetadata = createOAuthMetadata({ + provider, + issuerUrl: authServerUrl, + scopesSupported: ['mcp:tools'] + }); + oauthMetadata.introspection_endpoint = new URL('/introspect', authServerUrl).href; + return oauthMetadata; +}; +//# sourceMappingURL=demoInMemoryOAuthProvider.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/demoInMemoryOAuthProvider.js.map b/dist/esm/examples/server/demoInMemoryOAuthProvider.js.map new file mode 100644 index 000000000..80fcc5502 --- /dev/null +++ b/dist/esm/examples/server/demoInMemoryOAuthProvider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"demoInMemoryOAuthProvider.js","sourceRoot":"","sources":["../../../../src/examples/server/demoInMemoryOAuthProvider.ts"],"names":[],"mappings":"AAAA,O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AAE,CAAC;YACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,cAAc;gBACrB,iBAAiB,EAAE,kBAAkB,KAAK,EAAE;aAC/C,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC;IACrC,wBAAwB;IACxB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC9B,IAAI,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,gDAAgD,SAAS,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,gEAAgE;IAChE,iDAAiD;IACjD,MAAM,aAAa,GAAkB,mBAAmB,CAAC;QACrD,QAAQ;QACR,SAAS,EAAE,aAAa;QACxB,eAAe,EAAE,CAAC,WAAW,CAAC;KACjC,CAAC,CAAC;IAEH,aAAa,CAAC,sBAAsB,GAAG,IAAI,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC;IAElF,OAAO,aAAa,CAAC;AACzB,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationFormExample.d.ts b/dist/esm/examples/server/elicitationFormExample.d.ts new file mode 100644 index 000000000..e4b736e0f --- /dev/null +++ b/dist/esm/examples/server/elicitationFormExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationFormExample.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationFormExample.d.ts.map b/dist/esm/examples/server/elicitationFormExample.d.ts.map new file mode 100644 index 000000000..c569df428 --- /dev/null +++ b/dist/esm/examples/server/elicitationFormExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationFormExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/elicitationFormExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationFormExample.js b/dist/esm/examples/server/elicitationFormExample.js new file mode 100644 index 000000000..1a651166d --- /dev/null +++ b/dist/esm/examples/server/elicitationFormExample.js @@ -0,0 +1,436 @@ +// Run with: npx tsx src/examples/server/elicitationFormExample.ts +// +// This example demonstrates how to use form elicitation to collect structured user input +// with JSON Schema validation via a local HTTP server with SSE streaming. +// Form elicitation allows servers to request *non-sensitive* user input through the client +// with schema-based validation. +// Note: See also elicitationUrlExample.ts for an example of using URL elicitation +// to collect *sensitive* user input via a browser. +import { randomUUID } from 'node:crypto'; +import cors from 'cors'; +import express from 'express'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { isInitializeRequest } from '../../types.js'; +// Create MCP server - it will automatically use AjvJsonSchemaValidator with sensible defaults +// The validator supports format validation (email, date, etc.) if ajv-formats is installed +const mcpServer = new McpServer({ + name: 'form-elicitation-example-server', + version: '1.0.0' +}, { + capabilities: {} +}); +/** + * Example 1: Simple user registration tool + * Collects username, email, and password from the user + */ +mcpServer.registerTool('register_user', { + description: 'Register a new user account by collecting their information', + inputSchema: {} +}, async () => { + try { + // Request user information through form elicitation + const result = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Please provide your registration information:', + requestedSchema: { + type: 'object', + properties: { + username: { + type: 'string', + title: 'Username', + description: 'Your desired username (3-20 characters)', + minLength: 3, + maxLength: 20 + }, + email: { + type: 'string', + title: 'Email', + description: 'Your email address', + format: 'email' + }, + password: { + type: 'string', + title: 'Password', + description: 'Your password (min 8 characters)', + minLength: 8 + }, + newsletter: { + type: 'boolean', + title: 'Newsletter', + description: 'Subscribe to newsletter?', + default: false + } + }, + required: ['username', 'email', 'password'] + } + }); + // Handle the different possible actions + if (result.action === 'accept' && result.content) { + const { username, email, newsletter } = result.content; + return { + content: [ + { + type: 'text', + text: `Registration successful!\n\nUsername: ${username}\nEmail: ${email}\nNewsletter: ${newsletter ? 'Yes' : 'No'}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [ + { + type: 'text', + text: 'Registration cancelled by user.' + } + ] + }; + } + else { + return { + content: [ + { + type: 'text', + text: 'Registration was cancelled.' + } + ] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Registration failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +/** + * Example 2: Multi-step workflow with multiple form elicitation requests + * Demonstrates how to collect information in multiple steps + */ +mcpServer.registerTool('create_event', { + description: 'Create a calendar event by collecting event details', + inputSchema: {} +}, async () => { + try { + // Step 1: Collect basic event information + const basicInfo = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Step 1: Enter basic event information', + requestedSchema: { + type: 'object', + properties: { + title: { + type: 'string', + title: 'Event Title', + description: 'Name of the event', + minLength: 1 + }, + description: { + type: 'string', + title: 'Description', + description: 'Event description (optional)' + } + }, + required: ['title'] + } + }); + if (basicInfo.action !== 'accept' || !basicInfo.content) { + return { + content: [{ type: 'text', text: 'Event creation cancelled.' }] + }; + } + // Step 2: Collect date and time + const dateTime = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Step 2: Enter date and time', + requestedSchema: { + type: 'object', + properties: { + date: { + type: 'string', + title: 'Date', + description: 'Event date', + format: 'date' + }, + startTime: { + type: 'string', + title: 'Start Time', + description: 'Event start time (HH:MM)' + }, + duration: { + type: 'integer', + title: 'Duration', + description: 'Duration in minutes', + minimum: 15, + maximum: 480 + } + }, + required: ['date', 'startTime', 'duration'] + } + }); + if (dateTime.action !== 'accept' || !dateTime.content) { + return { + content: [{ type: 'text', text: 'Event creation cancelled.' }] + }; + } + // Combine all collected information + const event = { + ...basicInfo.content, + ...dateTime.content + }; + return { + content: [ + { + type: 'text', + text: `Event created successfully!\n\n${JSON.stringify(event, null, 2)}` + } + ] + }; + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Event creation failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +/** + * Example 3: Collecting address information + * Demonstrates validation with patterns and optional fields + */ +mcpServer.registerTool('update_shipping_address', { + description: 'Update shipping address with validation', + inputSchema: {} +}, async () => { + try { + const result = await mcpServer.server.elicitInput({ + mode: 'form', + message: 'Please provide your shipping address:', + requestedSchema: { + type: 'object', + properties: { + name: { + type: 'string', + title: 'Full Name', + description: 'Recipient name', + minLength: 1 + }, + street: { + type: 'string', + title: 'Street Address', + minLength: 1 + }, + city: { + type: 'string', + title: 'City', + minLength: 1 + }, + state: { + type: 'string', + title: 'State/Province', + minLength: 2, + maxLength: 2 + }, + zipCode: { + type: 'string', + title: 'ZIP/Postal Code', + description: '5-digit ZIP code' + }, + phone: { + type: 'string', + title: 'Phone Number (optional)', + description: 'Contact phone number' + } + }, + required: ['name', 'street', 'city', 'state', 'zipCode'] + } + }); + if (result.action === 'accept' && result.content) { + return { + content: [ + { + type: 'text', + text: `Address updated successfully!\n\n${JSON.stringify(result.content, null, 2)}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [{ type: 'text', text: 'Address update cancelled by user.' }] + }; + } + else { + return { + content: [{ type: 'text', text: 'Address update was cancelled.' }] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Address update failed: ${error instanceof Error ? error.message : String(error)}` + } + ], + isError: true + }; + } +}); +async function main() { + const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000; + const app = express(); + app.use(express.json()); + // Allow CORS for all domains, expose the Mcp-Session-Id header + app.use(cors({ + origin: '*', + exposedHeaders: ['Mcp-Session-Id'] + })); + // Map to store transports by session ID + const transports = {}; + // MCP POST endpoint + const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (sessionId) { + console.log(`Received MCP request for session: ${sessionId}`); + } + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport for this session + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + // New initialization request - create new transport + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + await mcpServer.connect(transport); + await transport.handleRequest(req, res, req.body); + return; + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } + }; + app.post('/mcp', mcpPostHandler); + // Handle GET requests for SSE streams + const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Establishing SSE stream for session ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + }; + app.get('/mcp', mcpGetHandler); + // Handle DELETE requests for session termination + const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } + }; + app.delete('/mcp', mcpDeleteHandler); + // Start listening + app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Form elicitation example server is running on http://localhost:${PORT}/mcp`); + console.log('Available tools:'); + console.log(' - register_user: Collect user registration information'); + console.log(' - create_event: Multi-step event creation'); + console.log(' - update_shipping_address: Collect and validate address'); + console.log('\nConnect your MCP client to this server using the HTTP transport.'); + }); + // Handle server shutdown + process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); + }); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=elicitationFormExample.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationFormExample.js.map b/dist/esm/examples/server/elicitationFormExample.js.map new file mode 100644 index 000000000..0a486154e --- /dev/null +++ b/dist/esm/examples/server/elicitationFormExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationFormExample.js","sourceRoot":"","sources":["../../../../src/examples/server/elicitationFormExample.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,yFAAyF;AACzF,0EAA0E;AAC1E,2FAA2F;AAC3F,gCAAgC;AAChC,kFAAkF;AAClF,mDAAmD;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAwC,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,8FAA8F;AAC9F,2FAA2F;AAC3F,MAAM,SAAS,GAAG,IAAI,SAAS,CAC3B;IACI,IAAI,EAAE,iCAAiC;IACvC,OAAO,E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AAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAEvC,6DAA6D;QAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,IAAI,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;gBAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;gBACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9E,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationUrlExample.d.ts b/dist/esm/examples/server/elicitationUrlExample.d.ts new file mode 100644 index 000000000..611f6eba2 --- /dev/null +++ b/dist/esm/examples/server/elicitationUrlExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=elicitationUrlExample.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationUrlExample.d.ts.map b/dist/esm/examples/server/elicitationUrlExample.d.ts.map new file mode 100644 index 000000000..04acd6664 --- /dev/null +++ b/dist/esm/examples/server/elicitationUrlExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/elicitationUrlExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationUrlExample.js b/dist/esm/examples/server/elicitationUrlExample.js new file mode 100644 index 000000000..cde127cc4 --- /dev/null +++ b/dist/esm/examples/server/elicitationUrlExample.js @@ -0,0 +1,651 @@ +// Run with: npx tsx src/examples/server/elicitationUrlExample.ts +// +// This example demonstrates how to use URL elicitation to securely collect +// *sensitive* user input in a remote (HTTP) server. +// URL elicitation allows servers to prompt the end-user to open a URL in their browser +// to collect sensitive information. +// Note: See also elicitationFormExample.ts for an example of using form (not URL) elicitation +// to collect *non-sensitive* user input with a structured schema. +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { z } from 'zod'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter } from '../../server/auth/router.js'; +import { requireBearerAuth } from '../../server/auth/middleware/bearerAuth.js'; +import { UrlElicitationRequiredError, isInitializeRequest } from '../../types.js'; +import { InMemoryEventStore } from '../shared/inMemoryEventStore.js'; +import { setupAuthServer } from './demoInMemoryOAuthProvider.js'; +import { checkResourceAllowed } from '../../shared/auth-utils.js'; +import cors from 'cors'; +// Create an MCP server with implementation details +const getServer = () => { + const mcpServer = new McpServer({ + name: 'url-elicitation-http-server', + version: '1.0.0' + }, { + capabilities: { logging: {} } + }); + mcpServer.registerTool('payment-confirm', { + description: 'A tool that confirms a payment directly with a user', + inputSchema: { + cartId: z.string().describe('The ID of the cart to confirm') + } + }, async ({ cartId }, extra) => { + /* + In a real world scenario, there would be some logic here to check if the user has the provided cartId. + For the purposes of this example, we'll throw an error (-> elicits the client to open a URL to confirm payment) + */ + const sessionId = extra.sessionId; + if (!sessionId) { + throw new Error('Expected a Session ID'); + } + // Create and track the elicitation + const elicitationId = generateTrackedElicitation(sessionId, elicitationId => mcpServer.server.createElicitationCompletionNotifier(elicitationId)); + throw new UrlElicitationRequiredError([ + { + mode: 'url', + message: 'This tool requires a payment confirmation. Open the link to confirm payment!', + url: `http://localhost:${MCP_PORT}/confirm-payment?session=${sessionId}&elicitation=${elicitationId}&cartId=${encodeURIComponent(cartId)}`, + elicitationId + } + ]); + }); + mcpServer.registerTool('third-party-auth', { + description: 'A demo tool that requires third-party OAuth credentials', + inputSchema: { + param1: z.string().describe('First parameter') + } + }, async (_, extra) => { + /* + In a real world scenario, there would be some logic here to check if we already have a valid access token for the user. + Auth info (with a subject or `sub` claim) can be typically be found in `extra.authInfo`. + If we do, we can just return the result of the tool call. + If we don't, we can throw an ElicitationRequiredError to request the user to authenticate. + For the purposes of this example, we'll throw an error (-> elicits the client to open a URL to authenticate). + */ + const sessionId = extra.sessionId; + if (!sessionId) { + throw new Error('Expected a Session ID'); + } + // Create and track the elicitation + const elicitationId = generateTrackedElicitation(sessionId, elicitationId => mcpServer.server.createElicitationCompletionNotifier(elicitationId)); + // Simulate OAuth callback and token exchange after 5 seconds + // In a real app, this would be called from your OAuth callback handler + setTimeout(() => { + console.log(`Simulating OAuth token received for elicitation ${elicitationId}`); + completeURLElicitation(elicitationId); + }, 5000); + throw new UrlElicitationRequiredError([ + { + mode: 'url', + message: 'This tool requires access to your example.com account. Open the link to authenticate!', + url: 'https://www.example.com/oauth/authorize', + elicitationId + } + ]); + }); + return mcpServer; +}; +const elicitationsMap = new Map(); +// Clean up old elicitations after 1 hour to prevent memory leaks +const ELICITATION_TTL_MS = 60 * 60 * 1000; // 1 hour +const CLEANUP_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes +function cleanupOldElicitations() { + const now = new Date(); + for (const [id, metadata] of elicitationsMap.entries()) { + if (now.getTime() - metadata.createdAt.getTime() > ELICITATION_TTL_MS) { + elicitationsMap.delete(id); + console.log(`Cleaned up expired elicitation: ${id}`); + } + } +} +setInterval(cleanupOldElicitations, CLEANUP_INTERVAL_MS); +/** + * Elicitation IDs must be unique strings within the MCP session + * UUIDs are used in this example for simplicity + */ +function generateElicitationId() { + return randomUUID(); +} +/** + * Helper function to create and track a new elicitation. + */ +function generateTrackedElicitation(sessionId, createCompletionNotifier) { + const elicitationId = generateElicitationId(); + // Create a Promise and its resolver for tracking completion + let completeResolver; + const completedPromise = new Promise(resolve => { + completeResolver = resolve; + }); + const completionNotifier = createCompletionNotifier ? createCompletionNotifier(elicitationId) : undefined; + // Store the elicitation in our map + elicitationsMap.set(elicitationId, { + status: 'pending', + completedPromise, + completeResolver: completeResolver, + createdAt: new Date(), + sessionId, + completionNotifier + }); + return elicitationId; +} +/** + * Helper function to complete an elicitation. + */ +function completeURLElicitation(elicitationId) { + const elicitation = elicitationsMap.get(elicitationId); + if (!elicitation) { + console.warn(`Attempted to complete unknown elicitation: ${elicitationId}`); + return; + } + if (elicitation.status === 'complete') { + console.warn(`Elicitation already complete: ${elicitationId}`); + return; + } + // Update metadata + elicitation.status = 'complete'; + // Send completion notification to the client + if (elicitation.completionNotifier) { + console.log(`Sending notifications/elicitation/complete notification for elicitation ${elicitationId}`); + elicitation.completionNotifier().catch(error => { + console.error(`Failed to send completion notification for elicitation ${elicitationId}:`, error); + }); + } + // Resolve the promise to unblock any waiting code + elicitation.completeResolver(); +} +const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000; +const AUTH_PORT = process.env.MCP_AUTH_PORT ? parseInt(process.env.MCP_AUTH_PORT, 10) : 3001; +const app = express(); +app.use(express.json()); +// Allow CORS all domains, expose the Mcp-Session-Id header +app.use(cors({ + origin: '*', // Allow all origins + exposedHeaders: ['Mcp-Session-Id'], + credentials: true // Allow cookies to be sent cross-origin +})); +// Set up OAuth (required for this example) +let authMiddleware = null; +// Create auth middleware for MCP endpoints +const mcpServerUrl = new URL(`http://localhost:${MCP_PORT}/mcp`); +const authServerUrl = new URL(`http://localhost:${AUTH_PORT}`); +const oauthMetadata = setupAuthServer({ authServerUrl, mcpServerUrl, strictResource: true }); +const tokenVerifier = { + verifyAccessToken: async (token) => { + const endpoint = oauthMetadata.introspection_endpoint; + if (!endpoint) { + throw new Error('No token verification endpoint available in metadata'); + } + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + token: token + }).toString() + }); + if (!response.ok) { + const text = await response.text().catch(() => null); + throw new Error(`Invalid or expired token: ${text}`); + } + const data = await response.json(); + if (!data.aud) { + throw new Error(`Resource Indicator (RFC8707) missing`); + } + if (!checkResourceAllowed({ requestedResource: data.aud, configuredResource: mcpServerUrl })) { + throw new Error(`Expected resource indicator ${mcpServerUrl}, got: ${data.aud}`); + } + // Convert the response to AuthInfo format + return { + token, + clientId: data.client_id, + scopes: data.scope ? data.scope.split(' ') : [], + expiresAt: data.exp + }; + } +}; +// Add metadata routes to the main MCP server +app.use(mcpAuthMetadataRouter({ + oauthMetadata, + resourceServerUrl: mcpServerUrl, + scopesSupported: ['mcp:tools'], + resourceName: 'MCP Demo Server' +})); +authMiddleware = requireBearerAuth({ + verifier: tokenVerifier, + requiredScopes: [], + resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(mcpServerUrl) +}); +/** + * API Key Form Handling + * + * Many servers today require an API key to operate, but there's no scalable way to do this dynamically for remote servers within MCP protocol. + * URL-mode elicitation enables the server to host a simple form and get the secret data securely from the user without involving the LLM or client. + **/ +async function sendApiKeyElicitation(sessionId, sender, createCompletionNotifier) { + if (!sessionId) { + console.error('No session ID provided'); + throw new Error('Expected a Session ID to track elicitation'); + } + console.log('🔑 URL elicitation demo: Requesting API key from client...'); + const elicitationId = generateTrackedElicitation(sessionId, createCompletionNotifier); + try { + const result = await sender({ + mode: 'url', + message: 'Please provide your API key to authenticate with this server', + // Host the form on the same server. In a real app, you might coordinate passing these state variables differently. + url: `http://localhost:${MCP_PORT}/api-key-form?session=${sessionId}&elicitation=${elicitationId}`, + elicitationId + }); + switch (result.action) { + case 'accept': + console.log('🔑 URL elicitation demo: Client accepted the API key elicitation (now pending form submission)'); + // Wait for the API key to be submitted via the form + // The form submission will complete the elicitation + break; + default: + console.log('🔑 URL elicitation demo: Client declined to provide an API key'); + // In a real app, this might close the connection, but for the demo, we'll continue + break; + } + } + catch (error) { + console.error('Error during API key elicitation:', error); + } +} +// API Key Form endpoint - serves a simple HTML form +app.get('/api-key-form', (req, res) => { + const mcpSessionId = req.query.session; + const elicitationId = req.query.elicitation; + if (!mcpSessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie + // In production, this is often handled by some user auth middleware to ensure the user has a valid session + // This session is different from the MCP session. + // This userSession is the cookie that the MCP Server's Authorization Server sets for the user when they log in. + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // Serve a simple HTML form + res.send(` + + + + Submit Your API Key + + + +

API Key Required

+
✓ Logged in as: ${userSession.name}
+
+ + + + +
+
This is a demo showing how a server can securely elicit sensitive data from a user using a URL.
+ + + `); +}); +// Handle API key form submission +app.post('/api-key-form', express.urlencoded(), (req, res) => { + const { session: sessionId, apiKey, elicitation: elicitationId } = req.body; + if (!sessionId || !apiKey || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie here too + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // A real app might store this API key to be used later for the user. + console.log(`🔑 Received API key \x1b[32m${apiKey}\x1b[0m for session ${sessionId}`); + // If we have an elicitationId, complete the elicitation + completeURLElicitation(elicitationId); + // Send a success response + res.send(` + + + + Success + + + +
+

Success ✓

+

API key received.

+
+

You can close this window and return to your MCP client.

+ + + `); +}); +// Helper to get the user session from the demo_session cookie +function getUserSessionCookie(cookieHeader) { + if (!cookieHeader) + return null; + const cookies = cookieHeader.split(';'); + for (const cookie of cookies) { + const [name, value] = cookie.trim().split('='); + if (name === 'demo_session' && value) { + try { + return JSON.parse(decodeURIComponent(value)); + } + catch (error) { + console.error('Failed to parse demo_session cookie:', error); + return null; + } + } + } + return null; +} +/** + * Payment Confirmation Form Handling + * + * This demonstrates how a server can use URL-mode elicitation to get user confirmation + * for sensitive operations like payment processing. + **/ +// Payment Confirmation Form endpoint - serves a simple HTML form +app.get('/confirm-payment', (req, res) => { + const mcpSessionId = req.query.session; + const elicitationId = req.query.elicitation; + const cartId = req.query.cartId; + if (!mcpSessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie + // In production, this is often handled by some user auth middleware to ensure the user has a valid session + // This session is different from the MCP session. + // This userSession is the cookie that the MCP Server's Authorization Server sets for the user when they log in. + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + // Serve a simple HTML form + res.send(` + + + + Confirm Payment + + + +

Confirm Payment

+
✓ Logged in as: ${userSession.name}
+ ${cartId ? `
Cart ID: ${cartId}
` : ''} +
+ ⚠️ Please review your order before confirming. +
+
+ + + ${cartId ? `` : ''} + + +
+
This is a demo showing how a server can securely get user confirmation for sensitive operations using URL-mode elicitation.
+ + + `); +}); +// Handle Payment Confirmation form submission +app.post('/confirm-payment', express.urlencoded(), (req, res) => { + const { session: sessionId, elicitation: elicitationId, cartId, action } = req.body; + if (!sessionId || !elicitationId) { + res.status(400).send('

Error

Missing required parameters

'); + return; + } + // Check for user session cookie here too + const userSession = getUserSessionCookie(req.headers.cookie); + if (!userSession) { + res.status(401).send('

Error

Unauthorized - please reconnect to login again

'); + return; + } + if (action === 'confirm') { + // A real app would process the payment here + console.log(`💳 Payment confirmed for cart ${cartId || 'unknown'} by user ${userSession.name} (session ${sessionId})`); + // Complete the elicitation + completeURLElicitation(elicitationId); + // Send a success response + res.send(` + + + + Payment Confirmed + + + +
+

Payment Confirmed ✓

+

Your payment has been successfully processed.

+ ${cartId ? `

Cart ID: ${cartId}

` : ''} +
+

You can close this window and return to your MCP client.

+ + + `); + } + else if (action === 'cancel') { + console.log(`💳 Payment cancelled for cart ${cartId || 'unknown'} by user ${userSession.name} (session ${sessionId})`); + // The client will still receive a notifications/elicitation/complete notification, + // which indicates that the out-of-band interaction is complete (but not necessarily successful) + completeURLElicitation(elicitationId); + res.send(` + + + + Payment Cancelled + + + +
+

Payment Cancelled

+

Your payment has been cancelled.

+
+

You can close this window and return to your MCP client.

+ + + `); + } + else { + res.status(400).send('

Error

Invalid action

'); + } +}); +// Map to store transports by session ID +const transports = {}; +const sessionsNeedingElicitation = {}; +// MCP POST endpoint +const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + console.debug(`Received MCP POST for session: ${sessionId || 'unknown'}`); + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + const server = getServer(); + // New initialization request + const eventStore = new InMemoryEventStore(); + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + sessionsNeedingElicitation[sessionId] = { + elicitationSender: params => server.server.elicitInput(params), + createCompletionNotifier: elicitationId => server.server.createElicitationCompletionNotifier(elicitationId) + }; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + delete sessionsNeedingElicitation[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + // so responses can flow back through the same transport + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + // The existing transport is already connected to the server + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}; +// Set up routes with auth middleware +app.post('/mcp', authMiddleware, mcpPostHandler); +// Handle GET requests for SSE streams (using built-in support from StreamableHTTP) +const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + // Check for Last-Event-ID header for resumability + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`); + } + else { + console.log(`Establishing new SSE stream for session ${sessionId}`); + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + if (sessionsNeedingElicitation[sessionId]) { + const { elicitationSender, createCompletionNotifier } = sessionsNeedingElicitation[sessionId]; + // Send an elicitation request to the client in the background + sendApiKeyElicitation(sessionId, elicitationSender, createCompletionNotifier) + .then(() => { + // Only delete on successful send for this demo + delete sessionsNeedingElicitation[sessionId]; + console.log(`🔑 URL elicitation demo: Finished sending API key elicitation request for session ${sessionId}`); + }) + .catch(error => { + console.error('Error sending API key elicitation:', error); + // Keep in map to potentially retry on next reconnect + }); + } +}; +// Set up GET route with conditional auth middleware +app.get('/mcp', authMiddleware, mcpGetHandler); +// Handle DELETE requests for session termination (according to MCP spec) +const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } +}; +// Set up DELETE route with auth middleware +app.delete('/mcp', authMiddleware, mcpDeleteHandler); +app.listen(MCP_PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + delete sessionsNeedingElicitation[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=elicitationUrlExample.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/elicitationUrlExample.js.map b/dist/esm/examples/server/elicitationUrlExample.js.map new file mode 100644 index 000000000..742290766 --- /dev/null +++ b/dist/esm/examples/server/elicitationUrlExample.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elicitationUrlExample.js","sourceRoot":"","sources":["../../../../src/examples/server/elicitationUrlExample.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,2EAA2E;AAC3E,oDAAoD;AACpD,uFAAuF;AACvF,oCAAoC;AACpC,8FAA8F;AAC9F,kEAAkE;AAElE,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,oCAAoC,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAkB,2BAA2B,EAAwC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxI,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAA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AAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts b/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts new file mode 100644 index 000000000..477fa6bae --- /dev/null +++ b/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=jsonResponseStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts.map b/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts.map new file mode 100644 index 000000000..ee8117ee2 --- /dev/null +++ b/dist/esm/examples/server/jsonResponseStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"jsonResponseStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/jsonResponseStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/jsonResponseStreamableHttp.js b/dist/esm/examples/server/jsonResponseStreamableHttp.js new file mode 100644 index 000000000..f9bd04d87 --- /dev/null +++ b/dist/esm/examples/server/jsonResponseStreamableHttp.js @@ -0,0 +1,147 @@ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import * as z from 'zod/v4'; +import { isInitializeRequest } from '../../types.js'; +import cors from 'cors'; +// Create an MCP server with implementation details +const getServer = () => { + const server = new McpServer({ + name: 'json-response-streamable-http-server', + version: '1.0.0' + }, { + capabilities: { + logging: {} + } + }); + // Register a simple tool that returns a greeting + server.tool('greet', 'A simple greeting tool', { + name: z.string().describe('Name to greet') + }, async ({ name }) => { + return { + content: [ + { + type: 'text', + text: `Hello, ${name}!` + } + ] + }; + }); + // Register a tool that sends multiple greetings with notifications + server.tool('multi-greet', 'A tool that sends different greetings with delays between them', { + name: z.string().describe('Name to greet') + }, async ({ name }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + await server.sendLoggingMessage({ + level: 'debug', + data: `Starting multi-greet for ${name}` + }, extra.sessionId); + await sleep(1000); // Wait 1 second before first greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending first greeting to ${name}` + }, extra.sessionId); + await sleep(1000); // Wait another second before second greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending second greeting to ${name}` + }, extra.sessionId); + return { + content: [ + { + type: 'text', + text: `Good morning, ${name}!` + } + ] + }; + }); + return server; +}; +const app = express(); +app.use(express.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use(cors({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +// Map to store transports by session ID +const transports = {}; +app.post('/mcp', async (req, res) => { + console.log('Received MCP request:', req.body); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + // New initialization request - use JSON response mode + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + enableJsonResponse: true, // Enable JSON response mode + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Connect the transport to the MCP server BEFORE handling the request + const server = getServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams according to spec +app.get('/mcp', async (req, res) => { + // Since this is a very simple example, we don't support GET requests for this server + // The spec requires returning 405 Method Not Allowed in this case + res.status(405).set('Allow', 'POST').send('Method Not Allowed'); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + process.exit(0); +}); +//# sourceMappingURL=jsonResponseStreamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/jsonResponseStreamableHttp.js.map b/dist/esm/examples/server/jsonResponseStreamableHttp.js.map new file mode 100644 index 000000000..67ae23baa --- /dev/null +++ b/dist/esm/examples/server/jsonResponseStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"jsonResponseStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/jsonResponseStreamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAkB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,mDAAmD;AACnD,MAAM,SAAS,GAAG,GAAG,EAAE;IACnB,MAAM,MAAM,GAAG,IAAI,SAAS,CACxB;QACI,IAAI,EAAE,sCA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AC;AACL,CAAC,CAAC,CAAC;AAEH,wDAAwD;AACxD,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;IAClD,qFAAqF;IACrF,kEAAkE;IAClE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;IACrB,IAAI,KAAK,EAAE,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,gDAAgD,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/mcpServerOutputSchema.d.ts b/dist/esm/examples/server/mcpServerOutputSchema.d.ts new file mode 100644 index 000000000..a6cb49747 --- /dev/null +++ b/dist/esm/examples/server/mcpServerOutputSchema.d.ts @@ -0,0 +1,7 @@ +#!/usr/bin/env node +/** + * Example MCP server using the high-level McpServer API with outputSchema + * This demonstrates how to easily create tools with structured output + */ +export {}; +//# sourceMappingURL=mcpServerOutputSchema.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/mcpServerOutputSchema.d.ts.map b/dist/esm/examples/server/mcpServerOutputSchema.d.ts.map new file mode 100644 index 000000000..bd3abdcc2 --- /dev/null +++ b/dist/esm/examples/server/mcpServerOutputSchema.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcpServerOutputSchema.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/mcpServerOutputSchema.ts"],"names":[],"mappings":";AACA;;;GAGG"} \ No newline at end of file diff --git a/dist/esm/examples/server/mcpServerOutputSchema.js b/dist/esm/examples/server/mcpServerOutputSchema.js new file mode 100644 index 000000000..17b52b73e --- /dev/null +++ b/dist/esm/examples/server/mcpServerOutputSchema.js @@ -0,0 +1,70 @@ +#!/usr/bin/env node +/** + * Example MCP server using the high-level McpServer API with outputSchema + * This demonstrates how to easily create tools with structured output + */ +import { McpServer } from '../../server/mcp.js'; +import { StdioServerTransport } from '../../server/stdio.js'; +import * as z from 'zod/v4'; +const server = new McpServer({ + name: 'mcp-output-schema-high-level-example', + version: '1.0.0' +}); +// Define a tool with structured output - Weather data +server.registerTool('get_weather', { + description: 'Get weather information for a city', + inputSchema: { + city: z.string().describe('City name'), + country: z.string().describe('Country code (e.g., US, UK)') + }, + outputSchema: { + temperature: z.object({ + celsius: z.number(), + fahrenheit: z.number() + }), + conditions: z.enum(['sunny', 'cloudy', 'rainy', 'stormy', 'snowy']), + humidity: z.number().min(0).max(100), + wind: z.object({ + speed_kmh: z.number(), + direction: z.string() + }) + } +}, async ({ city, country }) => { + // Parameters are available but not used in this example + void city; + void country; + // Simulate weather API call + const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10; + const conditions = ['sunny', 'cloudy', 'rainy', 'stormy', 'snowy'][Math.floor(Math.random() * 5)]; + const structuredContent = { + temperature: { + celsius: temp_c, + fahrenheit: Math.round(((temp_c * 9) / 5 + 32) * 10) / 10 + }, + conditions, + humidity: Math.round(Math.random() * 100), + wind: { + speed_kmh: Math.round(Math.random() * 50), + direction: ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'][Math.floor(Math.random() * 8)] + } + }; + return { + content: [ + { + type: 'text', + text: JSON.stringify(structuredContent, null, 2) + } + ], + structuredContent + }; +}); +async function main() { + const transport = new StdioServerTransport(); + await server.connect(transport); + console.error('High-level Output Schema Example Server running on stdio'); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=mcpServerOutputSchema.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/mcpServerOutputSchema.js.map b/dist/esm/examples/server/mcpServerOutputSchema.js.map new file mode 100644 index 000000000..b932b856b --- /dev/null +++ b/dist/esm/examples/server/mcpServerOutputSchema.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcpServerOutputSchema.js","sourceRoot":"","sources":["../../../../src/examples/server/mcpServerOutputSchema.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IACzB,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,sDAAsD;AACtD,MAAM,CAAC,YAAY,CACf,aAAa,EACb;IACI,WAAW,EAAE,oCAAoC;IACjD,WAAW,EAAE;QACT,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC;QACtC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KAC9D;IACD,YAAY,EAAE;QACV,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;YACnB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;SACzB,CAAC;QACF,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAA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,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;SACzF;KACJ,CAAC;IAEF,OAAO;QACH,OAAO,EAAE;YACL;gBACI,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;aACnD;SACJ;QACD,iBAAiB;KACpB,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleSseServer.d.ts b/dist/esm/examples/server/simpleSseServer.d.ts new file mode 100644 index 000000000..4269b7814 --- /dev/null +++ b/dist/esm/examples/server/simpleSseServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleSseServer.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleSseServer.d.ts.map b/dist/esm/examples/server/simpleSseServer.d.ts.map new file mode 100644 index 000000000..08a1b4502 --- /dev/null +++ b/dist/esm/examples/server/simpleSseServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleSseServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleSseServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleSseServer.js b/dist/esm/examples/server/simpleSseServer.js new file mode 100644 index 000000000..21e8ef96b --- /dev/null +++ b/dist/esm/examples/server/simpleSseServer.js @@ -0,0 +1,141 @@ +import express from 'express'; +import { McpServer } from '../../server/mcp.js'; +import { SSEServerTransport } from '../../server/sse.js'; +import * as z from 'zod/v4'; +/** + * This example server demonstrates the deprecated HTTP+SSE transport + * (protocol version 2024-11-05). It mainly used for testing backward compatible clients. + * + * The server exposes two endpoints: + * - /mcp: For establishing the SSE stream (GET) + * - /messages: For receiving client messages (POST) + * + */ +// Create an MCP server instance +const getServer = () => { + const server = new McpServer({ + name: 'simple-sse-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + server.tool('start-notification-stream', 'Starts sending periodic notifications', { + interval: z.number().describe('Interval in milliseconds between notifications').default(1000), + count: z.number().describe('Number of notifications to send').default(10) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + // Send the initial notification + await server.sendLoggingMessage({ + level: 'info', + data: `Starting notification stream with ${count} messages every ${interval}ms` + }, extra.sessionId); + // Send periodic notifications + while (counter < count) { + counter++; + await sleep(interval); + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + } + return { + content: [ + { + type: 'text', + text: `Completed sending ${count} notifications every ${interval}ms` + } + ] + }; + }); + return server; +}; +const app = express(); +app.use(express.json()); +// Store transports by session ID +const transports = {}; +// SSE endpoint for establishing the stream +app.get('/mcp', async (req, res) => { + console.log('Received GET request to /sse (establishing SSE stream)'); + try { + // Create a new SSE transport for the client + // The endpoint for POST messages is '/messages' + const transport = new SSEServerTransport('/messages', res); + // Store the transport by session ID + const sessionId = transport.sessionId; + transports[sessionId] = transport; + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + console.log(`SSE transport closed for session ${sessionId}`); + delete transports[sessionId]; + }; + // Connect the transport to the MCP server + const server = getServer(); + await server.connect(transport); + console.log(`Established SSE stream with session ID: ${sessionId}`); + } + catch (error) { + console.error('Error establishing SSE stream:', error); + if (!res.headersSent) { + res.status(500).send('Error establishing SSE stream'); + } + } +}); +// Messages endpoint for receiving client JSON-RPC requests +app.post('/messages', async (req, res) => { + console.log('Received POST request to /messages'); + // Extract session ID from URL query parameter + // In the SSE protocol, this is added by the client based on the endpoint event + const sessionId = req.query.sessionId; + if (!sessionId) { + console.error('No session ID provided in request URL'); + res.status(400).send('Missing sessionId parameter'); + return; + } + const transport = transports[sessionId]; + if (!transport) { + console.error(`No active transport found for session ID: ${sessionId}`); + res.status(404).send('Session not found'); + return; + } + try { + // Handle the POST message with the transport + await transport.handlePostMessage(req, res, req.body); + } + catch (error) { + console.error('Error handling request:', error); + if (!res.headersSent) { + res.status(500).send('Error handling request'); + } + } +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Simple SSE Server (deprecated protocol version 2024-11-05) listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleSseServer.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleSseServer.js.map b/dist/esm/examples/server/simpleSseServer.js.map new file mode 100644 index 000000000..4ac49a232 --- /dev/null +++ b/dist/esm/examples/server/simpleSseServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleSseServer.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleSseServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAq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file diff --git a/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts b/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts new file mode 100644 index 000000000..0aa4ad243 --- /dev/null +++ b/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStatelessStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts.map b/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts.map new file mode 100644 index 000000000..92deb06ec --- /dev/null +++ b/dist/esm/examples/server/simpleStatelessStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStatelessStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleStatelessStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStatelessStreamableHttp.js b/dist/esm/examples/server/simpleStatelessStreamableHttp.js new file mode 100644 index 000000000..d9e24a1d0 --- /dev/null +++ b/dist/esm/examples/server/simpleStatelessStreamableHttp.js @@ -0,0 +1,142 @@ +import express from 'express'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import * as z from 'zod/v4'; +import cors from 'cors'; +const getServer = () => { + // Create an MCP server with implementation details + const server = new McpServer({ + name: 'stateless-streamable-http-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + // Register a simple prompt + server.prompt('greeting-template', 'A simple greeting prompt template', { + name: z.string().describe('Name to include in greeting') + }, async ({ name }) => { + return { + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please greet ${name} in a friendly manner.` + } + } + ] + }; + }); + // Register a tool specifically for testing resumability + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(10) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + // Create a simple resource at a fixed URI + server.resource('greeting-resource', 'https://example.com/greetings/default', { mimeType: 'text/plain' }, async () => { + return { + contents: [ + { + uri: 'https://example.com/greetings/default', + text: 'Hello, world!' + } + ] + }; + }); + return server; +}; +const app = express(); +app.use(express.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use(cors({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +app.post('/mcp', async (req, res) => { + const server = getServer(); + try { + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: undefined + }); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + res.on('close', () => { + console.log('Request closed'); + transport.close(); + server.close(); + }); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +app.get('/mcp', async (req, res) => { + console.log('Received GET MCP request'); + res.writeHead(405).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); +}); +app.delete('/mcp', async (req, res) => { + console.log('Received DELETE MCP request'); + res.writeHead(405).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Stateless Streamable HTTP Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + process.exit(0); +}); +//# sourceMappingURL=simpleStatelessStreamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStatelessStreamableHttp.js.map b/dist/esm/examples/server/simpleStatelessStreamableHttp.js.map new file mode 100644 index 000000000..4963fadc1 --- /dev/null +++ b/dist/esm/examples/server/simpleStatelessStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStatelessStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleStatelessStreamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,SAAS,GAAG,GAAG,EAAE;IACnB,mDAAmD;IACnD,MAAM,MAAM,GAAG,IAAI,SAAS,CACxB;QACI,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,OAAO;KACnB,EACD,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CACpC,CAAC;IAEF,2BAA2B;IAC3B,MAAM,CAAC,MAAM,CACT,mBAAmB,EACnB,mCAAmC,EACnC;QACI,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KAC3D,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,EAA4B,EAAE;QACzC,OAAO;YACH,QAAQ,EAAE;gBACN;oBACI,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACL,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,gBAAgB,IAAI,wBAAwB;qBACrD;iBACJ;aACJ;SACJ,CAAC;IACN,CAAC,CACJ,CAAC;IAEF,wDAAwD;IACxD,MAAM,CAAC,IAAI,CACP,2BAA2B,EAC3B,gEAAg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;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0DAA0D,IAAI,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStreamableHttp.d.ts b/dist/esm/examples/server/simpleStreamableHttp.d.ts new file mode 100644 index 000000000..a20be42ca --- /dev/null +++ b/dist/esm/examples/server/simpleStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=simpleStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStreamableHttp.d.ts.map b/dist/esm/examples/server/simpleStreamableHttp.d.ts.map new file mode 100644 index 000000000..e3cf04224 --- /dev/null +++ b/dist/esm/examples/server/simpleStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStreamableHttp.js b/dist/esm/examples/server/simpleStreamableHttp.js new file mode 100644 index 000000000..3ec37261e --- /dev/null +++ b/dist/esm/examples/server/simpleStreamableHttp.js @@ -0,0 +1,633 @@ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import * as z from 'zod/v4'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter } from '../../server/auth/router.js'; +import { requireBearerAuth } from '../../server/auth/middleware/bearerAuth.js'; +import { ElicitResultSchema, isInitializeRequest } from '../../types.js'; +import { InMemoryEventStore } from '../shared/inMemoryEventStore.js'; +import { InMemoryTaskStore, InMemoryTaskMessageQueue } from '../../experimental/tasks/stores/in-memory.js'; +import { setupAuthServer } from './demoInMemoryOAuthProvider.js'; +import { checkResourceAllowed } from '../../shared/auth-utils.js'; +import cors from 'cors'; +// Check for OAuth flag +const useOAuth = process.argv.includes('--oauth'); +const strictOAuth = process.argv.includes('--oauth-strict'); +// Create shared task store for demonstration +const taskStore = new InMemoryTaskStore(); +// Create an MCP server with implementation details +const getServer = () => { + const server = new McpServer({ + name: 'simple-streamable-http-server', + version: '1.0.0', + icons: [{ src: './mcp.svg', sizes: ['512x512'], mimeType: 'image/svg+xml' }], + websiteUrl: 'https://github.com/modelcontextprotocol/typescript-sdk' + }, { + capabilities: { logging: {}, tasks: { requests: { tools: { call: {} } } } }, + taskStore, // Enable task support + taskMessageQueue: new InMemoryTaskMessageQueue() + }); + // Register a simple tool that returns a greeting + server.registerTool('greet', { + title: 'Greeting Tool', // Display name for UI + description: 'A simple greeting tool', + inputSchema: { + name: z.string().describe('Name to greet') + } + }, async ({ name }) => { + return { + content: [ + { + type: 'text', + text: `Hello, ${name}!` + } + ] + }; + }); + // Register a tool that sends multiple greetings with notifications (with annotations) + server.tool('multi-greet', 'A tool that sends different greetings with delays between them', { + name: z.string().describe('Name to greet') + }, { + title: 'Multiple Greeting Tool', + readOnlyHint: true, + openWorldHint: false + }, async ({ name }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + await server.sendLoggingMessage({ + level: 'debug', + data: `Starting multi-greet for ${name}` + }, extra.sessionId); + await sleep(1000); // Wait 1 second before first greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending first greeting to ${name}` + }, extra.sessionId); + await sleep(1000); // Wait another second before second greeting + await server.sendLoggingMessage({ + level: 'info', + data: `Sending second greeting to ${name}` + }, extra.sessionId); + return { + content: [ + { + type: 'text', + text: `Good morning, ${name}!` + } + ] + }; + }); + // Register a tool that demonstrates form elicitation (user input collection with a schema) + // This creates a closure that captures the server instance + server.tool('collect-user-info', 'A tool that collects user information through form elicitation', { + infoType: z.enum(['contact', 'preferences', 'feedback']).describe('Type of information to collect') + }, async ({ infoType }, extra) => { + let message; + let requestedSchema; + switch (infoType) { + case 'contact': + message = 'Please provide your contact information'; + requestedSchema = { + type: 'object', + properties: { + name: { + type: 'string', + title: 'Full Name', + description: 'Your full name' + }, + email: { + type: 'string', + title: 'Email Address', + description: 'Your email address', + format: 'email' + }, + phone: { + type: 'string', + title: 'Phone Number', + description: 'Your phone number (optional)' + } + }, + required: ['name', 'email'] + }; + break; + case 'preferences': + message = 'Please set your preferences'; + requestedSchema = { + type: 'object', + properties: { + theme: { + type: 'string', + title: 'Theme', + description: 'Choose your preferred theme', + enum: ['light', 'dark', 'auto'], + enumNames: ['Light', 'Dark', 'Auto'] + }, + notifications: { + type: 'boolean', + title: 'Enable Notifications', + description: 'Would you like to receive notifications?', + default: true + }, + frequency: { + type: 'string', + title: 'Notification Frequency', + description: 'How often would you like notifications?', + enum: ['daily', 'weekly', 'monthly'], + enumNames: ['Daily', 'Weekly', 'Monthly'] + } + }, + required: ['theme'] + }; + break; + case 'feedback': + message = 'Please provide your feedback'; + requestedSchema = { + type: 'object', + properties: { + rating: { + type: 'integer', + title: 'Rating', + description: 'Rate your experience (1-5)', + minimum: 1, + maximum: 5 + }, + comments: { + type: 'string', + title: 'Comments', + description: 'Additional comments (optional)', + maxLength: 500 + }, + recommend: { + type: 'boolean', + title: 'Would you recommend this?', + description: 'Would you recommend this to others?' + } + }, + required: ['rating', 'recommend'] + }; + break; + default: + throw new Error(`Unknown info type: ${infoType}`); + } + try { + // Use sendRequest through the extra parameter to elicit input + const result = await extra.sendRequest({ + method: 'elicitation/create', + params: { + mode: 'form', + message, + requestedSchema + } + }, ElicitResultSchema); + if (result.action === 'accept') { + return { + content: [ + { + type: 'text', + text: `Thank you! Collected ${infoType} information: ${JSON.stringify(result.content, null, 2)}` + } + ] + }; + } + else if (result.action === 'decline') { + return { + content: [ + { + type: 'text', + text: `No information was collected. User declined ${infoType} information request.` + } + ] + }; + } + else { + return { + content: [ + { + type: 'text', + text: `Information collection was cancelled by the user.` + } + ] + }; + } + } + catch (error) { + return { + content: [ + { + type: 'text', + text: `Error collecting ${infoType} information: ${error}` + } + ] + }; + } + }); + // Register a simple prompt with title + server.registerPrompt('greeting-template', { + title: 'Greeting Template', // Display name for UI + description: 'A simple greeting prompt template', + argsSchema: { + name: z.string().describe('Name to include in greeting') + } + }, async ({ name }) => { + return { + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please greet ${name} in a friendly manner.` + } + } + ] + }; + }); + // Register a tool specifically for testing resumability + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(50) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + // Create a simple resource at a fixed URI + server.registerResource('greeting-resource', 'https://example.com/greetings/default', { + title: 'Default Greeting', // Display name for UI + description: 'A simple greeting resource', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'https://example.com/greetings/default', + text: 'Hello, world!' + } + ] + }; + }); + // Create additional resources for ResourceLink demonstration + server.registerResource('example-file-1', 'file:///example/file1.txt', { + title: 'Example File 1', + description: 'First example file for ResourceLink demonstration', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'file:///example/file1.txt', + text: 'This is the content of file 1' + } + ] + }; + }); + server.registerResource('example-file-2', 'file:///example/file2.txt', { + title: 'Example File 2', + description: 'Second example file for ResourceLink demonstration', + mimeType: 'text/plain' + }, async () => { + return { + contents: [ + { + uri: 'file:///example/file2.txt', + text: 'This is the content of file 2' + } + ] + }; + }); + // Register a tool that returns ResourceLinks + server.registerTool('list-files', { + title: 'List Files with ResourceLinks', + description: 'Returns a list of files as ResourceLinks without embedding their content', + inputSchema: { + includeDescriptions: z.boolean().optional().describe('Whether to include descriptions in the resource links') + } + }, async ({ includeDescriptions = true }) => { + const resourceLinks = [ + { + type: 'resource_link', + uri: 'https://example.com/greetings/default', + name: 'Default Greeting', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'A simple greeting resource' }) + }, + { + type: 'resource_link', + uri: 'file:///example/file1.txt', + name: 'Example File 1', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'First example file for ResourceLink demonstration' }) + }, + { + type: 'resource_link', + uri: 'file:///example/file2.txt', + name: 'Example File 2', + mimeType: 'text/plain', + ...(includeDescriptions && { description: 'Second example file for ResourceLink demonstration' }) + } + ]; + return { + content: [ + { + type: 'text', + text: 'Here are the available files as resource links:' + }, + ...resourceLinks, + { + type: 'text', + text: '\nYou can read any of these resources using their URI.' + } + ] + }; + }); + // Register a long-running tool that demonstrates task execution + // Using the experimental tasks API - WARNING: may change without notice + server.experimental.tasks.registerToolTask('delay', { + title: 'Delay', + description: 'A simple tool that delays for a specified duration, useful for testing task execution', + inputSchema: { + duration: z.number().describe('Duration in milliseconds').default(5000) + } + }, { + async createTask({ duration }, { taskStore, taskRequestedTtl }) { + // Create the task + const task = await taskStore.createTask({ + ttl: taskRequestedTtl + }); + // Simulate out-of-band work + (async () => { + await new Promise(resolve => setTimeout(resolve, duration)); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [ + { + type: 'text', + text: `Completed ${duration}ms delay` + } + ] + }); + })(); + // Return CreateTaskResult with the created task + return { + task + }; + }, + async getTask(_args, { taskId, taskStore }) { + return await taskStore.getTask(taskId); + }, + async getTaskResult(_args, { taskId, taskStore }) { + const result = await taskStore.getTaskResult(taskId); + return result; + } + }); + return server; +}; +const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000; +const AUTH_PORT = process.env.MCP_AUTH_PORT ? parseInt(process.env.MCP_AUTH_PORT, 10) : 3001; +const app = express(); +app.use(express.json()); +// Allow CORS all domains, expose the Mcp-Session-Id header +app.use(cors({ + origin: '*', // Allow all origins + exposedHeaders: ['Mcp-Session-Id'] +})); +// Set up OAuth if enabled +let authMiddleware = null; +if (useOAuth) { + // Create auth middleware for MCP endpoints + const mcpServerUrl = new URL(`http://localhost:${MCP_PORT}/mcp`); + const authServerUrl = new URL(`http://localhost:${AUTH_PORT}`); + const oauthMetadata = setupAuthServer({ authServerUrl, mcpServerUrl, strictResource: strictOAuth }); + const tokenVerifier = { + verifyAccessToken: async (token) => { + const endpoint = oauthMetadata.introspection_endpoint; + if (!endpoint) { + throw new Error('No token verification endpoint available in metadata'); + } + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + token: token + }).toString() + }); + if (!response.ok) { + const text = await response.text().catch(() => null); + throw new Error(`Invalid or expired token: ${text}`); + } + const data = await response.json(); + if (strictOAuth) { + if (!data.aud) { + throw new Error(`Resource Indicator (RFC8707) missing`); + } + if (!checkResourceAllowed({ requestedResource: data.aud, configuredResource: mcpServerUrl })) { + throw new Error(`Expected resource indicator ${mcpServerUrl}, got: ${data.aud}`); + } + } + // Convert the response to AuthInfo format + return { + token, + clientId: data.client_id, + scopes: data.scope ? data.scope.split(' ') : [], + expiresAt: data.exp + }; + } + }; + // Add metadata routes to the main MCP server + app.use(mcpAuthMetadataRouter({ + oauthMetadata, + resourceServerUrl: mcpServerUrl, + scopesSupported: ['mcp:tools'], + resourceName: 'MCP Demo Server' + })); + authMiddleware = requireBearerAuth({ + verifier: tokenVerifier, + requiredScopes: [], + resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(mcpServerUrl) + }); +} +// Map to store transports by session ID +const transports = {}; +// MCP POST endpoint with optional auth +const mcpPostHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (sessionId) { + console.log(`Received MCP request for session: ${sessionId}`); + } + else { + console.log('Request body:', req.body); + } + if (useOAuth && req.auth) { + console.log('Authenticated user:', req.auth); + } + try { + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + // New initialization request + const eventStore = new InMemoryEventStore(); + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server BEFORE handling the request + // so responses can flow back through the same transport + const server = getServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport - no need to reconnect + // The existing transport is already connected to the server + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}; +// Set up routes with conditional auth middleware +if (useOAuth && authMiddleware) { + app.post('/mcp', authMiddleware, mcpPostHandler); +} +else { + app.post('/mcp', mcpPostHandler); +} +// Handle GET requests for SSE streams (using built-in support from StreamableHTTP) +const mcpGetHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + if (useOAuth && req.auth) { + console.log('Authenticated SSE connection from user:', req.auth); + } + // Check for Last-Event-ID header for resumability + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`); + } + else { + console.log(`Establishing new SSE stream for session ${sessionId}`); + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}; +// Set up GET route with conditional auth middleware +if (useOAuth && authMiddleware) { + app.get('/mcp', authMiddleware, mcpGetHandler); +} +else { + app.get('/mcp', mcpGetHandler); +} +// Handle DELETE requests for session termination (according to MCP spec) +const mcpDeleteHandler = async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Received session termination request for session ${sessionId}`); + try { + const transport = transports[sessionId]; + await transport.handleRequest(req, res); + } + catch (error) { + console.error('Error handling session termination:', error); + if (!res.headersSent) { + res.status(500).send('Error processing session termination'); + } + } +}; +// Set up DELETE route with conditional auth middleware +if (useOAuth && authMiddleware) { + app.delete('/mcp', authMiddleware, mcpDeleteHandler); +} +else { + app.delete('/mcp', mcpDeleteHandler); +} +app.listen(MCP_PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleStreamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleStreamableHttp.js.map b/dist/esm/examples/server/simpleStreamableHttp.js.map new file mode 100644 index 000000000..733cefc17 --- /dev/null +++ b/dist/esm/examples/server/simpleStreamableHttp.js.map @@ -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AAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleTaskInteractive.d.ts b/dist/esm/examples/server/simpleTaskInteractive.d.ts new file mode 100644 index 000000000..661c9f010 --- /dev/null +++ b/dist/esm/examples/server/simpleTaskInteractive.d.ts @@ -0,0 +1,12 @@ +/** + * Simple interactive task server demonstrating elicitation and sampling. + * + * This server demonstrates the task message queue pattern from the MCP Tasks spec: + * - confirm_delete: Uses elicitation to ask the user for confirmation + * - write_haiku: Uses sampling to request an LLM to generate content + * + * Both tools use the "call-now, fetch-later" pattern where the initial call + * creates a task, and the result is fetched via tasks/result endpoint. + */ +export {}; +//# sourceMappingURL=simpleTaskInteractive.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleTaskInteractive.d.ts.map b/dist/esm/examples/server/simpleTaskInteractive.d.ts.map new file mode 100644 index 000000000..3e48b9e76 --- /dev/null +++ b/dist/esm/examples/server/simpleTaskInteractive.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractive.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/simpleTaskInteractive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"} \ No newline at end of file diff --git a/dist/esm/examples/server/simpleTaskInteractive.js b/dist/esm/examples/server/simpleTaskInteractive.js new file mode 100644 index 000000000..d1ac14034 --- /dev/null +++ b/dist/esm/examples/server/simpleTaskInteractive.js @@ -0,0 +1,603 @@ +/** + * Simple interactive task server demonstrating elicitation and sampling. + * + * This server demonstrates the task message queue pattern from the MCP Tasks spec: + * - confirm_delete: Uses elicitation to ask the user for confirmation + * - write_haiku: Uses sampling to request an LLM to generate content + * + * Both tools use the "call-now, fetch-later" pattern where the initial call + * creates a task, and the result is fetched via tasks/result endpoint. + */ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { Server } from '../../server/index.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { RELATED_TASK_META_KEY, ListToolsRequestSchema, CallToolRequestSchema, GetTaskRequestSchema, GetTaskPayloadRequestSchema } from '../../types.js'; +import { isTerminal } from '../../experimental/tasks/interfaces.js'; +import { InMemoryTaskStore } from '../../experimental/tasks/stores/in-memory.js'; +// ============================================================================ +// Resolver - Promise-like for passing results between async operations +// ============================================================================ +class Resolver { + constructor() { + this._done = false; + this._promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + }); + } + setResult(value) { + if (this._done) + return; + this._done = true; + this._resolve(value); + } + setException(error) { + if (this._done) + return; + this._done = true; + this._reject(error); + } + wait() { + return this._promise; + } + done() { + return this._done; + } +} +class TaskMessageQueueWithResolvers { + constructor() { + this.queues = new Map(); + this.waitResolvers = new Map(); + } + getQueue(taskId) { + let queue = this.queues.get(taskId); + if (!queue) { + queue = []; + this.queues.set(taskId, queue); + } + return queue; + } + async enqueue(taskId, message, _sessionId, maxSize) { + const queue = this.getQueue(taskId); + if (maxSize !== undefined && queue.length >= maxSize) { + throw new Error(`Task message queue overflow: queue size (${queue.length}) exceeds maximum (${maxSize})`); + } + queue.push(message); + // Notify any waiters + this.notifyWaiters(taskId); + } + async enqueueWithResolver(taskId, message, resolver, originalRequestId) { + const queue = this.getQueue(taskId); + const queuedMessage = { + type: 'request', + message, + timestamp: Date.now(), + resolver, + originalRequestId + }; + queue.push(queuedMessage); + this.notifyWaiters(taskId); + } + async dequeue(taskId, _sessionId) { + const queue = this.getQueue(taskId); + return queue.shift(); + } + async dequeueAll(taskId, _sessionId) { + var _a; + const queue = (_a = this.queues.get(taskId)) !== null && _a !== void 0 ? _a : []; + this.queues.delete(taskId); + return queue; + } + async waitForMessage(taskId) { + // Check if there are already messages + const queue = this.getQueue(taskId); + if (queue.length > 0) + return; + // Wait for a message to be added + return new Promise(resolve => { + let waiters = this.waitResolvers.get(taskId); + if (!waiters) { + waiters = []; + this.waitResolvers.set(taskId, waiters); + } + waiters.push(resolve); + }); + } + notifyWaiters(taskId) { + const waiters = this.waitResolvers.get(taskId); + if (waiters) { + this.waitResolvers.delete(taskId); + for (const resolve of waiters) { + resolve(); + } + } + } + cleanup() { + this.queues.clear(); + this.waitResolvers.clear(); + } +} +// ============================================================================ +// Extended task store with wait functionality +// ============================================================================ +class TaskStoreWithNotifications extends InMemoryTaskStore { + constructor() { + super(...arguments); + this.updateResolvers = new Map(); + } + async updateTaskStatus(taskId, status, statusMessage, sessionId) { + await super.updateTaskStatus(taskId, status, statusMessage, sessionId); + this.notifyUpdate(taskId); + } + async storeTaskResult(taskId, status, result, sessionId) { + await super.storeTaskResult(taskId, status, result, sessionId); + this.notifyUpdate(taskId); + } + async waitForUpdate(taskId) { + return new Promise(resolve => { + let waiters = this.updateResolvers.get(taskId); + if (!waiters) { + waiters = []; + this.updateResolvers.set(taskId, waiters); + } + waiters.push(resolve); + }); + } + notifyUpdate(taskId) { + const waiters = this.updateResolvers.get(taskId); + if (waiters) { + this.updateResolvers.delete(taskId); + for (const resolve of waiters) { + resolve(); + } + } + } +} +// ============================================================================ +// Task Result Handler - delivers queued messages and routes responses +// ============================================================================ +class TaskResultHandler { + constructor(store, queue) { + this.store = store; + this.queue = queue; + this.pendingRequests = new Map(); + } + async handle(taskId, server, _sessionId) { + while (true) { + // Get fresh task state + const task = await this.store.getTask(taskId); + if (!task) { + throw new Error(`Task not found: ${taskId}`); + } + // Dequeue and send all pending messages + await this.deliverQueuedMessages(taskId, server, _sessionId); + // If task is terminal, return result + if (isTerminal(task.status)) { + const result = await this.store.getTaskResult(taskId); + // Add related-task metadata per spec + return { + ...result, + _meta: { + ...(result._meta || {}), + [RELATED_TASK_META_KEY]: { taskId } + } + }; + } + // Wait for task update or new message + await this.waitForUpdate(taskId); + } + } + async deliverQueuedMessages(taskId, server, _sessionId) { + while (true) { + const message = await this.queue.dequeue(taskId); + if (!message) + break; + console.log(`[Server] Delivering queued ${message.type} message for task ${taskId}`); + if (message.type === 'request') { + const reqMessage = message; + // Send the request via the server + // Store the resolver so we can route the response back + if (reqMessage.resolver && reqMessage.originalRequestId) { + this.pendingRequests.set(reqMessage.originalRequestId, reqMessage.resolver); + } + // Send the message - for elicitation/sampling, we use the server's methods + // But since we're in tasks/result context, we need to send via transport + // This is simplified - in production you'd use proper message routing + try { + const request = reqMessage.message; + let response; + if (request.method === 'elicitation/create') { + // Send elicitation request to client + const params = request.params; + response = await server.elicitInput(params); + } + else if (request.method === 'sampling/createMessage') { + // Send sampling request to client + const params = request.params; + response = await server.createMessage(params); + } + else { + throw new Error(`Unknown request method: ${request.method}`); + } + // Route response back to resolver + if (reqMessage.resolver) { + reqMessage.resolver.setResult(response); + } + } + catch (error) { + if (reqMessage.resolver) { + reqMessage.resolver.setException(error instanceof Error ? error : new Error(String(error))); + } + } + } + // For notifications, we'd send them too but this example focuses on requests + } + } + async waitForUpdate(taskId) { + // Race between store update and queue message + await Promise.race([this.store.waitForUpdate(taskId), this.queue.waitForMessage(taskId)]); + } + routeResponse(requestId, response) { + const resolver = this.pendingRequests.get(requestId); + if (resolver && !resolver.done()) { + this.pendingRequests.delete(requestId); + resolver.setResult(response); + return true; + } + return false; + } + routeError(requestId, error) { + const resolver = this.pendingRequests.get(requestId); + if (resolver && !resolver.done()) { + this.pendingRequests.delete(requestId); + resolver.setException(error); + return true; + } + return false; + } +} +// ============================================================================ +// Task Session - wraps server to enqueue requests during task execution +// ============================================================================ +class TaskSession { + constructor(server, taskId, store, queue) { + this.server = server; + this.taskId = taskId; + this.store = store; + this.queue = queue; + this.requestCounter = 0; + } + nextRequestId() { + return `task-${this.taskId}-${++this.requestCounter}`; + } + async elicit(message, requestedSchema) { + // Update task status to input_required + await this.store.updateTaskStatus(this.taskId, 'input_required'); + const requestId = this.nextRequestId(); + // Build the elicitation request with related-task metadata + const params = { + message, + requestedSchema, + mode: 'form', + _meta: { + [RELATED_TASK_META_KEY]: { taskId: this.taskId } + } + }; + const jsonrpcRequest = { + jsonrpc: '2.0', + id: requestId, + method: 'elicitation/create', + params + }; + // Create resolver to wait for response + const resolver = new Resolver(); + // Enqueue the request + await this.queue.enqueueWithResolver(this.taskId, jsonrpcRequest, resolver, requestId); + try { + // Wait for response + const response = await resolver.wait(); + // Update status back to working + await this.store.updateTaskStatus(this.taskId, 'working'); + return response; + } + catch (error) { + await this.store.updateTaskStatus(this.taskId, 'working'); + throw error; + } + } + async createMessage(messages, maxTokens) { + // Update task status to input_required + await this.store.updateTaskStatus(this.taskId, 'input_required'); + const requestId = this.nextRequestId(); + // Build the sampling request with related-task metadata + const params = { + messages, + maxTokens, + _meta: { + [RELATED_TASK_META_KEY]: { taskId: this.taskId } + } + }; + const jsonrpcRequest = { + jsonrpc: '2.0', + id: requestId, + method: 'sampling/createMessage', + params + }; + // Create resolver to wait for response + const resolver = new Resolver(); + // Enqueue the request + await this.queue.enqueueWithResolver(this.taskId, jsonrpcRequest, resolver, requestId); + try { + // Wait for response + const response = await resolver.wait(); + // Update status back to working + await this.store.updateTaskStatus(this.taskId, 'working'); + return response; + } + catch (error) { + await this.store.updateTaskStatus(this.taskId, 'working'); + throw error; + } + } +} +// ============================================================================ +// Server Setup +// ============================================================================ +const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 8000; +// Create shared stores +const taskStore = new TaskStoreWithNotifications(); +const messageQueue = new TaskMessageQueueWithResolvers(); +const taskResultHandler = new TaskResultHandler(taskStore, messageQueue); +// Track active task executions +const activeTaskExecutions = new Map(); +// Create the server +const createServer = () => { + const server = new Server({ name: 'simple-task-interactive', version: '1.0.0' }, { + capabilities: { + tools: {}, + tasks: { + requests: { + tools: { call: {} } + } + } + } + }); + // Register tools + server.setRequestHandler(ListToolsRequestSchema, async () => { + return { + tools: [ + { + name: 'confirm_delete', + description: 'Asks for confirmation before deleting (demonstrates elicitation)', + inputSchema: { + type: 'object', + properties: { + filename: { type: 'string' } + } + }, + execution: { taskSupport: 'required' } + }, + { + name: 'write_haiku', + description: 'Asks LLM to write a haiku (demonstrates sampling)', + inputSchema: { + type: 'object', + properties: { + topic: { type: 'string' } + } + }, + execution: { taskSupport: 'required' } + } + ] + }; + }); + // Handle tool calls + server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { + var _a, _b, _c; + const { name, arguments: args } = request.params; + const taskParams = (((_a = request.params._meta) === null || _a === void 0 ? void 0 : _a.task) || request.params.task); + // Validate task mode - these tools require tasks + if (!taskParams) { + throw new Error(`Tool ${name} requires task mode`); + } + // Create task + const taskOptions = { + ttl: taskParams.ttl, + pollInterval: (_b = taskParams.pollInterval) !== null && _b !== void 0 ? _b : 1000 + }; + const task = await taskStore.createTask(taskOptions, extra.requestId, request, extra.sessionId); + console.log(`\n[Server] ${name} called, task created: ${task.taskId}`); + // Start background task execution + const taskExecution = (async () => { + var _a, _b; + try { + const taskSession = new TaskSession(server, task.taskId, taskStore, messageQueue); + if (name === 'confirm_delete') { + const filename = (_a = args === null || args === void 0 ? void 0 : args.filename) !== null && _a !== void 0 ? _a : 'unknown.txt'; + console.log(`[Server] confirm_delete: asking about '${filename}'`); + console.log('[Server] Sending elicitation request to client...'); + const result = await taskSession.elicit(`Are you sure you want to delete '${filename}'?`, { + type: 'object', + properties: { + confirm: { type: 'boolean' } + }, + required: ['confirm'] + }); + console.log(`[Server] Received elicitation response: action=${result.action}, content=${JSON.stringify(result.content)}`); + let text; + if (result.action === 'accept' && result.content) { + const confirmed = result.content.confirm; + text = confirmed ? `Deleted '${filename}'` : 'Deletion cancelled'; + } + else { + text = 'Deletion cancelled'; + } + console.log(`[Server] Completing task with result: ${text}`); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [{ type: 'text', text }] + }); + } + else if (name === 'write_haiku') { + const topic = (_b = args === null || args === void 0 ? void 0 : args.topic) !== null && _b !== void 0 ? _b : 'nature'; + console.log(`[Server] write_haiku: topic '${topic}'`); + console.log('[Server] Sending sampling request to client...'); + const result = await taskSession.createMessage([ + { + role: 'user', + content: { type: 'text', text: `Write a haiku about ${topic}` } + } + ], 50); + let haiku = 'No response'; + if (result.content && 'text' in result.content) { + haiku = result.content.text; + } + console.log(`[Server] Received sampling response: ${haiku.substring(0, 50)}...`); + console.log('[Server] Completing task with haiku'); + await taskStore.storeTaskResult(task.taskId, 'completed', { + content: [{ type: 'text', text: `Haiku:\n${haiku}` }] + }); + } + } + catch (error) { + console.error(`[Server] Task ${task.taskId} failed:`, error); + await taskStore.storeTaskResult(task.taskId, 'failed', { + content: [{ type: 'text', text: `Error: ${error}` }], + isError: true + }); + } + finally { + activeTaskExecutions.delete(task.taskId); + } + })(); + activeTaskExecutions.set(task.taskId, { + promise: taskExecution, + server, + sessionId: (_c = extra.sessionId) !== null && _c !== void 0 ? _c : '' + }); + return { task }; + }); + // Handle tasks/get + server.setRequestHandler(GetTaskRequestSchema, async (request) => { + const { taskId } = request.params; + const task = await taskStore.getTask(taskId); + if (!task) { + throw new Error(`Task ${taskId} not found`); + } + return task; + }); + // Handle tasks/result + server.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => { + var _a; + const { taskId } = request.params; + console.log(`[Server] tasks/result called for task ${taskId}`); + return taskResultHandler.handle(taskId, server, (_a = extra.sessionId) !== null && _a !== void 0 ? _a : ''); + }); + return server; +}; +// ============================================================================ +// Express App Setup +// ============================================================================ +const app = express(); +app.use(express.json()); +// Map to store transports by session ID +const transports = {}; +// Helper to check if request is initialize +const isInitializeRequest = (body) => { + return typeof body === 'object' && body !== null && 'method' in body && body.method === 'initialize'; +}; +// MCP POST endpoint +app.post('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + try { + let transport; + if (sessionId && transports[sessionId]) { + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + onsessioninitialized: sid => { + console.log(`Session initialized: ${sid}`); + transports[sid] = transport; + } + }); + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}`); + delete transports[sid]; + } + }; + const server = createServer(); + await server.connect(transport); + await transport.handleRequest(req, res, req.body); + return; + } + else { + res.status(400).json({ + jsonrpc: '2.0', + error: { code: -32000, message: 'Bad Request: No valid session ID' }, + id: null + }); + return; + } + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { code: -32603, message: 'Internal server error' }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams +app.get('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Handle DELETE requests for session termination +app.delete('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Session termination request: ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Start server +app.listen(PORT, () => { + console.log(`Starting server on http://localhost:${PORT}/mcp`); + console.log('\nAvailable tools:'); + console.log(' - confirm_delete: Demonstrates elicitation (asks user y/n)'); + console.log(' - write_haiku: Demonstrates sampling (requests LLM completion)'); +}); +// Handle shutdown +process.on('SIGINT', async () => { + console.log('\nShutting down server...'); + for (const sessionId of Object.keys(transports)) { + try { + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing session ${sessionId}:`, error); + } + } + taskStore.cleanup(); + messageQueue.cleanup(); + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=simpleTaskInteractive.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/simpleTaskInteractive.js.map b/dist/esm/examples/server/simpleTaskInteractive.js.map new file mode 100644 index 000000000..337503bdb --- /dev/null +++ b/dist/esm/examples/server/simpleTaskInteractive.js.map @@ -0,0 +1 @@ +{"version":3,"file":"simpleTaskInteractive.js","sourceRoot":"","sources":["../../../../src/examples/server/simpleTaskInteractive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAMH,qBAAqB,EAWrB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAkD,UAAU,EAAqB,MAAM,wCAAwC,CAAC;AACvI,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAEjF,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAE/E,MAAM,QAAQ;IAMV;QAFQ,UAAK,GAAG,KAAK,CAAC;QAGlB,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,KAAQ;QACd,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,CAAC,KA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AAyB,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAChE,CAAC;IACL,CAAC;IACD,SAAS,CAAC,OAAO,EAAE,CAAC;IACpB,YAAY,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts new file mode 100644 index 000000000..c536d0c80 --- /dev/null +++ b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=sseAndStreamableHttpCompatibleServer.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map new file mode 100644 index 000000000..fb982c84a --- /dev/null +++ b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sseAndStreamableHttpCompatibleServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/sseAndStreamableHttpCompatibleServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js new file mode 100644 index 000000000..3385fac2d --- /dev/null +++ b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js @@ -0,0 +1,235 @@ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { SSEServerTransport } from '../../server/sse.js'; +import * as z from 'zod/v4'; +import { isInitializeRequest } from '../../types.js'; +import { InMemoryEventStore } from '../shared/inMemoryEventStore.js'; +import cors from 'cors'; +/** + * This example server demonstrates backwards compatibility with both: + * 1. The deprecated HTTP+SSE transport (protocol version 2024-11-05) + * 2. The Streamable HTTP transport (protocol version 2025-03-26) + * + * It maintains a single MCP server instance but exposes two transport options: + * - /mcp: The new Streamable HTTP endpoint (supports GET/POST/DELETE) + * - /sse: The deprecated SSE endpoint for older clients (GET to establish stream) + * - /messages: The deprecated POST endpoint for older clients (POST to send messages) + */ +const getServer = () => { + const server = new McpServer({ + name: 'backwards-compatible-server', + version: '1.0.0' + }, { capabilities: { logging: {} } }); + // Register a simple tool that sends notifications over time + server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', { + interval: z.number().describe('Interval in milliseconds between notifications').default(100), + count: z.number().describe('Number of notifications to send (0 for 100)').default(50) + }, async ({ interval, count }, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + let counter = 0; + while (count === 0 || counter < count) { + counter++; + try { + await server.sendLoggingMessage({ + level: 'info', + data: `Periodic notification #${counter} at ${new Date().toISOString()}` + }, extra.sessionId); + } + catch (error) { + console.error('Error sending notification:', error); + } + // Wait for the specified interval + await sleep(interval); + } + return { + content: [ + { + type: 'text', + text: `Started sending periodic notifications every ${interval}ms` + } + ] + }; + }); + return server; +}; +// Create Express application +const app = express(); +app.use(express.json()); +// Configure CORS to expose Mcp-Session-Id header for browser-based clients +app.use(cors({ + origin: '*', // Allow all origins - adjust as needed for production + exposedHeaders: ['Mcp-Session-Id'] +})); +// Store transports by session ID +const transports = {}; +//============================================================================= +// STREAMABLE HTTP TRANSPORT (PROTOCOL VERSION 2025-03-26) +//============================================================================= +// Handle all MCP Streamable HTTP requests (GET, POST, DELETE) on a single endpoint +app.all('/mcp', async (req, res) => { + console.log(`Received ${req.method} request to /mcp`); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Check if the transport is of the correct type + const existingTransport = transports[sessionId]; + if (existingTransport instanceof StreamableHTTPServerTransport) { + // Reuse existing transport + transport = existingTransport; + } + else { + // Transport exists but is not a StreamableHTTPServerTransport (could be SSEServerTransport) + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Session exists but uses a different transport protocol' + }, + id: null + }); + return; + } + } + else if (!sessionId && req.method === 'POST' && isInitializeRequest(req.body)) { + const eventStore = new InMemoryEventStore(); + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + eventStore, // Enable resumability + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + console.log(`StreamableHTTP session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Set up onclose handler to clean up transport when closed + transport.onclose = () => { + const sid = transport.sessionId; + if (sid && transports[sid]) { + console.log(`Transport closed for session ${sid}, removing from transports map`); + delete transports[sid]; + } + }; + // Connect the transport to the MCP server + const server = getServer(); + await server.connect(transport); + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with the transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +//============================================================================= +// DEPRECATED HTTP+SSE TRANSPORT (PROTOCOL VERSION 2024-11-05) +//============================================================================= +app.get('/sse', async (req, res) => { + console.log('Received GET request to /sse (deprecated SSE transport)'); + const transport = new SSEServerTransport('/messages', res); + transports[transport.sessionId] = transport; + res.on('close', () => { + delete transports[transport.sessionId]; + }); + const server = getServer(); + await server.connect(transport); +}); +app.post('/messages', async (req, res) => { + const sessionId = req.query.sessionId; + let transport; + const existingTransport = transports[sessionId]; + if (existingTransport instanceof SSEServerTransport) { + // Reuse existing transport + transport = existingTransport; + } + else { + // Transport exists but is not a SSEServerTransport (could be StreamableHTTPServerTransport) + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Session exists but uses a different transport protocol' + }, + id: null + }); + return; + } + if (transport) { + await transport.handlePostMessage(req, res, req.body); + } + else { + res.status(400).send('No transport found for sessionId'); + } +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Backwards compatible MCP server listening on port ${PORT}`); + console.log(` +============================================== +SUPPORTED TRANSPORT OPTIONS: + +1. Streamable Http(Protocol version: 2025-03-26) + Endpoint: /mcp + Methods: GET, POST, DELETE + Usage: + - Initialize with POST to /mcp + - Establish SSE stream with GET to /mcp + - Send requests with POST to /mcp + - Terminate session with DELETE to /mcp + +2. Http + SSE (Protocol version: 2024-11-05) + Endpoints: /sse (GET) and /messages (POST) + Usage: + - Establish SSE stream with GET to /sse + - Send requests with POST to /messages?sessionId= +============================================== +`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + // Close all active transports to properly clean up resources + for (const sessionId in transports) { + try { + console.log(`Closing transport for session ${sessionId}`); + await transports[sessionId].close(); + delete transports[sessionId]; + } + catch (error) { + console.error(`Error closing transport for session ${sessionId}:`, error); + } + } + console.log('Server shutdown complete'); + process.exit(0); +}); +//# sourceMappingURL=sseAndStreamableHttpCompatibleServer.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js.map b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js.map new file mode 100644 index 000000000..f854fbcd6 --- /dev/null +++ b/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sseAndStreamableHttpCompatibleServer.js","sourceRoot":"","sources":["../../../../src/examples/server/sseAndStreamableHttpCompatibleServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAA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,EAAE,KAAK,CAAC,EAAE;IACrB,IAAI,KAAK,EAAE,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,qDAAqD,IAAI,EAAE,CAAC,CAAC;IACzE,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;CAmBf,CAAC,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;YAC1D,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uCAAuC,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/ssePollingExample.d.ts b/dist/esm/examples/server/ssePollingExample.d.ts new file mode 100644 index 000000000..63e45548e --- /dev/null +++ b/dist/esm/examples/server/ssePollingExample.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=ssePollingExample.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/ssePollingExample.d.ts.map b/dist/esm/examples/server/ssePollingExample.d.ts.map new file mode 100644 index 000000000..93827316a --- /dev/null +++ b/dist/esm/examples/server/ssePollingExample.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ssePollingExample.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/ssePollingExample.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/ssePollingExample.js b/dist/esm/examples/server/ssePollingExample.js new file mode 100644 index 000000000..a6c04a787 --- /dev/null +++ b/dist/esm/examples/server/ssePollingExample.js @@ -0,0 +1,111 @@ +/** + * SSE Polling Example Server (SEP-1699) + * + * This example demonstrates server-initiated SSE stream disconnection + * and client reconnection with Last-Event-ID for resumability. + * + * Key features: + * - Configures `retryInterval` to tell clients how long to wait before reconnecting + * - Uses `eventStore` to persist events for replay after reconnection + * - Calls `closeSSEStream()` to gracefully disconnect clients mid-operation + * + * Run with: npx tsx src/examples/server/ssePollingExample.ts + * Test with: curl or the MCP Inspector + */ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { InMemoryEventStore } from '../shared/inMemoryEventStore.js'; +import cors from 'cors'; +// Create the MCP server +const server = new McpServer({ + name: 'sse-polling-example', + version: '1.0.0' +}, { + capabilities: { logging: {} } +}); +// Track active transports by session ID for closeSSEStream access +const transports = new Map(); +// Register a long-running tool that demonstrates server-initiated disconnect +server.tool('long-task', 'A long-running task that sends progress updates. Server will disconnect mid-task to demonstrate polling.', {}, async (_args, extra) => { + const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + console.log(`[${extra.sessionId}] Starting long-task...`); + // Send first progress notification + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 25% - Starting work...' + }, extra.sessionId); + await sleep(1000); + // Send second progress notification + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 50% - Halfway there...' + }, extra.sessionId); + await sleep(1000); + // Server decides to disconnect the client to free resources + // Client will reconnect via GET with Last-Event-ID after retryInterval + const transport = transports.get(extra.sessionId); + if (transport) { + console.log(`[${extra.sessionId}] Closing SSE stream to trigger client polling...`); + transport.closeSSEStream(extra.requestId); + } + // Continue processing while client is disconnected + // Events are stored in eventStore and will be replayed on reconnect + await sleep(500); + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 75% - Almost done (sent while client disconnected)...' + }, extra.sessionId); + await sleep(500); + await server.sendLoggingMessage({ + level: 'info', + data: 'Progress: 100% - Complete!' + }, extra.sessionId); + console.log(`[${extra.sessionId}] Task complete`); + return { + content: [ + { + type: 'text', + text: 'Long task completed successfully!' + } + ] + }; +}); +// Set up Express app +const app = express(); +app.use(cors()); +// Create event store for resumability +const eventStore = new InMemoryEventStore(); +// Handle all MCP requests - use express.json() only for this route +app.all('/mcp', express.json(), async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + // Reuse existing transport or create new one + let transport = sessionId ? transports.get(sessionId) : undefined; + if (!transport) { + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + eventStore, + retryInterval: 2000, // Client should reconnect after 2 seconds + onsessioninitialized: id => { + console.log(`[${id}] Session initialized`); + transports.set(id, transport); + } + }); + // Connect the MCP server to the transport + await server.connect(transport); + } + await transport.handleRequest(req, res, req.body); +}); +// Start the server +const PORT = 3001; +app.listen(PORT, () => { + console.log(`SSE Polling Example Server running on http://localhost:${PORT}/mcp`); + console.log(''); + console.log('This server demonstrates SEP-1699 SSE polling:'); + console.log('- retryInterval: 2000ms (client waits 2s before reconnecting)'); + console.log('- eventStore: InMemoryEventStore (events are persisted for replay)'); + console.log(''); + console.log('Try calling the "long-task" tool to see server-initiated disconnect in action.'); +}); +//# sourceMappingURL=ssePollingExample.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/ssePollingExample.js.map b/dist/esm/examples/server/ssePollingExample.js.map new file mode 100644 index 000000000..00316a544 --- /dev/null +++ b/dist/esm/examples/server/ssePollingExample.js.map @@ -0,0 +1 @@ +{"version":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CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,gFAAgF,CAAC,CAAC;AAClG,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts new file mode 100644 index 000000000..4df17831b --- /dev/null +++ b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=standaloneSseWithGetStreamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map new file mode 100644 index 000000000..df60dc51b --- /dev/null +++ b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"standaloneSseWithGetStreamableHttp.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/standaloneSseWithGetStreamableHttp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js new file mode 100644 index 000000000..b67302c96 --- /dev/null +++ b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js @@ -0,0 +1,111 @@ +import express from 'express'; +import { randomUUID } from 'node:crypto'; +import { McpServer } from '../../server/mcp.js'; +import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js'; +import { isInitializeRequest } from '../../types.js'; +// Create an MCP server with implementation details +const server = new McpServer({ + name: 'resource-list-changed-notification-server', + version: '1.0.0' +}); +// Store transports by session ID to send notifications +const transports = {}; +const addResource = (name, content) => { + const uri = `https://mcp-example.com/dynamic/${encodeURIComponent(name)}`; + server.resource(name, uri, { mimeType: 'text/plain', description: `Dynamic resource: ${name}` }, async () => { + return { + contents: [{ uri, text: content }] + }; + }); +}; +addResource('example-resource', 'Initial content for example-resource'); +const resourceChangeInterval = setInterval(() => { + const name = randomUUID(); + addResource(name, `Content for ${name}`); +}, 5000); // Change resources every 5 seconds for testing +const app = express(); +app.use(express.json()); +app.post('/mcp', async (req, res) => { + console.log('Received MCP request:', req.body); + try { + // Check for existing session ID + const sessionId = req.headers['mcp-session-id']; + let transport; + if (sessionId && transports[sessionId]) { + // Reuse existing transport + transport = transports[sessionId]; + } + else if (!sessionId && isInitializeRequest(req.body)) { + // New initialization request + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + onsessioninitialized: sessionId => { + // Store the transport by session ID when session is initialized + // This avoids race conditions where requests might come in before the session is stored + console.log(`Session initialized with ID: ${sessionId}`); + transports[sessionId] = transport; + } + }); + // Connect the transport to the MCP server + await server.connect(transport); + // Handle the request - the onsessioninitialized callback will store the transport + await transport.handleRequest(req, res, req.body); + return; // Already handled + } + else { + // Invalid request - no session ID or not initialization request + res.status(400).json({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: No valid session ID provided' + }, + id: null + }); + return; + } + // Handle the request with existing transport + await transport.handleRequest(req, res, req.body); + } + catch (error) { + console.error('Error handling MCP request:', error); + if (!res.headersSent) { + res.status(500).json({ + jsonrpc: '2.0', + error: { + code: -32603, + message: 'Internal server error' + }, + id: null + }); + } + } +}); +// Handle GET requests for SSE streams (now using built-in support from StreamableHTTP) +app.get('/mcp', async (req, res) => { + const sessionId = req.headers['mcp-session-id']; + if (!sessionId || !transports[sessionId]) { + res.status(400).send('Invalid or missing session ID'); + return; + } + console.log(`Establishing SSE stream for session ${sessionId}`); + const transport = transports[sessionId]; + await transport.handleRequest(req, res); +}); +// Start the server +const PORT = 3000; +app.listen(PORT, error => { + if (error) { + console.error('Failed to start server:', error); + process.exit(1); + } + console.log(`Server listening on port ${PORT}`); +}); +// Handle server shutdown +process.on('SIGINT', async () => { + console.log('Shutting down server...'); + clearInterval(resourceChangeInterval); + await server.close(); + process.exit(0); +}); +//# sourceMappingURL=standaloneSseWithGetStreamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js.map b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js.map new file mode 100644 index 000000000..8caa419a8 --- /dev/null +++ b/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"standaloneSseWithGetStreamableHttp.js","sourceRoot":"","sources":["../../../../src/examples/server/standaloneSseWithGetStreamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAsB,MAAM,gBAAgB,CAAC;AAEzE,mDAAmD;AACnD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IACzB,IAAI,EAAE,2CAA2C;IACjD,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAEH,uDAAuD;AACvD,MAAM,UAAU,GAA2D,EAAE,CAAC;AAE9E,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,EAAE;IAClD,MAAM,GAAG,GAAG,mCAAmC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1E,MAAM,CAAC,QAAQ,CACX,IAAI,EACJ,GAAG,EACH,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,IAAI,EAAE,EAAE,EACpE,KAAK,IAAiC,EAAE;QACpC,OAAO;YACH,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;SACrC,CAAC;IACN,CAAC,CACJ,CAAC;AACN,CAAC,CAAC;AAEF,WAAW,CAAC,kBAAkB,EAAE,sCAAsC,CAAC,CAAC;AAExE,MAAM,sBAAsB,GAAG,WAAW,CAAC,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AAuC,SAAS,EAAE,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;IACrB,IAAI,KAAK,EAAE,CAAC;QACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACtC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/server/toolWithSampleServer.d.ts b/dist/esm/examples/server/toolWithSampleServer.d.ts new file mode 100644 index 000000000..acc24b6a5 --- /dev/null +++ b/dist/esm/examples/server/toolWithSampleServer.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=toolWithSampleServer.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/server/toolWithSampleServer.d.ts.map b/dist/esm/examples/server/toolWithSampleServer.d.ts.map new file mode 100644 index 000000000..bd0cebcf1 --- /dev/null +++ b/dist/esm/examples/server/toolWithSampleServer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"toolWithSampleServer.d.ts","sourceRoot":"","sources":["../../../../src/examples/server/toolWithSampleServer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/examples/server/toolWithSampleServer.js b/dist/esm/examples/server/toolWithSampleServer.js new file mode 100644 index 000000000..326a288cd --- /dev/null +++ b/dist/esm/examples/server/toolWithSampleServer.js @@ -0,0 +1,46 @@ +// Run with: npx tsx src/examples/server/toolWithSampleServer.ts +import { McpServer } from '../../server/mcp.js'; +import { StdioServerTransport } from '../../server/stdio.js'; +import * as z from 'zod/v4'; +const mcpServer = new McpServer({ + name: 'tools-with-sample-server', + version: '1.0.0' +}); +// Tool that uses LLM sampling to summarize any text +mcpServer.registerTool('summarize', { + description: 'Summarize any text using an LLM', + inputSchema: { + text: z.string().describe('Text to summarize') + } +}, async ({ text }) => { + // Call the LLM through MCP sampling + const response = await mcpServer.server.createMessage({ + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please summarize the following text concisely:\n\n${text}` + } + } + ], + maxTokens: 500 + }); + const contents = Array.isArray(response.content) ? response.content : [response.content]; + return { + content: contents.map(content => ({ + type: 'text', + text: content.type === 'text' ? content.text : 'Unable to generate summary' + })) + }; +}); +async function main() { + const transport = new StdioServerTransport(); + await mcpServer.connect(transport); + console.log('MCP server is running...'); +} +main().catch(error => { + console.error('Server error:', error); + process.exit(1); +}); +//# sourceMappingURL=toolWithSampleServer.js.map \ No newline at end of file diff --git a/dist/esm/examples/server/toolWithSampleServer.js.map b/dist/esm/examples/server/toolWithSampleServer.js.map new file mode 100644 index 000000000..f4fb4337e --- /dev/null +++ b/dist/esm/examples/server/toolWithSampleServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"toolWithSampleServer.js","sourceRoot":"","sources":["../../../../src/examples/server/toolWithSampleServer.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,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AAG,CAAC,0BAA0B,CAAC,CAAC;AAC5C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/examples/shared/inMemoryEventStore.d.ts b/dist/esm/examples/shared/inMemoryEventStore.d.ts new file mode 100644 index 000000000..26ff38cf9 --- /dev/null +++ b/dist/esm/examples/shared/inMemoryEventStore.d.ts @@ -0,0 +1,31 @@ +import { JSONRPCMessage } from '../../types.js'; +import { EventStore } from '../../server/streamableHttp.js'; +/** + * Simple in-memory implementation of the EventStore interface for resumability + * This is primarily intended for examples and testing, not for production use + * where a persistent storage solution would be more appropriate. + */ +export declare class InMemoryEventStore implements EventStore { + private events; + /** + * Generates a unique event ID for a given stream ID + */ + private generateEventId; + /** + * Extracts the stream ID from an event ID + */ + private getStreamIdFromEventId; + /** + * Stores an event with a generated event ID + * Implements EventStore.storeEvent + */ + storeEvent(streamId: string, message: JSONRPCMessage): Promise; + /** + * Replays events that occurred after a specific event ID + * Implements EventStore.replayEventsAfter + */ + replayEventsAfter(lastEventId: string, { send }: { + send: (eventId: string, message: JSONRPCMessage) => Promise; + }): Promise; +} +//# sourceMappingURL=inMemoryEventStore.d.ts.map \ No newline at end of file diff --git a/dist/esm/examples/shared/inMemoryEventStore.d.ts.map b/dist/esm/examples/shared/inMemoryEventStore.d.ts.map new file mode 100644 index 000000000..a67ee6cd1 --- /dev/null +++ b/dist/esm/examples/shared/inMemoryEventStore.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemoryEventStore.d.ts","sourceRoot":"","sources":["../../../../src/examples/shared/inMemoryEventStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACjD,OAAO,CAAC,MAAM,CAAyE;IAEvF;;OAEG;IACH,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAK9B;;;OAGG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAM5E;;;OAGG;IACG,iBAAiB,CACnB,WAAW,EAAE,MAAM,EACnB,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,GAChF,OAAO,CAAC,MAAM,CAAC;CAkCrB"} \ No newline at end of file diff --git a/dist/esm/examples/shared/inMemoryEventStore.js b/dist/esm/examples/shared/inMemoryEventStore.js new file mode 100644 index 000000000..35f6dbb7c --- /dev/null +++ b/dist/esm/examples/shared/inMemoryEventStore.js @@ -0,0 +1,65 @@ +/** + * Simple in-memory implementation of the EventStore interface for resumability + * This is primarily intended for examples and testing, not for production use + * where a persistent storage solution would be more appropriate. + */ +export class InMemoryEventStore { + constructor() { + this.events = new Map(); + } + /** + * Generates a unique event ID for a given stream ID + */ + generateEventId(streamId) { + return `${streamId}_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`; + } + /** + * Extracts the stream ID from an event ID + */ + getStreamIdFromEventId(eventId) { + const parts = eventId.split('_'); + return parts.length > 0 ? parts[0] : ''; + } + /** + * Stores an event with a generated event ID + * Implements EventStore.storeEvent + */ + async storeEvent(streamId, message) { + const eventId = this.generateEventId(streamId); + this.events.set(eventId, { streamId, message }); + return eventId; + } + /** + * Replays events that occurred after a specific event ID + * Implements EventStore.replayEventsAfter + */ + async replayEventsAfter(lastEventId, { send }) { + if (!lastEventId || !this.events.has(lastEventId)) { + return ''; + } + // Extract the stream ID from the event ID + const streamId = this.getStreamIdFromEventId(lastEventId); + if (!streamId) { + return ''; + } + let foundLastEvent = false; + // Sort events by eventId for chronological ordering + const sortedEvents = [...this.events.entries()].sort((a, b) => a[0].localeCompare(b[0])); + for (const [eventId, { streamId: eventStreamId, message }] of sortedEvents) { + // Only include events from the same stream + if (eventStreamId !== streamId) { + continue; + } + // Start sending events after we find the lastEventId + if (eventId === lastEventId) { + foundLastEvent = true; + continue; + } + if (foundLastEvent) { + await send(eventId, message); + } + } + return streamId; + } +} +//# sourceMappingURL=inMemoryEventStore.js.map \ No newline at end of file diff --git a/dist/esm/examples/shared/inMemoryEventStore.js.map b/dist/esm/examples/shared/inMemoryEventStore.js.map new file mode 100644 index 000000000..b9e6af66a --- /dev/null +++ b/dist/esm/examples/shared/inMemoryEventStore.js.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemoryEventStore.js","sourceRoot":"","sources":["../../../../src/examples/shared/inMemoryEventStore.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAA/B;QACY,WAAM,GAA+D,IAAI,GAAG,EAAE,CAAC;IAoE3F,CAAC;IAlEG;;OAEG;IACK,eAAe,CAAC,QAAgB;QACpC,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IACtF,CAAC;IAED;;OAEG;IACK,sBAAsB,CAAC,OAAe;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,QAAgB,EAAE,OAAuB;QACtD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C,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/experimental/index.d.ts b/dist/esm/experimental/index.d.ts new file mode 100644 index 000000000..2a8633553 --- /dev/null +++ b/dist/esm/experimental/index.d.ts @@ -0,0 +1,13 @@ +/** + * Experimental MCP SDK features. + * WARNING: These APIs are experimental and may change without notice. + * + * Import experimental features from this module: + * ```typescript + * import { TaskStore, InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental'; + * ``` + * + * @experimental + */ +export * from './tasks/index.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/index.d.ts.map b/dist/esm/experimental/index.d.ts.map new file mode 100644 index 000000000..410892aa4 --- /dev/null +++ b/dist/esm/experimental/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kBAAkB,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/index.js b/dist/esm/experimental/index.js new file mode 100644 index 000000000..650f4e478 --- /dev/null +++ b/dist/esm/experimental/index.js @@ -0,0 +1,13 @@ +/** + * Experimental MCP SDK features. + * WARNING: These APIs are experimental and may change without notice. + * + * Import experimental features from this module: + * ```typescript + * import { TaskStore, InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental'; + * ``` + * + * @experimental + */ +export * from './tasks/index.js'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/experimental/index.js.map b/dist/esm/experimental/index.js.map new file mode 100644 index 000000000..3639685bd --- /dev/null +++ b/dist/esm/experimental/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,kBAAkB,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/client.d.ts b/dist/esm/experimental/tasks/client.d.ts new file mode 100644 index 000000000..9c7a92834 --- /dev/null +++ b/dist/esm/experimental/tasks/client.d.ts @@ -0,0 +1,121 @@ +/** + * Experimental client task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { Client } from '../../client/index.js'; +import type { RequestOptions } from '../../shared/protocol.js'; +import type { ResponseMessage } from '../../shared/responseMessage.js'; +import type { AnyObjectSchema, SchemaOutput } from '../../server/zod-compat.js'; +import type { CallToolRequest, ClientRequest, Notification, Request, Result } from '../../types.js'; +import { CallToolResultSchema, type CompatibilityCallToolResultSchema } from '../../types.js'; +import type { GetTaskResult, ListTasksResult, CancelTaskResult } from './types.js'; +/** + * Experimental task features for MCP clients. + * + * Access via `client.experimental.tasks`: + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'tool', arguments: {} }); + * const task = await client.experimental.tasks.getTask(taskId); + * ``` + * + * @experimental + */ +export declare class ExperimentalClientTasks { + private readonly _client; + constructor(_client: Client); + /** + * Calls a tool and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to tool execution, allowing you to + * observe intermediate task status updates for long-running tool calls. + * Automatically validates structured output if the tool has an outputSchema. + * + * @example + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} }); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Tool execution started:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Tool status:', message.task.status); + * break; + * case 'result': + * console.log('Tool result:', message.result); + * break; + * case 'error': + * console.error('Tool error:', message.error); + * break; + * } + * } + * ``` + * + * @param params - Tool call parameters (name and arguments) + * @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema) + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + callToolStream(params: CallToolRequest['params'], resultSchema?: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + getTask(taskId: string, options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + getTaskResult(taskId: string, resultSchema?: T, options?: RequestOptions): Promise>; + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + listTasks(cursor?: string, options?: RequestOptions): Promise; + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + cancelTask(taskId: string, options?: RequestOptions): Promise; + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request: ClientRequest | RequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; +} +//# sourceMappingURL=client.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/client.d.ts.map b/dist/esm/experimental/tasks/client.d.ts.map new file mode 100644 index 000000000..e54158d65 --- /dev/null +++ b/dist/esm/experimental/tasks/client.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KA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AAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IASpF;;;;;;;OAOG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IASrF;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,CAAC,SAAS,eAAe,EACnC,OAAO,EAAE,aAAa,GAAG,QAAQ,EACjC,YAAY,EAAE,CAAC,EACf,OAAO,CAAC,EAAE,cAAc,GACzB,cAAc,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;CAWlE"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/client.js b/dist/esm/experimental/tasks/client.js new file mode 100644 index 000000000..3bbe2788a --- /dev/null +++ b/dist/esm/experimental/tasks/client.js @@ -0,0 +1,185 @@ +/** + * Experimental client task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import { CallToolResultSchema, McpError, ErrorCode } from '../../types.js'; +/** + * Experimental task features for MCP clients. + * + * Access via `client.experimental.tasks`: + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'tool', arguments: {} }); + * const task = await client.experimental.tasks.getTask(taskId); + * ``` + * + * @experimental + */ +export class ExperimentalClientTasks { + constructor(_client) { + this._client = _client; + } + /** + * Calls a tool and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to tool execution, allowing you to + * observe intermediate task status updates for long-running tool calls. + * Automatically validates structured output if the tool has an outputSchema. + * + * @example + * ```typescript + * const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} }); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Tool execution started:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Tool status:', message.task.status); + * break; + * case 'result': + * console.log('Tool result:', message.result); + * break; + * case 'error': + * console.error('Tool error:', message.error); + * break; + * } + * } + * ``` + * + * @param params - Tool call parameters (name and arguments) + * @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema) + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + async *callToolStream(params, resultSchema = CallToolResultSchema, options) { + var _a; + // Access Client's internal methods + const clientInternal = this._client; + // Add task creation parameters if server supports it and not explicitly provided + const optionsWithTask = { + ...options, + // We check if the tool is known to be a task during auto-configuration, but assume + // the caller knows what they're doing if they pass this explicitly + task: (_a = options === null || options === void 0 ? void 0 : options.task) !== null && _a !== void 0 ? _a : (clientInternal.isToolTask(params.name) ? {} : undefined) + }; + const stream = clientInternal.requestStream({ method: 'tools/call', params }, resultSchema, optionsWithTask); + // Get the validator for this tool (if it has an output schema) + const validator = clientInternal.getToolOutputValidator(params.name); + // Iterate through the stream and validate the final result if needed + for await (const message of stream) { + // If this is a result message and the tool has an output schema, validate it + if (message.type === 'result' && validator) { + const result = message.result; + // If tool has outputSchema, it MUST return structuredContent (unless it's an error) + if (!result.structuredContent && !result.isError) { + yield { + type: 'error', + error: new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`) + }; + return; + } + // Only validate structured content if present (not when there's an error) + if (result.structuredContent) { + try { + // Validate the structured content against the schema + const validationResult = validator(result.structuredContent); + if (!validationResult.valid) { + yield { + type: 'error', + error: new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`) + }; + return; + } + } + catch (error) { + if (error instanceof McpError) { + yield { type: 'error', error }; + return; + } + yield { + type: 'error', + error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`) + }; + return; + } + } + } + // Yield the message (either validated result or any other message type) + yield message; + } + } + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + async getTask(taskId, options) { + return this._client.getTask({ taskId }, options); + } + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + async getTaskResult(taskId, resultSchema, options) { + // Delegate to the client's underlying Protocol method + return this._client.getTaskResult({ taskId }, resultSchema, options); + } + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + async listTasks(cursor, options) { + // Delegate to the client's underlying Protocol method + return this._client.listTasks(cursor ? { cursor } : undefined, options); + } + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + async cancelTask(taskId, options) { + // Delegate to the client's underlying Protocol method + return this._client.cancelTask({ taskId }, options); + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request, resultSchema, options) { + return this._client.requestStream(request, resultSchema, options); + } +} +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/client.js.map b/dist/esm/experimental/tasks/client.js.map new file mode 100644 index 000000000..b7500e98d --- /dev/null +++ b/dist/esm/experimental/tasks/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAE,oBAAoB,EAA0C,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAkBnH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IAKhC,YAA6B,OAAiD;QAAjD,YAAO,GAAP,OAAO,CAA0C;IAAG,CA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IACvD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,CAAC,MAAe,EAAE,OAAwB;QACrD,sDAAsD;QACtD,OACI,IAAI,CAAC,OAGR,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,OAAwB;QACrD,sDAAsD;QACtD,OACI,IAAI,CAAC,OAGR,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,aAAa,CACT,OAAiC,EACjC,YAAe,EACf,OAAwB;QAUxB,OAAQ,IAAI,CAAC,OAA8C,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9G,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/helpers.d.ts b/dist/esm/experimental/tasks/helpers.d.ts new file mode 100644 index 000000000..f5e505f81 --- /dev/null +++ b/dist/esm/experimental/tasks/helpers.d.ts @@ -0,0 +1,47 @@ +/** + * Experimental task capability assertion helpers. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +/** + * Type representing the task requests capability structure. + * This is derived from ClientTasksCapability.requests and ServerTasksCapability.requests. + */ +interface TaskRequestsCapability { + tools?: { + call?: object; + }; + sampling?: { + createMessage?: object; + }; + elicitation?: { + create?: object; + }; +} +/** + * Asserts that task creation is supported for tools/call. + * Used by Client.assertTaskCapability and Server.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export declare function assertToolsCallTaskCapability(requests: TaskRequestsCapability | undefined, method: string, entityName: 'Server' | 'Client'): void; +/** + * Asserts that task creation is supported for sampling/createMessage or elicitation/create. + * Used by Server.assertTaskCapability and Client.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export declare function assertClientRequestTaskCapability(requests: TaskRequestsCapability | undefined, method: string, entityName: 'Server' | 'Client'): void; +export {}; +//# sourceMappingURL=helpers.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/helpers.d.ts.map b/dist/esm/experimental/tasks/helpers.d.ts.map new file mode 100644 index 000000000..99dc90343 --- /dev/null +++ b/dist/esm/experimental/tasks/helpers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,UAAU,sBAAsB;IAC5B,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,WAAW,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CACzC,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAChC,IAAI,CAgBN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC7C,QAAQ,EAAE,sBAAsB,GAAG,SAAS,EAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAChC,IAAI,CAsBN"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/helpers.js b/dist/esm/experimental/tasks/helpers.js new file mode 100644 index 000000000..3f8687d7e --- /dev/null +++ b/dist/esm/experimental/tasks/helpers.js @@ -0,0 +1,66 @@ +/** + * Experimental task capability assertion helpers. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +/** + * Asserts that task creation is supported for tools/call. + * Used by Client.assertTaskCapability and Server.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export function assertToolsCallTaskCapability(requests, method, entityName) { + var _a; + if (!requests) { + throw new Error(`${entityName} does not support task creation (required for ${method})`); + } + switch (method) { + case 'tools/call': + if (!((_a = requests.tools) === null || _a === void 0 ? void 0 : _a.call)) { + throw new Error(`${entityName} does not support task creation for tools/call (required for ${method})`); + } + break; + default: + // Method doesn't support tasks, which is fine - no error + break; + } +} +/** + * Asserts that task creation is supported for sampling/createMessage or elicitation/create. + * Used by Server.assertTaskCapability and Client.assertTaskHandlerCapability. + * + * @param requests - The task requests capability object + * @param method - The method being checked + * @param entityName - 'Server' or 'Client' for error messages + * @throws Error if the capability is not supported + * + * @experimental + */ +export function assertClientRequestTaskCapability(requests, method, entityName) { + var _a, _b; + if (!requests) { + throw new Error(`${entityName} does not support task creation (required for ${method})`); + } + switch (method) { + case 'sampling/createMessage': + if (!((_a = requests.sampling) === null || _a === void 0 ? void 0 : _a.createMessage)) { + throw new Error(`${entityName} does not support task creation for sampling/createMessage (required for ${method})`); + } + break; + case 'elicitation/create': + if (!((_b = requests.elicitation) === null || _b === void 0 ? void 0 : _b.create)) { + throw new Error(`${entityName} does not support task creation for elicitation/create (required for ${method})`); + } + break; + default: + // Method doesn't support tasks, which is fine - no error + break; + } +} +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/helpers.js.map b/dist/esm/experimental/tasks/helpers.js.map new file mode 100644 index 000000000..ff93293f5 --- /dev/null +++ b/dist/esm/experimental/tasks/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/helpers.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end of file diff --git a/dist/esm/experimental/tasks/index.d.ts b/dist/esm/experimental/tasks/index.d.ts new file mode 100644 index 000000000..33ab79169 --- /dev/null +++ b/dist/esm/experimental/tasks/index.d.ts @@ -0,0 +1,16 @@ +/** + * Experimental task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +export * from './types.js'; +export * from './interfaces.js'; +export * from './helpers.js'; +export * from './client.js'; +export * from './server.js'; +export * from './mcp-server.js'; +export * from './stores/in-memory.js'; +export type { ResponseMessage, TaskStatusMessage, TaskCreatedMessage, ResultMessage, ErrorMessage, BaseResponseMessage } from '../../shared/responseMessage.js'; +export { takeResult, toArrayAsync } from '../../shared/responseMessage.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/index.d.ts.map b/dist/esm/experimental/tasks/index.d.ts.map new file mode 100644 index 000000000..cf117ed5f --- /dev/null +++ b/dist/esm/experimental/tasks/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,cAAc,CAAC;AAG7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,uBAAuB,CAAC;AAGtC,YAAY,EACR,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/index.js b/dist/esm/experimental/tasks/index.js new file mode 100644 index 000000000..aaa84f511 --- /dev/null +++ b/dist/esm/experimental/tasks/index.js @@ -0,0 +1,20 @@ +/** + * Experimental task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +// Re-export spec types for convenience +export * from './types.js'; +// SDK implementation interfaces +export * from './interfaces.js'; +// Assertion helpers +export * from './helpers.js'; +// Wrapper classes +export * from './client.js'; +export * from './server.js'; +export * from './mcp-server.js'; +// Store implementations +export * from './stores/in-memory.js'; +export { takeResult, toArrayAsync } from '../../shared/responseMessage.js'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/index.js.map b/dist/esm/experimental/tasks/index.js.map new file mode 100644 index 000000000..a01409c78 --- /dev/null +++ b/dist/esm/experimental/tasks/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uCAAuC;AACvC,cAAc,YAAY,CAAC;AAE3B,gCAAgC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,oBAAoB;AACpB,cAAc,cAAc,CAAC;AAE7B,kBAAkB;AAClB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAEhC,wBAAwB;AACxB,cAAc,uBAAuB,CAAC;AAWtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/interfaces.d.ts b/dist/esm/experimental/tasks/interfaces.d.ts new file mode 100644 index 000000000..da0f6f9b8 --- /dev/null +++ b/dist/esm/experimental/tasks/interfaces.d.ts @@ -0,0 +1,232 @@ +/** + * Experimental task interfaces for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + */ +import { Task, Request, RequestId, Result, JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, JSONRPCError, ServerRequest, ServerNotification, CallToolResult, GetTaskResult, ToolExecution } from '../../types.js'; +import { CreateTaskResult } from './types.js'; +import type { RequestHandlerExtra, RequestTaskStore } from '../../shared/protocol.js'; +import type { ZodRawShapeCompat, AnySchema, ShapeOutput } from '../../server/zod-compat.js'; +/** + * Extended handler extra with task store for task creation. + * @experimental + */ +export interface CreateTaskRequestHandlerExtra extends RequestHandlerExtra { + taskStore: RequestTaskStore; +} +/** + * Extended handler extra with task ID and store for task operations. + * @experimental + */ +export interface TaskRequestHandlerExtra extends RequestHandlerExtra { + taskId: string; + taskStore: RequestTaskStore; +} +/** + * Base callback type for tool handlers. + * @experimental + */ +export type BaseToolCallback, Args extends undefined | ZodRawShapeCompat | AnySchema = undefined> = Args extends ZodRawShapeCompat ? (args: ShapeOutput, extra: ExtraT) => SendResultT | Promise : Args extends AnySchema ? (args: unknown, extra: ExtraT) => SendResultT | Promise : (extra: ExtraT) => SendResultT | Promise; +/** + * Handler for creating a task. + * @experimental + */ +export type CreateTaskRequestHandler = BaseToolCallback; +/** + * Handler for task operations (get, getResult). + * @experimental + */ +export type TaskRequestHandler = BaseToolCallback; +/** + * Interface for task-based tool handlers. + * @experimental + */ +export interface ToolTaskHandler { + createTask: CreateTaskRequestHandler; + getTask: TaskRequestHandler; + getTaskResult: TaskRequestHandler; +} +/** + * Task-specific execution configuration. + * taskSupport cannot be 'forbidden' for task-based tools. + * @experimental + */ +export type TaskToolExecution = Omit & { + taskSupport: TaskSupport extends 'forbidden' | undefined ? never : TaskSupport; +}; +/** + * Represents a message queued for side-channel delivery via tasks/result. + * + * This is a serializable data structure that can be stored in external systems. + * All fields are JSON-serializable. + */ +export type QueuedMessage = QueuedRequest | QueuedNotification | QueuedResponse | QueuedError; +export interface BaseQueuedMessage { + /** Type of message */ + type: string; + /** When the message was queued (milliseconds since epoch) */ + timestamp: number; +} +export interface QueuedRequest extends BaseQueuedMessage { + type: 'request'; + /** The actual JSONRPC request */ + message: JSONRPCRequest; +} +export interface QueuedNotification extends BaseQueuedMessage { + type: 'notification'; + /** The actual JSONRPC notification */ + message: JSONRPCNotification; +} +export interface QueuedResponse extends BaseQueuedMessage { + type: 'response'; + /** The actual JSONRPC response */ + message: JSONRPCResponse; +} +export interface QueuedError extends BaseQueuedMessage { + type: 'error'; + /** The actual JSONRPC error */ + message: JSONRPCError; +} +/** + * Interface for managing per-task FIFO message queues. + * + * Similar to TaskStore, this allows pluggable queue implementations + * (in-memory, Redis, other distributed queues, etc.). + * + * Each method accepts taskId and optional sessionId parameters to enable + * a single queue instance to manage messages for multiple tasks, with + * isolation based on task ID and session ID. + * + * All methods are async to support external storage implementations. + * All data in QueuedMessage must be JSON-serializable. + * + * @experimental + */ +export interface TaskMessageQueue { + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + enqueue(taskId: string, message: QueuedMessage, sessionId?: string, maxSize?: number): Promise; + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + dequeue(taskId: string, sessionId?: string): Promise; + /** + * Removes and returns all messages from the queue for a specific task. + * Used when tasks are cancelled or failed to clean up pending messages. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + dequeueAll(taskId: string, sessionId?: string): Promise; +} +/** + * Task creation options. + * @experimental + */ +export interface CreateTaskOptions { + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl?: number | null; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval?: number; + /** + * Additional context to pass to the task store. + */ + context?: Record; +} +/** + * Interface for storing and retrieving task state and results. + * + * Similar to Transport, this allows pluggable task storage implementations + * (in-memory, database, distributed cache, etc.). + * + * @experimental + */ +export interface TaskStore { + /** + * Creates a new task with the given creation parameters and original request. + * The implementation must generate a unique taskId and createdAt timestamp. + * + * TTL Management: + * - The implementation receives the TTL suggested by the requestor via taskParams.ttl + * - The implementation MAY override the requested TTL (e.g., to enforce limits) + * - The actual TTL used MUST be returned in the Task object + * - Null TTL indicates unlimited task lifetime (no automatic cleanup) + * - Cleanup SHOULD occur automatically after TTL expires, regardless of task status + * + * @param taskParams - The task creation parameters from the request (ttl, pollInterval) + * @param requestId - The JSON-RPC request ID + * @param request - The original request that triggered task creation + * @param sessionId - Optional session ID for binding the task to a specific session + * @returns The created task object + */ + createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, sessionId?: string): Promise; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns The task object, or null if it does not exist + */ + getTask(taskId: string, sessionId?: string): Promise; + /** + * Stores the result of a task and sets its final status. + * + * @param taskId - The task identifier + * @param status - The final status: 'completed' for success, 'failed' for errors + * @param result - The result to store + * @param sessionId - Optional session ID for binding the operation to a specific session + */ + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, sessionId?: string): Promise; + /** + * Retrieves the stored result of a task. + * + * @param taskId - The task identifier + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns The stored result + */ + getTaskResult(taskId: string, sessionId?: string): Promise; + /** + * Updates a task's status (e.g., to 'cancelled', 'failed', 'completed'). + * + * @param taskId - The task identifier + * @param status - The new status + * @param statusMessage - Optional diagnostic message for failed tasks or other status information + * @param sessionId - Optional session ID for binding the operation to a specific session + */ + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string, sessionId?: string): Promise; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @param cursor - Optional cursor for pagination + * @param sessionId - Optional session ID for binding the query to a specific session + * @returns An object containing the tasks array and an optional nextCursor + */ + listTasks(cursor?: string, sessionId?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; +} +/** + * Checks if a task status represents a terminal state. + * Terminal states are those where the task has finished and will not change. + * + * @param status - The task status to check + * @returns True if the status is terminal (completed, failed, or cancelled) + * @experimental + */ +export declare function isTerminal(status: Task['status']): boolean; +//# sourceMappingURL=interfaces.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/interfaces.d.ts.map b/dist/esm/experimental/tasks/interfaces.d.ts.map new file mode 100644 index 000000000..9bf002e3d --- /dev/null +++ b/dist/esm/experimental/tasks/interfaces.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,IAAI,EACJ,OAAO,EACP,SAAS,EACT,MAAM,EACN,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,aAAa,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAM5F;;;GAGG;AACH,MAAM,WAAW,6BAA8B,SAAQ,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC;IACzG,SAAS,EAAE,gBAAgB,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC;IACnG,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CACxB,WAAW,SAAS,MAAM,EAC1B,MAAM,SAAS,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,EACrE,IAAI,SAAS,SAAS,GAAG,iBAAiB,GAAG,SAAS,GAAG,SAAS,IAClE,IAAI,SAAS,iBAAiB,GAC5B,CAAC,IAAI,EAAE,WAAW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;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,OAAO,CAE1D"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/interfaces.js b/dist/esm/experimental/tasks/interfaces.js new file mode 100644 index 000000000..d4949de65 --- /dev/null +++ b/dist/esm/experimental/tasks/interfaces.js @@ -0,0 +1,16 @@ +/** + * Experimental task interfaces for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + */ +/** + * Checks if a task status represents a terminal state. + * Terminal states are those where the task has finished and will not change. + * + * @param status - The task status to check + * @returns True if the status is terminal (completed, failed, or cancelled) + * @experimental + */ +export function isTerminal(status) { + return status === 'completed' || status === 'failed' || status === 'cancelled'; +} +//# sourceMappingURL=interfaces.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/interfaces.js.map b/dist/esm/experimental/tasks/interfaces.js.map new file mode 100644 index 000000000..c29899029 --- /dev/null +++ b/dist/esm/experimental/tasks/interfaces.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmRH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC7C,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnF,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/mcp-server.d.ts b/dist/esm/experimental/tasks/mcp-server.d.ts new file mode 100644 index 000000000..b3244f9d6 --- /dev/null +++ b/dist/esm/experimental/tasks/mcp-server.d.ts @@ -0,0 +1,77 @@ +/** + * Experimental McpServer task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { McpServer, RegisteredTool } from '../../server/mcp.js'; +import type { ZodRawShapeCompat, AnySchema } from '../../server/zod-compat.js'; +import type { ToolAnnotations } from '../../types.js'; +import type { ToolTaskHandler, TaskToolExecution } from './interfaces.js'; +/** + * Experimental task features for McpServer. + * + * Access via `server.experimental.tasks`: + * ```typescript + * server.experimental.tasks.registerToolTask('long-running', config, handler); + * ``` + * + * @experimental + */ +export declare class ExperimentalMcpServerTasks { + private readonly _mcpServer; + constructor(_mcpServer: McpServer); + /** + * Registers a task-based tool with a config object and handler. + * + * Task-based tools support long-running operations that can be polled for status + * and results. The handler must implement `createTask`, `getTask`, and `getTaskResult` + * methods. + * + * @example + * ```typescript + * server.experimental.tasks.registerToolTask('long-computation', { + * description: 'Performs a long computation', + * inputSchema: { input: z.string() }, + * execution: { taskSupport: 'required' } + * }, { + * createTask: async (args, extra) => { + * const task = await extra.taskStore.createTask({ ttl: 300000 }); + * startBackgroundWork(task.taskId, args); + * return { task }; + * }, + * getTask: async (args, extra) => { + * return extra.taskStore.getTask(extra.taskId); + * }, + * getTaskResult: async (args, extra) => { + * return extra.taskStore.getTaskResult(extra.taskId); + * } + * }); + * ``` + * + * @param name - The tool name + * @param config - Tool configuration (description, schemas, etc.) + * @param handler - Task handler with createTask, getTask, getTaskResult methods + * @returns RegisteredTool for managing the tool's lifecycle + * + * @experimental + */ + registerToolTask(name: string, config: { + title?: string; + description?: string; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + execution?: TaskToolExecution; + _meta?: Record; + }, handler: ToolTaskHandler): RegisteredTool; + registerToolTask(name: string, config: { + title?: string; + description?: string; + inputSchema: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + execution?: TaskToolExecution; + _meta?: Record; + }, handler: ToolTaskHandler): RegisteredTool; +} +//# sourceMappingURL=mcp-server.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/mcp-server.d.ts.map b/dist/esm/experimental/tasks/mcp-server.d.ts.map new file mode 100644 index 000000000..84ee9e08d --- /dev/null +++ b/dist/esm/experimental/tasks/mcp-server.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","s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AC9B,SAAS,CAAC,EAAE,iBAAiB,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,EACD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GACpC,cAAc;CAsCpB"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/mcp-server.js b/dist/esm/experimental/tasks/mcp-server.js new file mode 100644 index 000000000..39b9d1082 --- /dev/null +++ b/dist/esm/experimental/tasks/mcp-server.js @@ -0,0 +1,32 @@ +/** + * Experimental McpServer task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +/** + * Experimental task features for McpServer. + * + * Access via `server.experimental.tasks`: + * ```typescript + * server.experimental.tasks.registerToolTask('long-running', config, handler); + * ``` + * + * @experimental + */ +export class ExperimentalMcpServerTasks { + constructor(_mcpServer) { + this._mcpServer = _mcpServer; + } + registerToolTask(name, config, handler) { + // Validate that taskSupport is not 'forbidden' for task-based tools + const execution = { taskSupport: 'required', ...config.execution }; + if (execution.taskSupport === 'forbidden') { + throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`); + } + // Access McpServer's internal _createRegisteredTool method + const mcpServerInternal = this._mcpServer; + return mcpServerInternal._createRegisteredTool(name, config.title, config.description, config.inputSchema, config.outputSchema, config.annotations, execution, config._meta, handler); + } +} +//# sourceMappingURL=mcp-server.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/mcp-server.js.map b/dist/esm/experimental/tasks/mcp-server.js.map new file mode 100644 index 000000000..c01a314c9 --- /dev/null +++ b/dist/esm/experimental/tasks/mcp-server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH;;;;;;;;;GASG;AACH,MAAM,OAAO,0BAA0B;IACnC,YAA6B,UAAqB;QAArB,eAAU,GAAV,UAAU,CAAW;IAAG,CAAC;IAgEtD,gBAAgB,CAIZ,IAAY,EACZ,MAQC,EACD,OAAmC;QAEnC,oEAAoE;QACpE,MAAM,SAAS,GAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAClF,IAAI,SAAS,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,6DAA6D,CAAC,CAAC;QAC3H,CAAC;QAED,2DAA2D;QAC3D,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAA0C,CAAC;QAC1E,OAAO,iBAAiB,CAAC,qBAAqB,CAC1C,IAAI,EACJ,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,WAAW,EAClB,SAAS,EACT,MAAM,CAAC,KAAK,EACZ,OAAwD,CAC3D,CAAC;IACN,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/server.d.ts b/dist/esm/experimental/tasks/server.d.ts new file mode 100644 index 000000000..185e0bab5 --- /dev/null +++ b/dist/esm/experimental/tasks/server.d.ts @@ -0,0 +1,83 @@ +/** + * Experimental server task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import type { Server } from '../../server/index.js'; +import type { RequestOptions } from '../../shared/protocol.js'; +import type { ResponseMessage } from '../../shared/responseMessage.js'; +import type { AnySchema, SchemaOutput } from '../../server/zod-compat.js'; +import type { ServerRequest, Notification, Request, Result, GetTaskResult, ListTasksResult, CancelTaskResult } from '../../types.js'; +/** + * Experimental task features for low-level MCP servers. + * + * Access via `server.experimental.tasks`: + * ```typescript + * const stream = server.experimental.tasks.requestStream(request, schema, options); + * ``` + * + * For high-level server usage with task-based tools, use `McpServer.experimental.tasks` instead. + * + * @experimental + */ +export declare class ExperimentalServerTasks { + private readonly _server; + constructor(_server: Server); + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request: ServerRequest | RequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + getTask(taskId: string, options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + getTaskResult(taskId: string, resultSchema?: T, options?: RequestOptions): Promise>; + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + listTasks(cursor?: string, options?: RequestOptions): Promise; + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + cancelTask(taskId: string, options?: RequestOptions): Promise; +} +//# sourceMappingURL=server.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/server.d.ts.map b/dist/esm/experimental/tasks/server.d.ts.map new file mode 100644 index 000000000..a1681854f --- /dev/null +++ b/dist/esm/experimental/tasks/server.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EA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newline at end of file diff --git a/dist/esm/experimental/tasks/server.js b/dist/esm/experimental/tasks/server.js new file mode 100644 index 000000000..3b429bb0b --- /dev/null +++ b/dist/esm/experimental/tasks/server.js @@ -0,0 +1,89 @@ +/** + * Experimental server task features for MCP SDK. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +/** + * Experimental task features for low-level MCP servers. + * + * Access via `server.experimental.tasks`: + * ```typescript + * const stream = server.experimental.tasks.requestStream(request, schema, options); + * ``` + * + * For high-level server usage with task-based tools, use `McpServer.experimental.tasks` instead. + * + * @experimental + */ +export class ExperimentalServerTasks { + constructor(_server) { + this._server = _server; + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * This method provides streaming access to request processing, allowing you to + * observe intermediate task status updates for task-augmented requests. + * + * @param request - The request to send + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options (timeout, signal, task creation params, etc.) + * @returns AsyncGenerator that yields ResponseMessage objects + * + * @experimental + */ + requestStream(request, resultSchema, options) { + return this._server.requestStream(request, resultSchema, options); + } + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * @returns The task status + * + * @experimental + */ + async getTask(taskId, options) { + return this._server.getTask({ taskId }, options); + } + /** + * Retrieves the result of a completed task. + * + * @param taskId - The task identifier + * @param resultSchema - Zod schema for validating the result + * @param options - Optional request options + * @returns The task result + * + * @experimental + */ + async getTaskResult(taskId, resultSchema, options) { + return this._server.getTaskResult({ taskId }, resultSchema, options); + } + /** + * Lists tasks with optional pagination. + * + * @param cursor - Optional pagination cursor + * @param options - Optional request options + * @returns List of tasks with optional next cursor + * + * @experimental + */ + async listTasks(cursor, options) { + return this._server.listTasks(cursor ? { cursor } : undefined, options); + } + /** + * Cancels a running task. + * + * @param taskId - The task identifier + * @param options - Optional request options + * + * @experimental + */ + async cancelTask(taskId, options) { + return this._server.cancelTask({ taskId }, options); + } +} +//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/server.js.map b/dist/esm/experimental/tasks/server.js.map new file mode 100644 index 000000000..4395efda5 --- /dev/null +++ b/dist/esm/experimental/tasks/server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,uBAAuB;IAKhC,YAA6B,OAAiD;QAAjD,YAAO,GAAP,OAAO,CAA0C;IAAG,CAAC;IAElF;;;;;;;;;;;;;OAaG;IACH,aAAa,CACT,OAAiC,EACjC,YAAe,EACf,OAAwB;QAUxB,OAAQ,IAAI,CAAC,OAA8C,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9G,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,OAAwB;QAElD,OAAQ,IAAI,CAAC,OAAwC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACvF,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,aAAa,CAAsB,MAAc,EAAE,YAAgB,EAAE,OAAwB;QAC/F,OACI,IAAI,CAAC,OAOR,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,CAAC,MAAe,EAAE,OAAwB;QACrD,OACI,IAAI,CAAC,OAGR,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,OAAwB;QACrD,OACI,IAAI,CAAC,OAGR,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/stores/in-memory.d.ts b/dist/esm/experimental/tasks/stores/in-memory.d.ts new file mode 100644 index 000000000..b2228b578 --- /dev/null +++ b/dist/esm/experimental/tasks/stores/in-memory.d.ts @@ -0,0 +1,94 @@ +/** + * In-memory implementations of TaskStore and TaskMessageQueue. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import { Task, Request, RequestId, Result } from '../../../types.js'; +import { TaskStore, TaskMessageQueue, QueuedMessage, CreateTaskOptions } from '../interfaces.js'; +/** + * A simple in-memory implementation of TaskStore for demonstration purposes. + * + * This implementation stores all tasks in memory and provides automatic cleanup + * based on the ttl duration specified in the task creation parameters. + * + * Note: This is not suitable for production use as all data is lost on restart. + * For production, consider implementing TaskStore with a database or distributed cache. + * + * @experimental + */ +export declare class InMemoryTaskStore implements TaskStore { + private tasks; + private cleanupTimers; + /** + * Generates a unique task ID. + * Uses 16 bytes of random data encoded as hex (32 characters). + */ + private generateTaskId; + createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, _sessionId?: string): Promise; + getTask(taskId: string, _sessionId?: string): Promise; + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result, _sessionId?: string): Promise; + getTaskResult(taskId: string, _sessionId?: string): Promise; + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string, _sessionId?: string): Promise; + listTasks(cursor?: string, _sessionId?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; + /** + * Cleanup all timers (useful for testing or graceful shutdown) + */ + cleanup(): void; + /** + * Get all tasks (useful for debugging) + */ + getAllTasks(): Task[]; +} +/** + * A simple in-memory implementation of TaskMessageQueue for demonstration purposes. + * + * This implementation stores messages in memory, organized by task ID and optional session ID. + * Messages are stored in FIFO queues per task. + * + * Note: This is not suitable for production use in distributed systems. + * For production, consider implementing TaskMessageQueue with Redis or other distributed queues. + * + * @experimental + */ +export declare class InMemoryTaskMessageQueue implements TaskMessageQueue { + private queues; + /** + * Generates a queue key from taskId. + * SessionId is intentionally ignored because taskIds are globally unique + * and tasks need to be accessible across HTTP requests/sessions. + */ + private getQueueKey; + /** + * Gets or creates a queue for the given task and session. + */ + private getQueue; + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + enqueue(taskId: string, message: QueuedMessage, sessionId?: string, maxSize?: number): Promise; + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + dequeue(taskId: string, sessionId?: string): Promise; + /** + * Removes and returns all messages from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + dequeueAll(taskId: string, sessionId?: string): Promise; +} +//# sourceMappingURL=in-memory.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/stores/in-memory.d.ts.map b/dist/esm/experimental/tasks/stores/in-memory.d.ts.map new file mode 100644 index 000000000..5b8bd7020 --- /dev/null +++ b/dist/esm/experimental/tasks/stores/in-memory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/tasks/stores/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAc,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAU7G;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IAC/C,OAAO,CAAC,KAAK,CA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,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1G;;;;;OAKG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAKrF;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAMjF"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/stores/in-memory.js b/dist/esm/experimental/tasks/stores/in-memory.js new file mode 100644 index 000000000..cb7b669f1 --- /dev/null +++ b/dist/esm/experimental/tasks/stores/in-memory.js @@ -0,0 +1,248 @@ +/** + * In-memory implementations of TaskStore and TaskMessageQueue. + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ +import { isTerminal } from '../interfaces.js'; +import { randomBytes } from 'node:crypto'; +/** + * A simple in-memory implementation of TaskStore for demonstration purposes. + * + * This implementation stores all tasks in memory and provides automatic cleanup + * based on the ttl duration specified in the task creation parameters. + * + * Note: This is not suitable for production use as all data is lost on restart. + * For production, consider implementing TaskStore with a database or distributed cache. + * + * @experimental + */ +export class InMemoryTaskStore { + constructor() { + this.tasks = new Map(); + this.cleanupTimers = new Map(); + } + /** + * Generates a unique task ID. + * Uses 16 bytes of random data encoded as hex (32 characters). + */ + generateTaskId() { + return randomBytes(16).toString('hex'); + } + async createTask(taskParams, requestId, request, _sessionId) { + var _a, _b; + // Generate a unique task ID + const taskId = this.generateTaskId(); + // Ensure uniqueness + if (this.tasks.has(taskId)) { + throw new Error(`Task with ID ${taskId} already exists`); + } + const actualTtl = (_a = taskParams.ttl) !== null && _a !== void 0 ? _a : null; + // Create task with generated ID and timestamps + const createdAt = new Date().toISOString(); + const task = { + taskId, + status: 'working', + ttl: actualTtl, + createdAt, + lastUpdatedAt: createdAt, + pollInterval: (_b = taskParams.pollInterval) !== null && _b !== void 0 ? _b : 1000 + }; + this.tasks.set(taskId, { + task, + request, + requestId + }); + // Schedule cleanup if ttl is specified + // Cleanup occurs regardless of task status + if (actualTtl) { + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, actualTtl); + this.cleanupTimers.set(taskId, timer); + } + return task; + } + async getTask(taskId, _sessionId) { + const stored = this.tasks.get(taskId); + return stored ? { ...stored.task } : null; + } + async storeTaskResult(taskId, status, result, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + // Don't allow storing results for tasks already in terminal state + if (isTerminal(stored.task.status)) { + throw new Error(`Cannot store result for task ${taskId} in terminal status '${stored.task.status}'. Task results can only be stored once.`); + } + stored.result = result; + stored.task.status = status; + stored.task.lastUpdatedAt = new Date().toISOString(); + // Reset cleanup timer to start from now (if ttl is set) + if (stored.task.ttl) { + const existingTimer = this.cleanupTimers.get(taskId); + if (existingTimer) { + clearTimeout(existingTimer); + } + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, stored.task.ttl); + this.cleanupTimers.set(taskId, timer); + } + } + async getTaskResult(taskId, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + if (!stored.result) { + throw new Error(`Task ${taskId} has no result stored`); + } + return stored.result; + } + async updateTaskStatus(taskId, status, statusMessage, _sessionId) { + const stored = this.tasks.get(taskId); + if (!stored) { + throw new Error(`Task with ID ${taskId} not found`); + } + // Don't allow transitions from terminal states + if (isTerminal(stored.task.status)) { + throw new Error(`Cannot update task ${taskId} from terminal status '${stored.task.status}' to '${status}'. Terminal states (completed, failed, cancelled) cannot transition to other states.`); + } + stored.task.status = status; + if (statusMessage) { + stored.task.statusMessage = statusMessage; + } + stored.task.lastUpdatedAt = new Date().toISOString(); + // If task is in a terminal state and has ttl, start cleanup timer + if (isTerminal(status) && stored.task.ttl) { + const existingTimer = this.cleanupTimers.get(taskId); + if (existingTimer) { + clearTimeout(existingTimer); + } + const timer = setTimeout(() => { + this.tasks.delete(taskId); + this.cleanupTimers.delete(taskId); + }, stored.task.ttl); + this.cleanupTimers.set(taskId, timer); + } + } + async listTasks(cursor, _sessionId) { + const PAGE_SIZE = 10; + const allTaskIds = Array.from(this.tasks.keys()); + let startIndex = 0; + if (cursor) { + const cursorIndex = allTaskIds.indexOf(cursor); + if (cursorIndex >= 0) { + startIndex = cursorIndex + 1; + } + else { + // Invalid cursor - throw error + throw new Error(`Invalid cursor: ${cursor}`); + } + } + const pageTaskIds = allTaskIds.slice(startIndex, startIndex + PAGE_SIZE); + const tasks = pageTaskIds.map(taskId => { + const stored = this.tasks.get(taskId); + return { ...stored.task }; + }); + const nextCursor = startIndex + PAGE_SIZE < allTaskIds.length ? pageTaskIds[pageTaskIds.length - 1] : undefined; + return { tasks, nextCursor }; + } + /** + * Cleanup all timers (useful for testing or graceful shutdown) + */ + cleanup() { + for (const timer of this.cleanupTimers.values()) { + clearTimeout(timer); + } + this.cleanupTimers.clear(); + this.tasks.clear(); + } + /** + * Get all tasks (useful for debugging) + */ + getAllTasks() { + return Array.from(this.tasks.values()).map(stored => ({ ...stored.task })); + } +} +/** + * A simple in-memory implementation of TaskMessageQueue for demonstration purposes. + * + * This implementation stores messages in memory, organized by task ID and optional session ID. + * Messages are stored in FIFO queues per task. + * + * Note: This is not suitable for production use in distributed systems. + * For production, consider implementing TaskMessageQueue with Redis or other distributed queues. + * + * @experimental + */ +export class InMemoryTaskMessageQueue { + constructor() { + this.queues = new Map(); + } + /** + * Generates a queue key from taskId. + * SessionId is intentionally ignored because taskIds are globally unique + * and tasks need to be accessible across HTTP requests/sessions. + */ + getQueueKey(taskId, _sessionId) { + return taskId; + } + /** + * Gets or creates a queue for the given task and session. + */ + getQueue(taskId, sessionId) { + const key = this.getQueueKey(taskId, sessionId); + let queue = this.queues.get(key); + if (!queue) { + queue = []; + this.queues.set(key, queue); + } + return queue; + } + /** + * Adds a message to the end of the queue for a specific task. + * Atomically checks queue size and throws if maxSize would be exceeded. + * @param taskId The task identifier + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @param maxSize Optional maximum queue size - if specified and queue is full, throws an error + * @throws Error if maxSize is specified and would be exceeded + */ + async enqueue(taskId, message, sessionId, maxSize) { + const queue = this.getQueue(taskId, sessionId); + // Atomically check size and enqueue + if (maxSize !== undefined && queue.length >= maxSize) { + throw new Error(`Task message queue overflow: queue size (${queue.length}) exceeds maximum (${maxSize})`); + } + queue.push(message); + } + /** + * Removes and returns the first message from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns The first message, or undefined if the queue is empty + */ + async dequeue(taskId, sessionId) { + const queue = this.getQueue(taskId, sessionId); + return queue.shift(); + } + /** + * Removes and returns all messages from the queue for a specific task. + * @param taskId The task identifier + * @param sessionId Optional session ID for binding the query to a specific session + * @returns Array of all messages that were in the queue + */ + async dequeueAll(taskId, sessionId) { + var _a; + const key = this.getQueueKey(taskId, sessionId); + const queue = (_a = this.queues.get(key)) !== null && _a !== void 0 ? _a : []; + this.queues.delete(key); + return queue; + } +} +//# sourceMappingURL=in-memory.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/stores/in-memory.js.map b/dist/esm/experimental/tasks/stores/in-memory.js.map new file mode 100644 index 000000000..857693a19 --- /dev/null +++ b/dist/esm/experimental/tasks/stores/in-memory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"in-memory.js","sourceRoot":"","sources":["../../../../../src/experimental/tasks/stores/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAa,UAAU,EAAsD,MAAM,kBAAkB,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,i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EAAE,SAAS,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,MAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/types.d.ts b/dist/esm/experimental/tasks/types.d.ts new file mode 100644 index 000000000..6022e19b2 --- /dev/null +++ b/dist/esm/experimental/tasks/types.d.ts @@ -0,0 +1,10 @@ +/** + * Re-exports of task-related types from the MCP protocol spec. + * WARNING: These APIs are experimental and may change without notice. + * + * These types are defined in types.ts (matching the protocol spec) and + * re-exported here for convenience when working with experimental task features. + */ +export { TaskCreationParamsSchema, RelatedTaskMetadataSchema, TaskSchema, CreateTaskResultSchema, TaskStatusNotificationParamsSchema, TaskStatusNotificationSchema, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, ClientTasksCapabilitySchema, ServerTasksCapabilitySchema } from '../../types.js'; +export type { Task, TaskCreationParams, RelatedTaskMetadata, CreateTaskResult, TaskStatusNotificationParams, TaskStatusNotification, GetTaskRequest, GetTaskResult, GetTaskPayloadRequest, ListTasksRequest, ListTasksResult, CancelTaskRequest, CancelTaskResult } from '../../types.js'; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/types.d.ts.map b/dist/esm/experimental/tasks/types.d.ts.map new file mode 100644 index 000000000..f7b9ead05 --- /dev/null +++ b/dist/esm/experimental/tasks/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/experimental/tasks/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACtB,kCAAkC,EAClC,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC9B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACR,IAAI,EACJ,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACnB,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/dist/esm/experimental/tasks/types.js b/dist/esm/experimental/tasks/types.js new file mode 100644 index 000000000..2162c093a --- /dev/null +++ b/dist/esm/experimental/tasks/types.js @@ -0,0 +1,10 @@ +/** + * Re-exports of task-related types from the MCP protocol spec. + * WARNING: These APIs are experimental and may change without notice. + * + * These types are defined in types.ts (matching the protocol spec) and + * re-exported here for convenience when working with experimental task features. + */ +// Task schemas (Zod) +export { TaskCreationParamsSchema, RelatedTaskMetadataSchema, TaskSchema, CreateTaskResultSchema, TaskStatusNotificationParamsSchema, TaskStatusNotificationSchema, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, ClientTasksCapabilitySchema, ServerTasksCapabilitySchema } from '../../types.js'; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/esm/experimental/tasks/types.js.map b/dist/esm/experimental/tasks/types.js.map new file mode 100644 index 000000000..f52e75e09 --- /dev/null +++ b/dist/esm/experimental/tasks/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/experimental/tasks/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAqB;AACrB,OAAO,EACH,wBAAwB,EACxB,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACtB,kCAAkC,EAClC,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC9B,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/dist/esm/inMemory.d.ts b/dist/esm/inMemory.d.ts new file mode 100644 index 000000000..32a931a86 --- /dev/null +++ b/dist/esm/inMemory.d.ts @@ -0,0 +1,31 @@ +import { Transport } from './shared/transport.js'; +import { JSONRPCMessage, RequestId } from './types.js'; +import { AuthInfo } from './server/auth/types.js'; +/** + * In-memory transport for creating clients and servers that talk to each other within the same process. + */ +export declare class InMemoryTransport implements Transport { + private _otherTransport?; + private _messageQueue; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: { + authInfo?: AuthInfo; + }) => void; + sessionId?: string; + /** + * Creates a pair of linked in-memory transports that can communicate with each other. One should be passed to a Client and one to a Server. + */ + static createLinkedPair(): [InMemoryTransport, InMemoryTransport]; + start(): Promise; + close(): Promise; + /** + * Sends a message with optional auth info. + * This is useful for testing authentication scenarios. + */ + send(message: JSONRPCMessage, options?: { + relatedRequestId?: RequestId; + authInfo?: AuthInfo; + }): Promise; +} +//# sourceMappingURL=inMemory.d.ts.map \ No newline at end of file diff --git a/dist/esm/inMemory.d.ts.map b/dist/esm/inMemory.d.ts.map new file mode 100644 index 000000000..46bc74be1 --- /dev/null +++ b/dist/esm/inMemory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemory.d.ts","sourceRoot":"","sources":["../../src/inMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAOlD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IAC/C,OAAO,CAAC,eAAe,CAAC,CAAoB;IAC5C,OAAO,CAAC,aAAa,CAAuB;IAE5C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,gBAAgB,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAQ3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;;OAGG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAWtH"} \ No newline at end of file diff --git a/dist/esm/inMemory.js b/dist/esm/inMemory.js new file mode 100644 index 000000000..930bbff51 --- /dev/null +++ b/dist/esm/inMemory.js @@ -0,0 +1,49 @@ +/** + * In-memory transport for creating clients and servers that talk to each other within the same process. + */ +export class InMemoryTransport { + constructor() { + this._messageQueue = []; + } + /** + * Creates a pair of linked in-memory transports that can communicate with each other. One should be passed to a Client and one to a Server. + */ + static createLinkedPair() { + const clientTransport = new InMemoryTransport(); + const serverTransport = new InMemoryTransport(); + clientTransport._otherTransport = serverTransport; + serverTransport._otherTransport = clientTransport; + return [clientTransport, serverTransport]; + } + async start() { + var _a; + // Process any messages that were queued before start was called + while (this._messageQueue.length > 0) { + const queuedMessage = this._messageQueue.shift(); + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, queuedMessage.message, queuedMessage.extra); + } + } + async close() { + var _a; + const other = this._otherTransport; + this._otherTransport = undefined; + await (other === null || other === void 0 ? void 0 : other.close()); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + /** + * Sends a message with optional auth info. + * This is useful for testing authentication scenarios. + */ + async send(message, options) { + if (!this._otherTransport) { + throw new Error('Not connected'); + } + if (this._otherTransport.onmessage) { + this._otherTransport.onmessage(message, { authInfo: options === null || options === void 0 ? void 0 : options.authInfo }); + } + else { + this._otherTransport._messageQueue.push({ message, extra: { authInfo: options === null || options === void 0 ? void 0 : options.authInfo } }); + } + } +} +//# sourceMappingURL=inMemory.js.map \ No newline at end of file diff --git a/dist/esm/inMemory.js.map b/dist/esm/inMemory.js.map new file mode 100644 index 000000000..f001ce163 --- /dev/null +++ b/dist/esm/inMemory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"inMemory.js","sourceRoot":"","sources":["../../src/inMemory.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QAEY,kBAAa,GAAoB,EAAE,CAAC;IAgDhD,CAAC;IAzCG;;OAEG;IACH,MAAM,CAAC,gBAAgB;QACnB,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAChD,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAChD,eAAe,CAAC,eAAe,GAAG,eAAe,CAAC;QAClD,eAAe,CAAC,eAAe,GAAG,eAAe,CAAC;QAClD,OAAO,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,gEAAgE;QAChE,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAG,CAAC;YAClD,MAAA,IAAI,CAAC,SAAS,qDAAG,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,MAAM,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,EAAE,CAAA,CAAC;QACrB,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB,EAAE,OAA+D;QAC/F,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACjG,CAAC;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/package.json b/dist/esm/package.json new file mode 100644 index 000000000..6990891ff --- /dev/null +++ b/dist/esm/package.json @@ -0,0 +1 @@ +{"type": "module"} diff --git a/dist/esm/server/auth/clients.d.ts b/dist/esm/server/auth/clients.d.ts new file mode 100644 index 000000000..be6899a19 --- /dev/null +++ b/dist/esm/server/auth/clients.d.ts @@ -0,0 +1,19 @@ +import { OAuthClientInformationFull } from '../../shared/auth.js'; +/** + * Stores information about registered OAuth clients for this server. + */ +export interface OAuthRegisteredClientsStore { + /** + * Returns information about a registered client, based on its ID. + */ + getClient(clientId: string): OAuthClientInformationFull | undefined | Promise; + /** + * Registers a new client with the server. The client ID and secret will be automatically generated by the library. A modified version of the client information can be returned to reflect specific values enforced by the server. + * + * NOTE: Implementations should NOT delete expired client secrets in-place. Auth middleware provided by this library will automatically check the `client_secret_expires_at` field and reject requests with expired secrets. Any custom logic for authenticating clients should check the `client_secret_expires_at` field as well. + * + * If unimplemented, dynamic client registration is unsupported. + */ + registerClient?(client: Omit): OAuthClientInformationFull | Promise; +} +//# sourceMappingURL=clients.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/clients.d.ts.map b/dist/esm/server/auth/clients.d.ts.map new file mode 100644 index 000000000..ab3851db3 --- /dev/null +++ b/dist/esm/server/auth/clients.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IACxC;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,GAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAAC;IAEtH;;;;;;OAMG;IACH,cAAc,CAAC,CACX,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,WAAW,GAAG,qBAAqB,CAAC,GAC9E,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;CACvE"} \ No newline at end of file diff --git a/dist/esm/server/auth/clients.js b/dist/esm/server/auth/clients.js new file mode 100644 index 000000000..6181a5709 --- /dev/null +++ b/dist/esm/server/auth/clients.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=clients.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/clients.js.map b/dist/esm/server/auth/clients.js.map new file mode 100644 index 000000000..021010442 --- /dev/null +++ b/dist/esm/server/auth/clients.js.map @@ -0,0 +1 @@ +{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../../src/server/auth/clients.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/server/auth/errors.d.ts b/dist/esm/server/auth/errors.d.ts new file mode 100644 index 000000000..7fddf954c --- /dev/null +++ b/dist/esm/server/auth/errors.d.ts @@ -0,0 +1,148 @@ +import { OAuthErrorResponse } from '../../shared/auth.js'; +/** + * Base class for all OAuth errors + */ +export declare class OAuthError extends Error { + readonly errorUri?: string | undefined; + static errorCode: string; + constructor(message: string, errorUri?: string | undefined); + /** + * Converts the error to a standard OAuth error response object + */ + toResponseObject(): OAuthErrorResponse; + get errorCode(): string; +} +/** + * Invalid request error - The request is missing a required parameter, + * includes an invalid parameter value, includes a parameter more than once, + * or is otherwise malformed. + */ +export declare class InvalidRequestError extends OAuthError { + static errorCode: string; +} +/** + * Invalid client error - Client authentication failed (e.g., unknown client, no client + * authentication included, or unsupported authentication method). + */ +export declare class InvalidClientError extends OAuthError { + static errorCode: string; +} +/** + * Invalid grant error - The provided authorization grant or refresh token is + * invalid, expired, revoked, does not match the redirection URI used in the + * authorization request, or was issued to another client. + */ +export declare class InvalidGrantError extends OAuthError { + static errorCode: string; +} +/** + * Unauthorized client error - The authenticated client is not authorized to use + * this authorization grant type. + */ +export declare class UnauthorizedClientError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported grant type error - The authorization grant type is not supported + * by the authorization server. + */ +export declare class UnsupportedGrantTypeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid scope error - The requested scope is invalid, unknown, malformed, or + * exceeds the scope granted by the resource owner. + */ +export declare class InvalidScopeError extends OAuthError { + static errorCode: string; +} +/** + * Access denied error - The resource owner or authorization server denied the request. + */ +export declare class AccessDeniedError extends OAuthError { + static errorCode: string; +} +/** + * Server error - The authorization server encountered an unexpected condition + * that prevented it from fulfilling the request. + */ +export declare class ServerError extends OAuthError { + static errorCode: string; +} +/** + * Temporarily unavailable error - The authorization server is currently unable to + * handle the request due to a temporary overloading or maintenance of the server. + */ +export declare class TemporarilyUnavailableError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported response type error - The authorization server does not support + * obtaining an authorization code using this method. + */ +export declare class UnsupportedResponseTypeError extends OAuthError { + static errorCode: string; +} +/** + * Unsupported token type error - The authorization server does not support + * the requested token type. + */ +export declare class UnsupportedTokenTypeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid token error - The access token provided is expired, revoked, malformed, + * or invalid for other reasons. + */ +export declare class InvalidTokenError extends OAuthError { + static errorCode: string; +} +/** + * Method not allowed error - The HTTP method used is not allowed for this endpoint. + * (Custom, non-standard error) + */ +export declare class MethodNotAllowedError extends OAuthError { + static errorCode: string; +} +/** + * Too many requests error - Rate limit exceeded. + * (Custom, non-standard error based on RFC 6585) + */ +export declare class TooManyRequestsError extends OAuthError { + static errorCode: string; +} +/** + * Invalid client metadata error - The client metadata is invalid. + * (Custom error for dynamic client registration - RFC 7591) + */ +export declare class InvalidClientMetadataError extends OAuthError { + static errorCode: string; +} +/** + * Insufficient scope error - The request requires higher privileges than provided by the access token. + */ +export declare class InsufficientScopeError extends OAuthError { + static errorCode: string; +} +/** + * Invalid target error - The requested resource is invalid, missing, unknown, or malformed. + * (Custom error for resource indicators - RFC 8707) + */ +export declare class InvalidTargetError extends OAuthError { + static errorCode: string; +} +/** + * A utility class for defining one-off error codes + */ +export declare class CustomOAuthError extends OAuthError { + private readonly customErrorCode; + constructor(customErrorCode: string, message: string, errorUri?: string); + get errorCode(): string; +} +/** + * A full list of all OAuthErrors, enabling parsing from error responses + */ +export declare const OAUTH_ERRORS: { + readonly [x: string]: typeof InvalidRequestError; +}; +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/errors.d.ts.map b/dist/esm/server/auth/errors.d.ts.map new file mode 100644 index 000000000..5c0e99202 --- /dev/null +++ b/dist/esm/server/auth/errors.d.ts.map @@ -0,0 +1 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S,SAA+B;CAClD;AAED;;;GAGG;AACH,qBAAa,yBAA0B,SAAQ,UAAU;IACrD,MAAM,CAAC,SAAS,SAA4B;CAC/C;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC7C,MAAM,CAAC,SAAS,SAAmB;CACtC;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,UAAU;IACjD,MAAM,CAAC,SAAS,SAAwB;CAC3C;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IAChD,MAAM,CAAC,SAAS,SAAuB;CAC1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;IACtD,MAAM,CAAC,SAAS,SAA6B;CAChD;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,MAAM,CAAC,SAAS,SAAwB;CAC3C;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAC9C,MAAM,CAAC,SAAS,SAAoB;CACvC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAExC,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,MAAM,EACxC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM;IAKrB,IAAI,SAAS,IAAI,MAAM,CAEtB;CACJ;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;CAkBf,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/errors.js b/dist/esm/server/auth/errors.js new file mode 100644 index 000000000..7106ab98a --- /dev/null +++ b/dist/esm/server/auth/errors.js @@ -0,0 +1,180 @@ +/** + * Base class for all OAuth errors + */ +export class OAuthError extends Error { + constructor(message, errorUri) { + super(message); + this.errorUri = errorUri; + this.name = this.constructor.name; + } + /** + * Converts the error to a standard OAuth error response object + */ + toResponseObject() { + const response = { + error: this.errorCode, + error_description: this.message + }; + if (this.errorUri) { + response.error_uri = this.errorUri; + } + return response; + } + get errorCode() { + return this.constructor.errorCode; + } +} +/** + * Invalid request error - The request is missing a required parameter, + * includes an invalid parameter value, includes a parameter more than once, + * or is otherwise malformed. + */ +export class InvalidRequestError extends OAuthError { +} +InvalidRequestError.errorCode = 'invalid_request'; +/** + * Invalid client error - Client authentication failed (e.g., unknown client, no client + * authentication included, or unsupported authentication method). + */ +export class InvalidClientError extends OAuthError { +} +InvalidClientError.errorCode = 'invalid_client'; +/** + * Invalid grant error - The provided authorization grant or refresh token is + * invalid, expired, revoked, does not match the redirection URI used in the + * authorization request, or was issued to another client. + */ +export class InvalidGrantError extends OAuthError { +} +InvalidGrantError.errorCode = 'invalid_grant'; +/** + * Unauthorized client error - The authenticated client is not authorized to use + * this authorization grant type. + */ +export class UnauthorizedClientError extends OAuthError { +} +UnauthorizedClientError.errorCode = 'unauthorized_client'; +/** + * Unsupported grant type error - The authorization grant type is not supported + * by the authorization server. + */ +export class UnsupportedGrantTypeError extends OAuthError { +} +UnsupportedGrantTypeError.errorCode = 'unsupported_grant_type'; +/** + * Invalid scope error - The requested scope is invalid, unknown, malformed, or + * exceeds the scope granted by the resource owner. + */ +export class InvalidScopeError extends OAuthError { +} +InvalidScopeError.errorCode = 'invalid_scope'; +/** + * Access denied error - The resource owner or authorization server denied the request. + */ +export class AccessDeniedError extends OAuthError { +} +AccessDeniedError.errorCode = 'access_denied'; +/** + * Server error - The authorization server encountered an unexpected condition + * that prevented it from fulfilling the request. + */ +export class ServerError extends OAuthError { +} +ServerError.errorCode = 'server_error'; +/** + * Temporarily unavailable error - The authorization server is currently unable to + * handle the request due to a temporary overloading or maintenance of the server. + */ +export class TemporarilyUnavailableError extends OAuthError { +} +TemporarilyUnavailableError.errorCode = 'temporarily_unavailable'; +/** + * Unsupported response type error - The authorization server does not support + * obtaining an authorization code using this method. + */ +export class UnsupportedResponseTypeError extends OAuthError { +} +UnsupportedResponseTypeError.errorCode = 'unsupported_response_type'; +/** + * Unsupported token type error - The authorization server does not support + * the requested token type. + */ +export class UnsupportedTokenTypeError extends OAuthError { +} +UnsupportedTokenTypeError.errorCode = 'unsupported_token_type'; +/** + * Invalid token error - The access token provided is expired, revoked, malformed, + * or invalid for other reasons. + */ +export class InvalidTokenError extends OAuthError { +} +InvalidTokenError.errorCode = 'invalid_token'; +/** + * Method not allowed error - The HTTP method used is not allowed for this endpoint. + * (Custom, non-standard error) + */ +export class MethodNotAllowedError extends OAuthError { +} +MethodNotAllowedError.errorCode = 'method_not_allowed'; +/** + * Too many requests error - Rate limit exceeded. + * (Custom, non-standard error based on RFC 6585) + */ +export class TooManyRequestsError extends OAuthError { +} +TooManyRequestsError.errorCode = 'too_many_requests'; +/** + * Invalid client metadata error - The client metadata is invalid. + * (Custom error for dynamic client registration - RFC 7591) + */ +export class InvalidClientMetadataError extends OAuthError { +} +InvalidClientMetadataError.errorCode = 'invalid_client_metadata'; +/** + * Insufficient scope error - The request requires higher privileges than provided by the access token. + */ +export class InsufficientScopeError extends OAuthError { +} +InsufficientScopeError.errorCode = 'insufficient_scope'; +/** + * Invalid target error - The requested resource is invalid, missing, unknown, or malformed. + * (Custom error for resource indicators - RFC 8707) + */ +export class InvalidTargetError extends OAuthError { +} +InvalidTargetError.errorCode = 'invalid_target'; +/** + * A utility class for defining one-off error codes + */ +export class CustomOAuthError extends OAuthError { + constructor(customErrorCode, message, errorUri) { + super(message, errorUri); + this.customErrorCode = customErrorCode; + } + get errorCode() { + return this.customErrorCode; + } +} +/** + * A full list of all OAuthErrors, enabling parsing from error responses + */ +export const OAUTH_ERRORS = { + [InvalidRequestError.errorCode]: InvalidRequestError, + [InvalidClientError.errorCode]: InvalidClientError, + [InvalidGrantError.errorCode]: InvalidGrantError, + [UnauthorizedClientError.errorCode]: UnauthorizedClientError, + [UnsupportedGrantTypeError.errorCode]: UnsupportedGrantTypeError, + [InvalidScopeError.errorCode]: InvalidScopeError, + [AccessDeniedError.errorCode]: AccessDeniedError, + [ServerError.errorCode]: ServerError, + [TemporarilyUnavailableError.errorCode]: TemporarilyUnavailableError, + [UnsupportedResponseTypeError.errorCode]: UnsupportedResponseTypeError, + [UnsupportedTokenTypeError.errorCode]: UnsupportedTokenTypeError, + [InvalidTokenError.errorCode]: InvalidTokenError, + [MethodNotAllowedError.errorCode]: MethodNotAllowedError, + [TooManyRequestsError.errorCode]: TooManyRequestsError, + [InvalidClientMetadataError.errorCode]: InvalidClientMetadataError, + [InsufficientScopeError.errorCode]: InsufficientScopeError, + [InvalidTargetError.errorCode]: InvalidTargetError +}; +//# sourceMappingURL=errors.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/errors.js.map b/dist/esm/server/auth/errors.js.map new file mode 100644 index 000000000..1461367c6 --- /dev/null +++ b/dist/esm/server/auth/errors.js.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/server/auth/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGjC,YACI,OAAe,EACC,QAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAS;QAGjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,MAAM,QAAQ,GAAuB;YACjC,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,iBAAiB,EAAE,IAAI,CAAC,OAAO;SAClC,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QACvC,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,IAAI,SAAS;QACT,OAAQ,IAAI,CAAC,WAAiC,CAAC,SAAS,CAAC;IAC7D,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;;AACxC,6BAAS,GAAG,iBAAiB,CAAC;AAGzC;;;GAGG;AACH,MAAM,OAAO,kB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AC,EAAE,0BAA0B;IAClE,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,sBAAsB;IAC1D,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,kBAAkB;CAC5C,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/authorize.d.ts b/dist/esm/server/auth/handlers/authorize.d.ts new file mode 100644 index 000000000..38e9829bd --- /dev/null +++ b/dist/esm/server/auth/handlers/authorize.d.ts @@ -0,0 +1,13 @@ +import { RequestHandler } from 'express'; +import { OAuthServerProvider } from '../provider.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type AuthorizationHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the authorization endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function authorizationHandler({ provider, rateLimit: rateLimitConfig }: AuthorizationHandlerOptions): RequestHandler; +//# sourceMappingURL=authorize.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/authorize.d.ts.map b/dist/esm/server/auth/handlers/authorize.d.ts.map new file mode 100644 index 000000000..b06798834 --- /dev/null +++ b/dist/esm/server/auth/handlers/authorize.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,2BAA2B,GAAG;IACtC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAqBF,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,2BAA2B,GAAG,cAAc,CAgH1H"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/authorize.js b/dist/esm/server/auth/handlers/authorize.js new file mode 100644 index 000000000..e29f09438 --- /dev/null +++ b/dist/esm/server/auth/handlers/authorize.js @@ -0,0 +1,138 @@ +import * as z from 'zod/v4'; +import express from 'express'; +import { rateLimit } from 'express-rate-limit'; +import { allowedMethods } from '../middleware/allowedMethods.js'; +import { InvalidRequestError, InvalidClientError, ServerError, TooManyRequestsError, OAuthError } from '../errors.js'; +// Parameters that must be validated in order to issue redirects. +const ClientAuthorizationParamsSchema = z.object({ + client_id: z.string(), + redirect_uri: z + .string() + .optional() + .refine(value => value === undefined || URL.canParse(value), { message: 'redirect_uri must be a valid URL' }) +}); +// Parameters that must be validated for a successful authorization request. Failure can be reported to the redirect URI. +const RequestAuthorizationParamsSchema = z.object({ + response_type: z.literal('code'), + code_challenge: z.string(), + code_challenge_method: z.literal('S256'), + scope: z.string().optional(), + state: z.string().optional(), + resource: z.string().url().optional() +}); +export function authorizationHandler({ provider, rateLimit: rateLimitConfig }) { + // Create a router to apply middleware + const router = express.Router(); + router.use(allowedMethods(['GET', 'POST'])); + router.use(express.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use(rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // 100 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new TooManyRequestsError('You have exceeded the rate limit for authorization requests').toResponseObject(), + ...rateLimitConfig + })); + } + router.all('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + // In the authorization flow, errors are split into two categories: + // 1. Pre-redirect errors (direct response with 400) + // 2. Post-redirect errors (redirect with error parameters) + // Phase 1: Validate client_id and redirect_uri. Any errors here must be direct responses. + let client_id, redirect_uri, client; + try { + const result = ClientAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query); + if (!result.success) { + throw new InvalidRequestError(result.error.message); + } + client_id = result.data.client_id; + redirect_uri = result.data.redirect_uri; + client = await provider.clientsStore.getClient(client_id); + if (!client) { + throw new InvalidClientError('Invalid client_id'); + } + if (redirect_uri !== undefined) { + if (!client.redirect_uris.includes(redirect_uri)) { + throw new InvalidRequestError('Unregistered redirect_uri'); + } + } + else if (client.redirect_uris.length === 1) { + redirect_uri = client.redirect_uris[0]; + } + else { + throw new InvalidRequestError('redirect_uri must be specified when client has multiple registered URIs'); + } + } + catch (error) { + // Pre-redirect errors - return direct response + // + // These don't need to be JSON encoded, as they'll be displayed in a user + // agent, but OTOH they all represent exceptional situations (arguably, + // "programmer error"), so presenting a nice HTML page doesn't help the + // user anyway. + if (error instanceof OAuthError) { + const status = error instanceof ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + return; + } + // Phase 2: Validate other parameters. Any errors here should go into redirect responses. + let state; + try { + // Parse and validate authorization parameters + const parseResult = RequestAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query); + if (!parseResult.success) { + throw new InvalidRequestError(parseResult.error.message); + } + const { scope, code_challenge, resource } = parseResult.data; + state = parseResult.data.state; + // Validate scopes + let requestedScopes = []; + if (scope !== undefined) { + requestedScopes = scope.split(' '); + } + // All validation passed, proceed with authorization + await provider.authorize(client, { + state, + scopes: requestedScopes, + redirectUri: redirect_uri, + codeChallenge: code_challenge, + resource: resource ? new URL(resource) : undefined + }, res); + } + catch (error) { + // Post-redirect errors - redirect with error parameters + if (error instanceof OAuthError) { + res.redirect(302, createErrorRedirect(redirect_uri, error, state)); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.redirect(302, createErrorRedirect(redirect_uri, serverError, state)); + } + } + }); + return router; +} +/** + * Helper function to create redirect URL with error parameters + */ +function createErrorRedirect(redirectUri, error, state) { + const errorUrl = new URL(redirectUri); + errorUrl.searchParams.set('error', error.errorCode); + errorUrl.searchParams.set('error_description', error.message); + if (error.errorUri) { + errorUrl.searchParams.set('error_uri', error.errorUri); + } + if (state) { + errorUrl.searchParams.set('state', state); + } + return errorUrl.href; +} +//# sourceMappingURL=authorize.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/authorize.js.map b/dist/esm/server/auth/handlers/authorize.js.map new file mode 100644 index 000000000..6911f9a38 --- /dev/null +++ b/dist/esm/server/auth/handlers/authorize.js.map @@ -0,0 +1 @@ +{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,SAAS,EAA+B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAWtH,iEAAiE;AACjE,MAAM,+BAA+B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,YAAY,EAAE,CAAC;SACV,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,kCAAkC,EAAE,CAAC;CACpH,CAAC,CAAC;AAEH,yHAAyH;AACzH,MAAM,gCAAgC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAChC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,qBAAqB,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EA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S;aACrD,EACD,GAAG,CACN,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,wDAAwD;YACxD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACvE,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAC7E,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,WAAmB,EAAE,KAAiB,EAAE,KAAc;IAC/E,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACtC,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,EAAE,CAAC;QACR,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/metadata.d.ts b/dist/esm/server/auth/handlers/metadata.d.ts new file mode 100644 index 000000000..4d0328617 --- /dev/null +++ b/dist/esm/server/auth/handlers/metadata.d.ts @@ -0,0 +1,4 @@ +import { RequestHandler } from 'express'; +import { OAuthMetadata, OAuthProtectedResourceMetadata } from '../../../shared/auth.js'; +export declare function metadataHandler(metadata: OAuthMetadata | OAuthProtectedResourceMetadata): RequestHandler; +//# sourceMappingURL=metadata.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/metadata.d.ts.map b/dist/esm/server/auth/handlers/metadata.d.ts.map new file mode 100644 index 000000000..55e3a50dc --- /dev/null +++ b/dist/esm/server/auth/handlers/metadata.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAIxF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,aAAa,GAAG,8BAA8B,GAAG,cAAc,CAaxG"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/metadata.js b/dist/esm/server/auth/handlers/metadata.js new file mode 100644 index 000000000..94dadb709 --- /dev/null +++ b/dist/esm/server/auth/handlers/metadata.js @@ -0,0 +1,15 @@ +import express from 'express'; +import cors from 'cors'; +import { allowedMethods } from '../middleware/allowedMethods.js'; +export function metadataHandler(metadata) { + // Nested router so we can configure middleware and restrict HTTP method + const router = express.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use(cors()); + router.use(allowedMethods(['GET', 'OPTIONS'])); + router.get('/', (req, res) => { + res.status(200).json(metadata); + }); + return router; +} +//# sourceMappingURL=metadata.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/metadata.js.map b/dist/esm/server/auth/handlers/metadata.js.map new file mode 100644 index 000000000..625ed947d --- /dev/null +++ b/dist/esm/server/auth/handlers/metadata.js.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,OAA2B,MAAM,SAAS,CAAC;AAElD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,UAAU,eAAe,CAAC,QAAwD;IACpF,wEAAwE;IACxE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;IAClF,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/register.d.ts b/dist/esm/server/auth/handlers/register.d.ts new file mode 100644 index 000000000..e9add2845 --- /dev/null +++ b/dist/esm/server/auth/handlers/register.d.ts @@ -0,0 +1,29 @@ +import { RequestHandler } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type ClientRegistrationHandlerOptions = { + /** + * A store used to save information about dynamically registered OAuth clients. + */ + clientsStore: OAuthRegisteredClientsStore; + /** + * The number of seconds after which to expire issued client secrets, or 0 to prevent expiration of client secrets (not recommended). + * + * If not set, defaults to 30 days. + */ + clientSecretExpirySeconds?: number; + /** + * Rate limiting configuration for the client registration endpoint. + * Set to false to disable rate limiting for this endpoint. + * Registration endpoints are particularly sensitive to abuse and should be rate limited. + */ + rateLimit?: Partial | false; + /** + * Whether to generate a client ID before calling the client registration endpoint. + * + * If not set, defaults to true. + */ + clientIdGeneration?: boolean; +}; +export declare function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds, rateLimit: rateLimitConfig, clientIdGeneration }: ClientRegistrationHandlerOptions): RequestHandler; +//# sourceMappingURL=register.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/register.d.ts.map b/dist/esm/server/auth/handlers/register.d.ts.map new file mode 100644 index 000000000..a38ebdb89 --- /dev/null +++ b/dist/esm/server/auth/handlers/register.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,gCAAgC,GAAG;IAC3C;;OAEG;IACH,YAAY,EAAE,2BAA2B,CAAC;IAE1C;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IAE9C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAIF,wBAAgB,yBAAyB,CAAC,EACtC,YAAY,EACZ,yBAAgE,EAChE,SAAS,EAAE,eAAe,EAC1B,kBAAyB,EAC5B,EAAE,gCAAgC,GAAG,cAAc,CA0EnD"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/register.js b/dist/esm/server/auth/handlers/register.js new file mode 100644 index 000000000..ef6c44d51 --- /dev/null +++ b/dist/esm/server/auth/handlers/register.js @@ -0,0 +1,71 @@ +import express from 'express'; +import { OAuthClientMetadataSchema } from '../../../shared/auth.js'; +import crypto from 'node:crypto'; +import cors from 'cors'; +import { rateLimit } from 'express-rate-limit'; +import { allowedMethods } from '../middleware/allowedMethods.js'; +import { InvalidClientMetadataError, ServerError, TooManyRequestsError, OAuthError } from '../errors.js'; +const DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS = 30 * 24 * 60 * 60; // 30 days +export function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds = DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS, rateLimit: rateLimitConfig, clientIdGeneration = true }) { + if (!clientsStore.registerClient) { + throw new Error('Client registration store does not support registering clients'); + } + // Nested router so we can configure middleware and restrict HTTP method + const router = express.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use(cors()); + router.use(allowedMethods(['POST'])); + router.use(express.json()); + // Apply rate limiting unless explicitly disabled - stricter limits for registration + if (rateLimitConfig !== false) { + router.use(rateLimit({ + windowMs: 60 * 60 * 1000, // 1 hour + max: 20, // 20 requests per hour - stricter as registration is sensitive + standardHeaders: true, + legacyHeaders: false, + message: new TooManyRequestsError('You have exceeded the rate limit for client registration requests').toResponseObject(), + ...rateLimitConfig + })); + } + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = OAuthClientMetadataSchema.safeParse(req.body); + if (!parseResult.success) { + throw new InvalidClientMetadataError(parseResult.error.message); + } + const clientMetadata = parseResult.data; + const isPublicClient = clientMetadata.token_endpoint_auth_method === 'none'; + // Generate client credentials + const clientSecret = isPublicClient ? undefined : crypto.randomBytes(32).toString('hex'); + const clientIdIssuedAt = Math.floor(Date.now() / 1000); + // Calculate client secret expiry time + const clientsDoExpire = clientSecretExpirySeconds > 0; + const secretExpiryTime = clientsDoExpire ? clientIdIssuedAt + clientSecretExpirySeconds : 0; + const clientSecretExpiresAt = isPublicClient ? undefined : secretExpiryTime; + let clientInfo = { + ...clientMetadata, + client_secret: clientSecret, + client_secret_expires_at: clientSecretExpiresAt + }; + if (clientIdGeneration) { + clientInfo.client_id = crypto.randomUUID(); + clientInfo.client_id_issued_at = clientIdIssuedAt; + } + clientInfo = await clientsStore.registerClient(clientInfo); + res.status(201).json(clientInfo); + } + catch (error) { + if (error instanceof OAuthError) { + const status = error instanceof ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=register.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/register.js.map b/dist/esm/server/auth/handlers/register.js.map new file mode 100644 index 000000000..3f4c082f0 --- /dev/null +++ b/dist/esm/server/auth/handlers/register.js.map @@ -0,0 +1 @@ +{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":"AAAA,OAAO,OAA2B,MAAM,SAAS,CAAC;AAClD,OAAO,EAA8B,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAChG,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAA+B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA8BzG,MAAM,oCAAoC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AAE1E,MAAM,UAAU,yBAAyB,CAAC,EACtC,YAAY,EACZ,yBAAyB,GAAG,oCAAoC,EAChE,SAAS,EAAE,eAAe,EAC1B,kBAAkB,GAAG,IAAI,EACM;IAC/B,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACtF,CAAC;IAED,wEAAwE;IACxE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;I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YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/revoke.d.ts b/dist/esm/server/auth/handlers/revoke.d.ts new file mode 100644 index 000000000..2be32bb3c --- /dev/null +++ b/dist/esm/server/auth/handlers/revoke.d.ts @@ -0,0 +1,13 @@ +import { OAuthServerProvider } from '../provider.js'; +import { RequestHandler } from 'express'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type RevocationHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the token revocation endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function revocationHandler({ provider, rateLimit: rateLimitConfig }: RevocationHandlerOptions): RequestHandler; +//# sourceMappingURL=revoke.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/revoke.d.ts.map b/dist/esm/server/auth/handlers/revoke.d.ts.map new file mode 100644 index 000000000..fb13cf19f --- /dev/null +++ b/dist/esm/server/auth/handlers/revoke.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/revoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5E,MAAM,MAAM,wBAAwB,GAAG;IACnC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,wBAAwB,GAAG,cAAc,CA4DpH"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/revoke.js b/dist/esm/server/auth/handlers/revoke.js new file mode 100644 index 000000000..68f5284dd --- /dev/null +++ b/dist/esm/server/auth/handlers/revoke.js @@ -0,0 +1,59 @@ +import express from 'express'; +import cors from 'cors'; +import { authenticateClient } from '../middleware/clientAuth.js'; +import { OAuthTokenRevocationRequestSchema } from '../../../shared/auth.js'; +import { rateLimit } from 'express-rate-limit'; +import { allowedMethods } from '../middleware/allowedMethods.js'; +import { InvalidRequestError, ServerError, TooManyRequestsError, OAuthError } from '../errors.js'; +export function revocationHandler({ provider, rateLimit: rateLimitConfig }) { + if (!provider.revokeToken) { + throw new Error('Auth provider does not support revoking tokens'); + } + // Nested router so we can configure middleware and restrict HTTP method + const router = express.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use(cors()); + router.use(allowedMethods(['POST'])); + router.use(express.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use(rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 50, // 50 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new TooManyRequestsError('You have exceeded the rate limit for token revocation requests').toResponseObject(), + ...rateLimitConfig + })); + } + // Authenticate and extract client details + router.use(authenticateClient({ clientsStore: provider.clientsStore })); + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = OAuthTokenRevocationRequestSchema.safeParse(req.body); + if (!parseResult.success) { + throw new InvalidRequestError(parseResult.error.message); + } + const client = req.client; + if (!client) { + // This should never happen + throw new ServerError('Internal Server Error'); + } + await provider.revokeToken(client, parseResult.data); + res.status(200).json({}); + } + catch (error) { + if (error instanceof OAuthError) { + const status = error instanceof ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=revoke.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/revoke.js.map b/dist/esm/server/auth/handlers/revoke.js.map new file mode 100644 index 000000000..e1a0b1db9 --- /dev/null +++ b/dist/esm/server/auth/handlers/revoke.js.map @@ -0,0 +1 @@ +{"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/revoke.ts"],"names":[],"mappings":"AACA,OAAO,OAA2B,MAAM,SAAS,CAAC;AAClD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAA+B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAWlG,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAA4B;IAChG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACtE,CAAC;IAED,wEAAwE;IACxE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;IAClF,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAEpD,iDAAiD;IACjD,IAAI,eAAe,KAAK,KAAK,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CACN,SAAS,CAAC;YACN,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI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ACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/token.d.ts b/dist/esm/server/auth/handlers/token.d.ts new file mode 100644 index 000000000..24d1c8783 --- /dev/null +++ b/dist/esm/server/auth/handlers/token.d.ts @@ -0,0 +1,13 @@ +import { RequestHandler } from 'express'; +import { OAuthServerProvider } from '../provider.js'; +import { Options as RateLimitOptions } from 'express-rate-limit'; +export type TokenHandlerOptions = { + provider: OAuthServerProvider; + /** + * Rate limiting configuration for the token endpoint. + * Set to false to disable rate limiting for this endpoint. + */ + rateLimit?: Partial | false; +}; +export declare function tokenHandler({ provider, rateLimit: rateLimitConfig }: TokenHandlerOptions): RequestHandler; +//# sourceMappingURL=token.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/token.d.ts.map b/dist/esm/server/auth/handlers/token.d.ts.map new file mode 100644 index 000000000..68189b0b2 --- /dev/null +++ b/dist/esm/server/auth/handlers/token.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/token.ts"],"names":[],"mappings":"AACA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIrD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW5E,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAmBF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,mBAAmB,GAAG,cAAc,CA+G1G"} \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/token.js b/dist/esm/server/auth/handlers/token.js new file mode 100644 index 000000000..8ce2721f2 --- /dev/null +++ b/dist/esm/server/auth/handlers/token.js @@ -0,0 +1,107 @@ +import * as z from 'zod/v4'; +import express from 'express'; +import cors from 'cors'; +import { verifyChallenge } from 'pkce-challenge'; +import { authenticateClient } from '../middleware/clientAuth.js'; +import { rateLimit } from 'express-rate-limit'; +import { allowedMethods } from '../middleware/allowedMethods.js'; +import { InvalidRequestError, InvalidGrantError, UnsupportedGrantTypeError, ServerError, TooManyRequestsError, OAuthError } from '../errors.js'; +const TokenRequestSchema = z.object({ + grant_type: z.string() +}); +const AuthorizationCodeGrantSchema = z.object({ + code: z.string(), + code_verifier: z.string(), + redirect_uri: z.string().optional(), + resource: z.string().url().optional() +}); +const RefreshTokenGrantSchema = z.object({ + refresh_token: z.string(), + scope: z.string().optional(), + resource: z.string().url().optional() +}); +export function tokenHandler({ provider, rateLimit: rateLimitConfig }) { + // Nested router so we can configure middleware and restrict HTTP method + const router = express.Router(); + // Configure CORS to allow any origin, to make accessible to web-based MCP clients + router.use(cors()); + router.use(allowedMethods(['POST'])); + router.use(express.urlencoded({ extended: false })); + // Apply rate limiting unless explicitly disabled + if (rateLimitConfig !== false) { + router.use(rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 50, // 50 requests per windowMs + standardHeaders: true, + legacyHeaders: false, + message: new TooManyRequestsError('You have exceeded the rate limit for token requests').toResponseObject(), + ...rateLimitConfig + })); + } + // Authenticate and extract client details + router.use(authenticateClient({ clientsStore: provider.clientsStore })); + router.post('/', async (req, res) => { + res.setHeader('Cache-Control', 'no-store'); + try { + const parseResult = TokenRequestSchema.safeParse(req.body); + if (!parseResult.success) { + throw new InvalidRequestError(parseResult.error.message); + } + const { grant_type } = parseResult.data; + const client = req.client; + if (!client) { + // This should never happen + throw new ServerError('Internal Server Error'); + } + switch (grant_type) { + case 'authorization_code': { + const parseResult = AuthorizationCodeGrantSchema.safeParse(req.body); + if (!parseResult.success) { + throw new InvalidRequestError(parseResult.error.message); + } + const { code, code_verifier, redirect_uri, resource } = parseResult.data; + const skipLocalPkceValidation = provider.skipLocalPkceValidation; + // Perform local PKCE validation unless explicitly skipped + // (e.g. to validate code_verifier in upstream server) + if (!skipLocalPkceValidation) { + const codeChallenge = await provider.challengeForAuthorizationCode(client, code); + if (!(await verifyChallenge(code_verifier, codeChallenge))) { + throw new InvalidGrantError('code_verifier does not match the challenge'); + } + } + // Passes the code_verifier to the provider if PKCE validation didn't occur locally + const tokens = await provider.exchangeAuthorizationCode(client, code, skipLocalPkceValidation ? code_verifier : undefined, redirect_uri, resource ? new URL(resource) : undefined); + res.status(200).json(tokens); + break; + } + case 'refresh_token': { + const parseResult = RefreshTokenGrantSchema.safeParse(req.body); + if (!parseResult.success) { + throw new InvalidRequestError(parseResult.error.message); + } + const { refresh_token, scope, resource } = parseResult.data; + const scopes = scope === null || scope === void 0 ? void 0 : scope.split(' '); + const tokens = await provider.exchangeRefreshToken(client, refresh_token, scopes, resource ? new URL(resource) : undefined); + res.status(200).json(tokens); + break; + } + // Additional auth methods will not be added on the server side of the SDK. + case 'client_credentials': + default: + throw new UnsupportedGrantTypeError('The grant type is not supported by this authorization server.'); + } + } + catch (error) { + if (error instanceof OAuthError) { + const status = error instanceof ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }); + return router; +} +//# sourceMappingURL=token.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/handlers/token.js.map b/dist/esm/server/auth/handlers/token.js.map new file mode 100644 index 000000000..eb8eab548 --- /dev/null +++ b/dist/esm/server/auth/handlers/token.js.map @@ -0,0 +1 @@ +{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAA2B,MAAM,SAAS,CAAC;AAElD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,SAAS,EAA+B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EACH,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,WAAW,EACX,oBAAoB,EACpB,UAAU,EACb,MAAM,cAAc,CAAC;AAWtB,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,EA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AC,CAAC,CAAC,GAAG,CAAC;gBACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/allowedMethods.d.ts b/dist/esm/server/auth/middleware/allowedMethods.d.ts new file mode 100644 index 000000000..ee6037e0d --- /dev/null +++ b/dist/esm/server/auth/middleware/allowedMethods.d.ts @@ -0,0 +1,9 @@ +import { RequestHandler } from 'express'; +/** + * Middleware to handle unsupported HTTP methods with a 405 Method Not Allowed response. + * + * @param allowedMethods Array of allowed HTTP methods for this endpoint (e.g., ['GET', 'POST']) + * @returns Express middleware that returns a 405 error if method not in allowed list + */ +export declare function allowedMethods(allowedMethods: string[]): RequestHandler; +//# sourceMappingURL=allowedMethods.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/allowedMethods.d.ts.map b/dist/esm/server/auth/middleware/allowedMethods.d.ts.map new file mode 100644 index 000000000..d3de93e24 --- /dev/null +++ b/dist/esm/server/auth/middleware/allowedMethods.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"allowedMethods.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/allowedMethods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,cAAc,CAUvE"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/allowedMethods.js b/dist/esm/server/auth/middleware/allowedMethods.js new file mode 100644 index 000000000..af2ba0892 --- /dev/null +++ b/dist/esm/server/auth/middleware/allowedMethods.js @@ -0,0 +1,18 @@ +import { MethodNotAllowedError } from '../errors.js'; +/** + * Middleware to handle unsupported HTTP methods with a 405 Method Not Allowed response. + * + * @param allowedMethods Array of allowed HTTP methods for this endpoint (e.g., ['GET', 'POST']) + * @returns Express middleware that returns a 405 error if method not in allowed list + */ +export function allowedMethods(allowedMethods) { + return (req, res, next) => { + if (allowedMethods.includes(req.method)) { + next(); + return; + } + const error = new MethodNotAllowedError(`The method ${req.method} is not allowed for this endpoint`); + res.status(405).set('Allow', allowedMethods.join(', ')).json(error.toResponseObject()); + }; +} +//# sourceMappingURL=allowedMethods.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/allowedMethods.js.map b/dist/esm/server/auth/middleware/allowedMethods.js.map new file mode 100644 index 000000000..c41097986 --- /dev/null +++ b/dist/esm/server/auth/middleware/allowedMethods.js.map @@ -0,0 +1 @@ +{"version":3,"file":"allowedMethods.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/allowedMethods.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,cAAwB;IACnD,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,IAAI,EAAE,CAAC;YACP,OAAO;QACX,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,qBAAqB,CAAC,cAAc,GAAG,CAAC,MAAM,mCAAmC,CAAC,CAAC;QACrG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC3F,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/bearerAuth.d.ts b/dist/esm/server/auth/middleware/bearerAuth.d.ts new file mode 100644 index 000000000..10730758b --- /dev/null +++ b/dist/esm/server/auth/middleware/bearerAuth.d.ts @@ -0,0 +1,35 @@ +import { RequestHandler } from 'express'; +import { OAuthTokenVerifier } from '../provider.js'; +import { AuthInfo } from '../types.js'; +export type BearerAuthMiddlewareOptions = { + /** + * A provider used to verify tokens. + */ + verifier: OAuthTokenVerifier; + /** + * Optional scopes that the token must have. + */ + requiredScopes?: string[]; + /** + * Optional resource metadata URL to include in WWW-Authenticate header. + */ + resourceMetadataUrl?: string; +}; +declare module 'express-serve-static-core' { + interface Request { + /** + * Information about the validated access token, if the `requireBearerAuth` middleware was used. + */ + auth?: AuthInfo; + } +} +/** + * Middleware that requires a valid Bearer token in the Authorization header. + * + * This will validate the token with the auth provider and add the resulting auth info to the request object. + * + * If resourceMetadataUrl is provided, it will be included in the WWW-Authenticate header + * for 401 responses as per the OAuth 2.0 Protected Resource Metadata spec. + */ +export declare function requireBearerAuth({ verifier, requiredScopes, resourceMetadataUrl }: BearerAuthMiddlewareOptions): RequestHandler; +//# sourceMappingURL=bearerAuth.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/bearerAuth.d.ts.map b/dist/esm/server/auth/middleware/bearerAuth.d.ts.map new file mode 100644 index 000000000..c9d939f3b --- /dev/null +++ b/dist/esm/server/auth/middleware/bearerAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bearerAuth.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/bearerAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,MAAM,2BAA2B,GAAG;IACtC;;OAEG;IACH,QAAQ,EAAE,kBAAkB,CAAC;IAE7B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,OAAO,QAAQ,2BAA2B,CAAC;IACvC,UAAU,OAAO;QACb;;WAEG;QACH,IAAI,CAAC,EAAE,QAAQ,CAAC;KACnB;CACJ;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,cAAmB,EAAE,mBAAmB,EAAE,EAAE,2BAA2B,GAAG,cAAc,CA8DrI"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/bearerAuth.js b/dist/esm/server/auth/middleware/bearerAuth.js new file mode 100644 index 000000000..0c527b4f4 --- /dev/null +++ b/dist/esm/server/auth/middleware/bearerAuth.js @@ -0,0 +1,72 @@ +import { InsufficientScopeError, InvalidTokenError, OAuthError, ServerError } from '../errors.js'; +/** + * Middleware that requires a valid Bearer token in the Authorization header. + * + * This will validate the token with the auth provider and add the resulting auth info to the request object. + * + * If resourceMetadataUrl is provided, it will be included in the WWW-Authenticate header + * for 401 responses as per the OAuth 2.0 Protected Resource Metadata spec. + */ +export function requireBearerAuth({ verifier, requiredScopes = [], resourceMetadataUrl }) { + return async (req, res, next) => { + try { + const authHeader = req.headers.authorization; + if (!authHeader) { + throw new InvalidTokenError('Missing Authorization header'); + } + const [type, token] = authHeader.split(' '); + if (type.toLowerCase() !== 'bearer' || !token) { + throw new InvalidTokenError("Invalid Authorization header format, expected 'Bearer TOKEN'"); + } + const authInfo = await verifier.verifyAccessToken(token); + // Check if token has the required scopes (if any) + if (requiredScopes.length > 0) { + const hasAllScopes = requiredScopes.every(scope => authInfo.scopes.includes(scope)); + if (!hasAllScopes) { + throw new InsufficientScopeError('Insufficient scope'); + } + } + // Check if the token is set to expire or if it is expired + if (typeof authInfo.expiresAt !== 'number' || isNaN(authInfo.expiresAt)) { + throw new InvalidTokenError('Token has no expiration time'); + } + else if (authInfo.expiresAt < Date.now() / 1000) { + throw new InvalidTokenError('Token has expired'); + } + req.auth = authInfo; + next(); + } + catch (error) { + // Build WWW-Authenticate header parts + const buildWwwAuthHeader = (errorCode, message) => { + let header = `Bearer error="${errorCode}", error_description="${message}"`; + if (requiredScopes.length > 0) { + header += `, scope="${requiredScopes.join(' ')}"`; + } + if (resourceMetadataUrl) { + header += `, resource_metadata="${resourceMetadataUrl}"`; + } + return header; + }; + if (error instanceof InvalidTokenError) { + res.set('WWW-Authenticate', buildWwwAuthHeader(error.errorCode, error.message)); + res.status(401).json(error.toResponseObject()); + } + else if (error instanceof InsufficientScopeError) { + res.set('WWW-Authenticate', buildWwwAuthHeader(error.errorCode, error.message)); + res.status(403).json(error.toResponseObject()); + } + else if (error instanceof ServerError) { + res.status(500).json(error.toResponseObject()); + } + else if (error instanceof OAuthError) { + res.status(400).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }; +} +//# sourceMappingURL=bearerAuth.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/bearerAuth.js.map b/dist/esm/server/auth/middleware/bearerAuth.js.map new file mode 100644 index 000000000..d8d0179b7 --- /dev/null +++ b/dist/esm/server/auth/middleware/bearerAuth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bearerAuth.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/bearerAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA8BlG;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,cAAc,GAAG,EAAE,EAAE,mBAAmB,EAA+B;IACjH,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,I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C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/clientAuth.d.ts b/dist/esm/server/auth/middleware/clientAuth.d.ts new file mode 100644 index 000000000..837f95fd2 --- /dev/null +++ b/dist/esm/server/auth/middleware/clientAuth.d.ts @@ -0,0 +1,19 @@ +import { RequestHandler } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { OAuthClientInformationFull } from '../../../shared/auth.js'; +export type ClientAuthenticationMiddlewareOptions = { + /** + * A store used to read information about registered OAuth clients. + */ + clientsStore: OAuthRegisteredClientsStore; +}; +declare module 'express-serve-static-core' { + interface Request { + /** + * The authenticated client for this request, if the `authenticateClient` middleware was used. + */ + client?: OAuthClientInformationFull; + } +} +export declare function authenticateClient({ clientsStore }: ClientAuthenticationMiddlewareOptions): RequestHandler; +//# sourceMappingURL=clientAuth.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/clientAuth.d.ts.map b/dist/esm/server/auth/middleware/clientAuth.d.ts.map new file mode 100644 index 000000000..5455132c9 --- /dev/null +++ b/dist/esm/server/auth/middleware/clientAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"clientAuth.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/clientAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,qCAAqC,GAAG;IAChD;;OAEG;IACH,YAAY,EAAE,2BAA2B,CAAC;CAC7C,CAAC;AAOF,OAAO,QAAQ,2BAA2B,CAAC;IACvC,UAAU,OAAO;QACb;;WAEG;QACH,MAAM,CAAC,EAAE,0BAA0B,CAAC;KACvC;CACJ;AAED,wBAAgB,kBAAkB,CAAC,EAAE,YAAY,EAAE,EAAE,qCAAqC,GAAG,cAAc,CAoC1G"} \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/clientAuth.js b/dist/esm/server/auth/middleware/clientAuth.js new file mode 100644 index 000000000..cce72a2d2 --- /dev/null +++ b/dist/esm/server/auth/middleware/clientAuth.js @@ -0,0 +1,45 @@ +import * as z from 'zod/v4'; +import { InvalidRequestError, InvalidClientError, ServerError, OAuthError } from '../errors.js'; +const ClientAuthenticatedRequestSchema = z.object({ + client_id: z.string(), + client_secret: z.string().optional() +}); +export function authenticateClient({ clientsStore }) { + return async (req, res, next) => { + try { + const result = ClientAuthenticatedRequestSchema.safeParse(req.body); + if (!result.success) { + throw new InvalidRequestError(String(result.error)); + } + const { client_id, client_secret } = result.data; + const client = await clientsStore.getClient(client_id); + if (!client) { + throw new InvalidClientError('Invalid client_id'); + } + if (client.client_secret) { + if (!client_secret) { + throw new InvalidClientError('Client secret is required'); + } + if (client.client_secret !== client_secret) { + throw new InvalidClientError('Invalid client_secret'); + } + if (client.client_secret_expires_at && client.client_secret_expires_at < Math.floor(Date.now() / 1000)) { + throw new InvalidClientError('Client secret has expired'); + } + } + req.client = client; + next(); + } + catch (error) { + if (error instanceof OAuthError) { + const status = error instanceof ServerError ? 500 : 400; + res.status(status).json(error.toResponseObject()); + } + else { + const serverError = new ServerError('Internal Server Error'); + res.status(500).json(serverError.toResponseObject()); + } + } + }; +} +//# sourceMappingURL=clientAuth.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/middleware/clientAuth.js.map b/dist/esm/server/auth/middleware/clientAuth.js.map new file mode 100644 index 000000000..5023c023b --- /dev/null +++ b/dist/esm/server/auth/middleware/clientAuth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"clientAuth.js","sourceRoot":"","sources":["../../../../../src/server/auth/middleware/clientAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAShG,MAAM,gCAAgC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAC;AAWH,MAAM,UAAU,kBAAkB,CAAC,EAAE,YAAY,EAAyC;IACtF,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,gCAAgC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClB,MAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACxD,CAAC;YACD,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,MAAM,IAAI,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;YACtD,CAAC;YACD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACvB,IAAI,CAAC,aAAa,EAAE,CAAC;oBACjB,MAAM,IAAI,kBAAkB,CAAC,2BAA2B,CAAC,CAAC;gBAC9D,CAAC;gBACD,IAAI,MAAM,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;oBACzC,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;gBAC1D,CAAC;gBACD,IAAI,MAAM,CAAC,wBAAwB,IAAI,MAAM,CAAC,wBAAwB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;oBACrG,MAAM,IAAI,kBAAkB,CAAC,2BAA2B,CAAC,CAAC;gBAC9D,CAAC;YACL,CAAC;YAED,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;YACpB,IAAI,EAAE,CAAC;QACX,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;gBACxD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACJ,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;IACL,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/provider.d.ts b/dist/esm/server/auth/provider.d.ts new file mode 100644 index 000000000..3e4eca392 --- /dev/null +++ b/dist/esm/server/auth/provider.d.ts @@ -0,0 +1,68 @@ +import { Response } from 'express'; +import { OAuthRegisteredClientsStore } from './clients.js'; +import { OAuthClientInformationFull, OAuthTokenRevocationRequest, OAuthTokens } from '../../shared/auth.js'; +import { AuthInfo } from './types.js'; +export type AuthorizationParams = { + state?: string; + scopes?: string[]; + codeChallenge: string; + redirectUri: string; + resource?: URL; +}; +/** + * Implements an end-to-end OAuth server. + */ +export interface OAuthServerProvider { + /** + * A store used to read information about registered OAuth clients. + */ + get clientsStore(): OAuthRegisteredClientsStore; + /** + * Begins the authorization flow, which can either be implemented by this server itself or via redirection to a separate authorization server. + * + * This server must eventually issue a redirect with an authorization response or an error response to the given redirect URI. Per OAuth 2.1: + * - In the successful case, the redirect MUST include the `code` and `state` (if present) query parameters. + * - In the error case, the redirect MUST include the `error` query parameter, and MAY include an optional `error_description` query parameter. + */ + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + /** + * Returns the `codeChallenge` that was used when the indicated authorization began. + */ + challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise; + /** + * Exchanges an authorization code for an access token. + */ + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, codeVerifier?: string, redirectUri?: string, resource?: URL): Promise; + /** + * Exchanges a refresh token for an access token. + */ + exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: URL): Promise; + /** + * Verifies an access token and returns information about it. + */ + verifyAccessToken(token: string): Promise; + /** + * Revokes an access or refresh token. If unimplemented, token revocation is not supported (not recommended). + * + * If the given token is invalid or already revoked, this method should do nothing. + */ + revokeToken?(client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest): Promise; + /** + * Whether to skip local PKCE validation. + * + * If true, the server will not perform PKCE validation locally and will pass the code_verifier to the upstream server. + * + * NOTE: This should only be true if the upstream server is performing the actual PKCE validation. + */ + skipLocalPkceValidation?: boolean; +} +/** + * Slim implementation useful for token verification + */ +export interface OAuthTokenVerifier { + /** + * Verifies an access token and returns information about it. + */ + verifyAccessToken(token: string): Promise; +} +//# sourceMappingURL=provider.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/provider.d.ts.map b/dist/esm/server/auth/provider.d.ts.map new file mode 100644 index 000000000..d1a4bfff0 --- /dev/null +++ b/dist/esm/server/auth/provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,MAAM,mBAAmB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,IAAI,YAAY,IAAI,2BAA2B,CAAC;IAEhD;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,0BAA0B,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzG;;OAEG;IACH,6BAA6B,CAAC,MAAM,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE9G;;OAEG;IACH,yBAAyB,CACrB,MAAM,EAAE,0BAA0B,EAClC,iBAAiB,EAAE,MAAM,EACzB,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAExI;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpD;;;;OAIG;IACH,WAAW,CAAC,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtG;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACvD"} \ No newline at end of file diff --git a/dist/esm/server/auth/provider.js b/dist/esm/server/auth/provider.js new file mode 100644 index 000000000..be31058cd --- /dev/null +++ b/dist/esm/server/auth/provider.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=provider.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/provider.js.map b/dist/esm/server/auth/provider.js.map new file mode 100644 index 000000000..b968414aa --- /dev/null +++ b/dist/esm/server/auth/provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../src/server/auth/provider.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/server/auth/providers/proxyProvider.d.ts b/dist/esm/server/auth/providers/proxyProvider.d.ts new file mode 100644 index 000000000..ee6f35081 --- /dev/null +++ b/dist/esm/server/auth/providers/proxyProvider.d.ts @@ -0,0 +1,49 @@ +import { Response } from 'express'; +import { OAuthRegisteredClientsStore } from '../clients.js'; +import { OAuthClientInformationFull, OAuthTokenRevocationRequest, OAuthTokens } from '../../../shared/auth.js'; +import { AuthInfo } from '../types.js'; +import { AuthorizationParams, OAuthServerProvider } from '../provider.js'; +import { FetchLike } from '../../../shared/transport.js'; +export type ProxyEndpoints = { + authorizationUrl: string; + tokenUrl: string; + revocationUrl?: string; + registrationUrl?: string; +}; +export type ProxyOptions = { + /** + * Individual endpoint URLs for proxying specific OAuth operations + */ + endpoints: ProxyEndpoints; + /** + * Function to verify access tokens and return auth info + */ + verifyAccessToken: (token: string) => Promise; + /** + * Function to fetch client information from the upstream server + */ + getClient: (clientId: string) => Promise; + /** + * Custom fetch implementation used for all network requests. + */ + fetch?: FetchLike; +}; +/** + * Implements an OAuth server that proxies requests to another OAuth server. + */ +export declare class ProxyOAuthServerProvider implements OAuthServerProvider { + protected readonly _endpoints: ProxyEndpoints; + protected readonly _verifyAccessToken: (token: string) => Promise; + protected readonly _getClient: (clientId: string) => Promise; + protected readonly _fetch?: FetchLike; + skipLocalPkceValidation: boolean; + revokeToken?: (client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest) => Promise; + constructor(options: ProxyOptions); + get clientsStore(): OAuthRegisteredClientsStore; + authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise; + challengeForAuthorizationCode(_client: OAuthClientInformationFull, _authorizationCode: string): Promise; + exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, codeVerifier?: string, redirectUri?: string, resource?: URL): Promise; + exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: URL): Promise; + verifyAccessToken(token: string): Promise; +} +//# sourceMappingURL=proxyProvider.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/providers/proxyProvider.d.ts.map b/dist/esm/server/auth/providers/proxyProvider.d.ts.map new file mode 100644 index 000000000..124c105fa --- /dev/null +++ b/dist/esm/server/auth/providers/proxyProvider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proxyProvider.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/providers/proxyProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5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E,OAAO,EAAE,2BAA2B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;gBAE9F,OAAO,EAAE,YAAY;IAuCjC,IAAI,YAAY,IAAI,2BAA2B,CAwB9C;IAEK,SAAS,CAAC,MAAM,EAAE,0BAA0B,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxG,6BAA6B,CAAC,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM/G,yBAAyB,CAC3B,MAAM,EAAE,0BAA0B,EAClC,iBAAiB,EAAE,MAAM,EACzB,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,WAAW,CAAC;IAwCjB,oBAAoB,CACtB,MAAM,EAAE,0BAA0B,EAClC,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,MAAM,EAAE,EACjB,QAAQ,CAAC,EAAE,GAAG,GACf,OAAO,CAAC,WAAW,CAAC;IAoCjB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;CAG5D"} \ No newline at end of file diff --git a/dist/esm/server/auth/providers/proxyProvider.js b/dist/esm/server/auth/providers/proxyProvider.js new file mode 100644 index 000000000..72ee96620 --- /dev/null +++ b/dist/esm/server/auth/providers/proxyProvider.js @@ -0,0 +1,161 @@ +import { OAuthClientInformationFullSchema, OAuthTokensSchema } from '../../../shared/auth.js'; +import { ServerError } from '../errors.js'; +/** + * Implements an OAuth server that proxies requests to another OAuth server. + */ +export class ProxyOAuthServerProvider { + constructor(options) { + var _a; + this.skipLocalPkceValidation = true; + this._endpoints = options.endpoints; + this._verifyAccessToken = options.verifyAccessToken; + this._getClient = options.getClient; + this._fetch = options.fetch; + if ((_a = options.endpoints) === null || _a === void 0 ? void 0 : _a.revocationUrl) { + this.revokeToken = async (client, request) => { + var _a, _b; + const revocationUrl = this._endpoints.revocationUrl; + if (!revocationUrl) { + throw new Error('No revocation endpoint configured'); + } + const params = new URLSearchParams(); + params.set('token', request.token); + params.set('client_id', client.client_id); + if (client.client_secret) { + params.set('client_secret', client.client_secret); + } + if (request.token_type_hint) { + params.set('token_type_hint', request.token_type_hint); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(revocationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + if (!response.ok) { + throw new ServerError(`Token revocation failed: ${response.status}`); + } + }; + } + } + get clientsStore() { + const registrationUrl = this._endpoints.registrationUrl; + return { + getClient: this._getClient, + ...(registrationUrl && { + registerClient: async (client) => { + var _a, _b; + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(registrationUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(client) + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new ServerError(`Client registration failed: ${response.status}`); + } + const data = await response.json(); + return OAuthClientInformationFullSchema.parse(data); + } + }) + }; + } + async authorize(client, params, res) { + var _a; + // Start with required OAuth parameters + const targetUrl = new URL(this._endpoints.authorizationUrl); + const searchParams = new URLSearchParams({ + client_id: client.client_id, + response_type: 'code', + redirect_uri: params.redirectUri, + code_challenge: params.codeChallenge, + code_challenge_method: 'S256' + }); + // Add optional standard OAuth parameters + if (params.state) + searchParams.set('state', params.state); + if ((_a = params.scopes) === null || _a === void 0 ? void 0 : _a.length) + searchParams.set('scope', params.scopes.join(' ')); + if (params.resource) + searchParams.set('resource', params.resource.href); + targetUrl.search = searchParams.toString(); + res.redirect(targetUrl.toString()); + } + async challengeForAuthorizationCode(_client, _authorizationCode) { + // In a proxy setup, we don't store the code challenge ourselves + // Instead, we proxy the token request and let the upstream server validate it + return ''; + } + async exchangeAuthorizationCode(client, authorizationCode, codeVerifier, redirectUri, resource) { + var _a, _b; + const params = new URLSearchParams({ + grant_type: 'authorization_code', + client_id: client.client_id, + code: authorizationCode + }); + if (client.client_secret) { + params.append('client_secret', client.client_secret); + } + if (codeVerifier) { + params.append('code_verifier', codeVerifier); + } + if (redirectUri) { + params.append('redirect_uri', redirectUri); + } + if (resource) { + params.append('resource', resource.href); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._endpoints.tokenUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new ServerError(`Token exchange failed: ${response.status}`); + } + const data = await response.json(); + return OAuthTokensSchema.parse(data); + } + async exchangeRefreshToken(client, refreshToken, scopes, resource) { + var _a, _b; + const params = new URLSearchParams({ + grant_type: 'refresh_token', + client_id: client.client_id, + refresh_token: refreshToken + }); + if (client.client_secret) { + params.set('client_secret', client.client_secret); + } + if (scopes === null || scopes === void 0 ? void 0 : scopes.length) { + params.set('scope', scopes.join(' ')); + } + if (resource) { + params.set('resource', resource.href); + } + const response = await ((_a = this._fetch) !== null && _a !== void 0 ? _a : fetch)(this._endpoints.tokenUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: params.toString() + }); + if (!response.ok) { + await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); + throw new ServerError(`Token refresh failed: ${response.status}`); + } + const data = await response.json(); + return OAuthTokensSchema.parse(data); + } + async verifyAccessToken(token) { + return this._verifyAccessToken(token); + } +} +//# sourceMappingURL=proxyProvider.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/providers/proxyProvider.js.map b/dist/esm/server/auth/providers/proxyProvider.js.map new file mode 100644 index 000000000..cb94caac5 --- /dev/null +++ b/dist/esm/server/auth/providers/proxyProvider.js.map @@ -0,0 +1 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CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/server/auth/router.d.ts b/dist/esm/server/auth/router.d.ts new file mode 100644 index 000000000..43dabde7d --- /dev/null +++ b/dist/esm/server/auth/router.d.ts @@ -0,0 +1,101 @@ +import express, { RequestHandler } from 'express'; +import { ClientRegistrationHandlerOptions } from './handlers/register.js'; +import { TokenHandlerOptions } from './handlers/token.js'; +import { AuthorizationHandlerOptions } from './handlers/authorize.js'; +import { RevocationHandlerOptions } from './handlers/revoke.js'; +import { OAuthServerProvider } from './provider.js'; +import { OAuthMetadata } from '../../shared/auth.js'; +export type AuthRouterOptions = { + /** + * A provider implementing the actual authorization logic for this router. + */ + provider: OAuthServerProvider; + /** + * The authorization server's issuer identifier, which is a URL that uses the "https" scheme and has no query or fragment components. + */ + issuerUrl: URL; + /** + * The base URL of the authorization server to use for the metadata endpoints. + * + * If not provided, the issuer URL will be used as the base URL. + */ + baseUrl?: URL; + /** + * An optional URL of a page containing human-readable information that developers might want or need to know when using the authorization server. + */ + serviceDocumentationUrl?: URL; + /** + * An optional list of scopes supported by this authorization server + */ + scopesSupported?: string[]; + /** + * The resource name to be displayed in protected resource metadata + */ + resourceName?: string; + /** + * The URL of the protected resource (RS) whose metadata we advertise. + * If not provided, falls back to `baseUrl` and then to `issuerUrl` (AS=RS). + */ + resourceServerUrl?: URL; + authorizationOptions?: Omit; + clientRegistrationOptions?: Omit; + revocationOptions?: Omit; + tokenOptions?: Omit; +}; +export declare const createOAuthMetadata: (options: { + provider: OAuthServerProvider; + issuerUrl: URL; + baseUrl?: URL; + serviceDocumentationUrl?: URL; + scopesSupported?: string[]; +}) => OAuthMetadata; +/** + * Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported). + * Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients. + * Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead. + * + * By default, rate limiting is applied to all endpoints to prevent abuse. + * + * This router MUST be installed at the application root, like so: + * + * const app = express(); + * app.use(mcpAuthRouter(...)); + */ +export declare function mcpAuthRouter(options: AuthRouterOptions): RequestHandler; +export type AuthMetadataOptions = { + /** + * OAuth Metadata as would be returned from the authorization server + * this MCP server relies on + */ + oauthMetadata: OAuthMetadata; + /** + * The url of the MCP server, for use in protected resource metadata + */ + resourceServerUrl: URL; + /** + * The url for documentation for the MCP server + */ + serviceDocumentationUrl?: URL; + /** + * An optional list of scopes supported by this MCP server + */ + scopesSupported?: string[]; + /** + * An optional resource name to display in resource metadata + */ + resourceName?: string; +}; +export declare function mcpAuthMetadataRouter(options: AuthMetadataOptions): express.Router; +/** + * Helper function to construct the OAuth 2.0 Protected Resource Metadata URL + * from a given server URL. This replaces the path with the standard metadata endpoint. + * + * @param serverUrl - The base URL of the protected resource server + * @returns The URL for the OAuth protected resource metadata endpoint + * + * @example + * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp')) + * // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp' + */ +export declare function getOAuthProtectedResourceMetadataUrl(serverUrl: URL): string; +//# sourceMappingURL=router.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/router.d.ts.map b/dist/esm/server/auth/router.d.ts.map new file mode 100644 index 000000000..615cb964b --- /dev/null +++ b/dist/esm/server/auth/router.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAA6B,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAgB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAwB,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;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AAa,CAAC;IAE7B;;OAEG;IACH,iBAAiB,EAAE,GAAG,CAAC;IAEvB;;OAEG;IACH,uBAAuB,CAAC,EAAE,GAAG,CAAC;IAE9B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAuBlF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oCAAoC,CAAC,SAAS,EAAE,GAAG,GAAG,MAAM,CAI3E"} \ No newline at end of file diff --git a/dist/esm/server/auth/router.js b/dist/esm/server/auth/router.js new file mode 100644 index 000000000..731d5c8a1 --- /dev/null +++ b/dist/esm/server/auth/router.js @@ -0,0 +1,121 @@ +import express from 'express'; +import { clientRegistrationHandler } from './handlers/register.js'; +import { tokenHandler } from './handlers/token.js'; +import { authorizationHandler } from './handlers/authorize.js'; +import { revocationHandler } from './handlers/revoke.js'; +import { metadataHandler } from './handlers/metadata.js'; +// Check for dev mode flag that allows HTTP issuer URLs (for development/testing only) +const allowInsecureIssuerUrl = process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === 'true' || process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === '1'; +if (allowInsecureIssuerUrl) { + // eslint-disable-next-line no-console + console.warn('MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL is enabled - HTTP issuer URLs are allowed. Do not use in production.'); +} +const checkIssuerUrl = (issuer) => { + // Technically RFC 8414 does not permit a localhost HTTPS exemption, but this will be necessary for ease of testing + if (issuer.protocol !== 'https:' && issuer.hostname !== 'localhost' && issuer.hostname !== '127.0.0.1' && !allowInsecureIssuerUrl) { + throw new Error('Issuer URL must be HTTPS'); + } + if (issuer.hash) { + throw new Error(`Issuer URL must not have a fragment: ${issuer}`); + } + if (issuer.search) { + throw new Error(`Issuer URL must not have a query string: ${issuer}`); + } +}; +export const createOAuthMetadata = (options) => { + var _a; + const issuer = options.issuerUrl; + const baseUrl = options.baseUrl; + checkIssuerUrl(issuer); + const authorization_endpoint = '/authorize'; + const token_endpoint = '/token'; + const registration_endpoint = options.provider.clientsStore.registerClient ? '/register' : undefined; + const revocation_endpoint = options.provider.revokeToken ? '/revoke' : undefined; + const metadata = { + issuer: issuer.href, + service_documentation: (_a = options.serviceDocumentationUrl) === null || _a === void 0 ? void 0 : _a.href, + authorization_endpoint: new URL(authorization_endpoint, baseUrl || issuer).href, + response_types_supported: ['code'], + code_challenge_methods_supported: ['S256'], + token_endpoint: new URL(token_endpoint, baseUrl || issuer).href, + token_endpoint_auth_methods_supported: ['client_secret_post', 'none'], + grant_types_supported: ['authorization_code', 'refresh_token'], + scopes_supported: options.scopesSupported, + revocation_endpoint: revocation_endpoint ? new URL(revocation_endpoint, baseUrl || issuer).href : undefined, + revocation_endpoint_auth_methods_supported: revocation_endpoint ? ['client_secret_post'] : undefined, + registration_endpoint: registration_endpoint ? new URL(registration_endpoint, baseUrl || issuer).href : undefined + }; + return metadata; +}; +/** + * Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported). + * Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients. + * Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead. + * + * By default, rate limiting is applied to all endpoints to prevent abuse. + * + * This router MUST be installed at the application root, like so: + * + * const app = express(); + * app.use(mcpAuthRouter(...)); + */ +export function mcpAuthRouter(options) { + var _a, _b; + const oauthMetadata = createOAuthMetadata(options); + const router = express.Router(); + router.use(new URL(oauthMetadata.authorization_endpoint).pathname, authorizationHandler({ provider: options.provider, ...options.authorizationOptions })); + router.use(new URL(oauthMetadata.token_endpoint).pathname, tokenHandler({ provider: options.provider, ...options.tokenOptions })); + router.use(mcpAuthMetadataRouter({ + oauthMetadata, + // Prefer explicit RS; otherwise fall back to AS baseUrl, then to issuer (back-compat) + resourceServerUrl: (_b = (_a = options.resourceServerUrl) !== null && _a !== void 0 ? _a : options.baseUrl) !== null && _b !== void 0 ? _b : new URL(oauthMetadata.issuer), + serviceDocumentationUrl: options.serviceDocumentationUrl, + scopesSupported: options.scopesSupported, + resourceName: options.resourceName + })); + if (oauthMetadata.registration_endpoint) { + router.use(new URL(oauthMetadata.registration_endpoint).pathname, clientRegistrationHandler({ + clientsStore: options.provider.clientsStore, + ...options.clientRegistrationOptions + })); + } + if (oauthMetadata.revocation_endpoint) { + router.use(new URL(oauthMetadata.revocation_endpoint).pathname, revocationHandler({ provider: options.provider, ...options.revocationOptions })); + } + return router; +} +export function mcpAuthMetadataRouter(options) { + var _a; + checkIssuerUrl(new URL(options.oauthMetadata.issuer)); + const router = express.Router(); + const protectedResourceMetadata = { + resource: options.resourceServerUrl.href, + authorization_servers: [options.oauthMetadata.issuer], + scopes_supported: options.scopesSupported, + resource_name: options.resourceName, + resource_documentation: (_a = options.serviceDocumentationUrl) === null || _a === void 0 ? void 0 : _a.href + }; + // Serve PRM at the path-specific URL per RFC 9728 + const rsPath = new URL(options.resourceServerUrl.href).pathname; + router.use(`/.well-known/oauth-protected-resource${rsPath === '/' ? '' : rsPath}`, metadataHandler(protectedResourceMetadata)); + // Always add this for OAuth Authorization Server metadata per RFC 8414 + router.use('/.well-known/oauth-authorization-server', metadataHandler(options.oauthMetadata)); + return router; +} +/** + * Helper function to construct the OAuth 2.0 Protected Resource Metadata URL + * from a given server URL. This replaces the path with the standard metadata endpoint. + * + * @param serverUrl - The base URL of the protected resource server + * @returns The URL for the OAuth protected resource metadata endpoint + * + * @example + * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp')) + * // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp' + */ +export function getOAuthProtectedResourceMetadataUrl(serverUrl) { + const u = new URL(serverUrl.href); + const rsPath = u.pathname && u.pathname !== '/' ? u.pathname : ''; + return new URL(`/.well-known/oauth-protected-resource${rsPath}`, u).href; +} +//# sourceMappingURL=router.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/router.js.map b/dist/esm/server/auth/router.js.map new file mode 100644 index 000000000..018a69ab6 --- /dev/null +++ b/dist/esm/server/auth/router.js.map @@ -0,0 +1 @@ +{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":"AAAA,OAAO,OAA2B,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAoC,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAA+B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAA4B,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzD,sFAAsF;AACtF,MAAM,sBAAsB,GACxB,OAAO,CAAC,GAAG,CAAC,yCAAyC,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,yCAAyC,KAAK,GAAG,CAAC;AACtI,IAAI,sBAAsB,EAAE,CAAC;IACzB,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,gHAAgH,CAAC,CAAC;AACnI,CAAC;AAgDD,MAAM,cAAc,GAAG,CAAC,MAAW,EAAQ,EAAE;IACzC,mHAAmH;IACnH,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChI,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,MAAM,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,4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AE,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAE/H,uEAAuE;IACvE,MAAM,CAAC,GAAG,CAAC,yCAAyC,EAAE,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IAE9F,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oCAAoC,CAAC,SAAc;IAC/D,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAClE,OAAO,IAAI,GAAG,CAAC,wCAAwC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/auth/types.d.ts b/dist/esm/server/auth/types.d.ts new file mode 100644 index 000000000..05ec8485a --- /dev/null +++ b/dist/esm/server/auth/types.d.ts @@ -0,0 +1,32 @@ +/** + * Information about a validated access token, provided to request handlers. + */ +export interface AuthInfo { + /** + * The access token. + */ + token: string; + /** + * The client ID associated with this token. + */ + clientId: string; + /** + * Scopes associated with this token. + */ + scopes: string[]; + /** + * When the token expires (in seconds since epoch). + */ + expiresAt?: number; + /** + * The RFC 8707 resource server identifier for which this token is valid. + * If set, this MUST match the MCP server's resource identifier (minus hash fragment). + */ + resource?: URL; + /** + * Additional data associated with the token. + * This field should be used for any additional data that needs to be attached to the auth info. + */ + extra?: Record; +} +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/auth/types.d.ts.map b/dist/esm/server/auth/types.d.ts.map new file mode 100644 index 000000000..021e94740 --- /dev/null +++ b/dist/esm/server/auth/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"} \ No newline at end of file diff --git a/dist/esm/server/auth/types.js b/dist/esm/server/auth/types.js new file mode 100644 index 000000000..718fd38ae --- /dev/null +++ b/dist/esm/server/auth/types.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/esm/server/auth/types.js.map b/dist/esm/server/auth/types.js.map new file mode 100644 index 000000000..0d8063dee --- /dev/null +++ b/dist/esm/server/auth/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/server/completable.d.ts b/dist/esm/server/completable.d.ts new file mode 100644 index 000000000..1b3159ac8 --- /dev/null +++ b/dist/esm/server/completable.d.ts @@ -0,0 +1,38 @@ +import { AnySchema, SchemaInput } from './zod-compat.js'; +export declare const COMPLETABLE_SYMBOL: unique symbol; +export type CompleteCallback = (value: SchemaInput, context?: { + arguments?: Record; +}) => SchemaInput[] | Promise[]>; +export type CompletableMeta = { + complete: CompleteCallback; +}; +export type CompletableSchema = T & { + [COMPLETABLE_SYMBOL]: CompletableMeta; +}; +/** + * Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP. + * Works with both Zod v3 and v4 schemas. + */ +export declare function completable(schema: T, complete: CompleteCallback): CompletableSchema; +/** + * Checks if a schema is completable (has completion metadata). + */ +export declare function isCompletable(schema: unknown): schema is CompletableSchema; +/** + * Gets the completer callback from a completable schema, if it exists. + */ +export declare function getCompleter(schema: T): CompleteCallback | undefined; +/** + * Unwraps a completable schema to get the underlying schema. + * For backward compatibility with code that called `.unwrap()`. + */ +export declare function unwrapCompletable(schema: CompletableSchema): T; +export declare enum McpZodTypeKind { + Completable = "McpCompletable" +} +export interface CompletableDef { + type: T; + complete: CompleteCallback; + typeName: McpZodTypeKind.Completable; +} +//# sourceMappingURL=completable.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/completable.d.ts.map b/dist/esm/server/completable.d.ts.map new file mode 100644 index 000000000..83ea2f1e2 --- /dev/null +++ b/dist/esm/server/completable.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"completable.d.ts","sourceRoot":"","sources":["../../../src/server/completable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAAsC,CAAC;AAE/E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,CAC5D,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE;IACN,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,KACA,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI;IAC3D,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GAAG;IACrD,CAAC,kBAAkB,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAQ/G;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAErF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAG5F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAEtF;AAID,oBAAY,cAAc;IACtB,WAAW,mBAAmB;CACjC;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC3D,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,cAAc,CAAC,WAAW,CAAC;CACxC"} \ No newline at end of file diff --git a/dist/esm/server/completable.js b/dist/esm/server/completable.js new file mode 100644 index 000000000..4f636e3ea --- /dev/null +++ b/dist/esm/server/completable.js @@ -0,0 +1,41 @@ +export const COMPLETABLE_SYMBOL = Symbol.for('mcp.completable'); +/** + * Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP. + * Works with both Zod v3 and v4 schemas. + */ +export function completable(schema, complete) { + Object.defineProperty(schema, COMPLETABLE_SYMBOL, { + value: { complete }, + enumerable: false, + writable: false, + configurable: false + }); + return schema; +} +/** + * Checks if a schema is completable (has completion metadata). + */ +export function isCompletable(schema) { + return !!schema && typeof schema === 'object' && COMPLETABLE_SYMBOL in schema; +} +/** + * Gets the completer callback from a completable schema, if it exists. + */ +export function getCompleter(schema) { + const meta = schema[COMPLETABLE_SYMBOL]; + return meta === null || meta === void 0 ? void 0 : meta.complete; +} +/** + * Unwraps a completable schema to get the underlying schema. + * For backward compatibility with code that called `.unwrap()`. + */ +export function unwrapCompletable(schema) { + return schema; +} +// Legacy exports for backward compatibility +// These types are deprecated but kept for existing code +export var McpZodTypeKind; +(function (McpZodTypeKind) { + McpZodTypeKind["Completable"] = "McpCompletable"; +})(McpZodTypeKind || (McpZodTypeKind = {})); +//# sourceMappingURL=completable.js.map \ No newline at end of file diff --git a/dist/esm/server/completable.js.map b/dist/esm/server/completable.js.map new file mode 100644 index 000000000..d8700d494 --- /dev/null +++ b/dist/esm/server/completable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"completable.js","sourceRoot":"","sources":["../../../src/server/completable.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAiB/E;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAsB,MAAS,EAAE,QAA6B;IACrF,MAAM,CAAC,cAAc,CAAC,MAAgB,EAAE,kBAAkB,EAAE;QACxD,KAAK,EAAE,EAAE,QAAQ,EAAwB;QACzC,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;KACtB,CAAC,CAAC;IACH,OAAO,MAA8B,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IACzC,OAAO,CAAC,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,kBAAkB,IAAK,MAAiB,CAAC;AAC9F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAsB,MAAS;IACvD,MAAM,IAAI,GAAI,MAAmE,CAAC,kBAAkB,CAAC,CAAC;IACtG,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAA2C,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAsB,MAA4B;IAC/E,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,4CAA4C;AAC5C,wDAAwD;AACxD,MAAM,CAAN,IAAY,cAEX;AAFD,WAAY,cAAc;IACtB,gDAA8B,CAAA;AAClC,CAAC,EAFW,cAAc,KAAd,cAAc,QAEzB"} \ No newline at end of file diff --git a/dist/esm/server/index.d.ts b/dist/esm/server/index.d.ts new file mode 100644 index 000000000..e093d20eb --- /dev/null +++ b/dist/esm/server/index.d.ts @@ -0,0 +1,358 @@ +import { Protocol, type NotificationOptions, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js'; +import { type ClientCapabilities, type CreateMessageRequest, type ElicitRequestFormParams, type ElicitRequestURLParams, type ElicitResult, type Implementation, type ListRootsRequest, type LoggingMessageNotification, type Notification, type Request, type ResourceUpdatedNotification, type Result, type ServerCapabilities, type ServerNotification, type ServerRequest, type ServerResult } from '../types.js'; +import type { jsonSchemaValidator } from '../validation/types.js'; +import { AnyObjectSchema, SchemaOutput } from './zod-compat.js'; +import { RequestHandlerExtra } from '../shared/protocol.js'; +import { ExperimentalServerTasks } from '../experimental/tasks/server.js'; +export type ServerOptions = ProtocolOptions & { + /** + * Capabilities to advertise as being supported by this server. + */ + capabilities?: ServerCapabilities; + /** + * Optional instructions describing how to use the server and its features. + */ + instructions?: string; + /** + * JSON Schema validator for elicitation response validation. + * + * The validator is used to validate user input returned from elicitation + * requests against the requested schema. + * + * @default AjvJsonSchemaValidator + * + * @example + * ```typescript + * // ajv (default) + * const server = new Server( + * { name: 'my-server', version: '1.0.0' }, + * { + * capabilities: {} + * jsonSchemaValidator: new AjvJsonSchemaValidator() + * } + * ); + * + * // @cfworker/json-schema + * const server = new Server( + * { name: 'my-server', version: '1.0.0' }, + * { + * capabilities: {}, + * jsonSchemaValidator: new CfWorkerJsonSchemaValidator() + * } + * ); + * ``` + */ + jsonSchemaValidator?: jsonSchemaValidator; +}; +/** + * An MCP server on top of a pluggable transport. + * + * This server will automatically respond to the initialization flow as initiated from the client. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed server + * const server = new Server({ + * name: "CustomServer", + * version: "1.0.0" + * }) + * ``` + * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases. + */ +export declare class Server extends Protocol { + private _serverInfo; + private _clientCapabilities?; + private _clientVersion?; + private _capabilities; + private _instructions?; + private _jsonSchemaValidator; + private _experimental?; + /** + * Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification). + */ + oninitialized?: () => void; + /** + * Initializes this server with the given name and version information. + */ + constructor(_serverInfo: Implementation, options?: ServerOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalServerTasks; + }; + private _loggingLevels; + private readonly LOG_LEVEL_SEVERITY; + private isMessageIgnored; + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities: ServerCapabilities): void; + /** + * Override request handler registration to enforce server-side validation for tools/call. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => ServerResult | ResultT | Promise): void; + protected assertCapabilityForMethod(method: RequestT['method']): void; + protected assertNotificationCapability(method: (ServerNotification | NotificationT)['method']): void; + protected assertRequestHandlerCapability(method: string): void; + protected assertTaskCapability(method: string): void; + protected assertTaskHandlerCapability(method: string): void; + private _oninitialize; + /** + * After initialization has completed, this will be populated with the client's reported capabilities. + */ + getClientCapabilities(): ClientCapabilities | undefined; + /** + * After initialization has completed, this will be populated with information about the client's name and version. + */ + getClientVersion(): Implementation | undefined; + private getCapabilities; + ping(): Promise<{ + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + model: string; + role: "user" | "assistant"; + content: { + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + [x: string]: unknown; + type: "tool_use"; + name: string; + id: string; + input: { + [x: string]: unknown; + }; + _meta?: { + [x: string]: unknown; + } | undefined; + } | { + [x: string]: unknown; + type: "tool_result"; + toolUseId: string; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + structuredContent?: { + [x: string]: unknown; + } | undefined; + isError?: boolean | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + } | ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + [x: string]: unknown; + type: "tool_use"; + name: string; + id: string; + input: { + [x: string]: unknown; + }; + _meta?: { + [x: string]: unknown; + } | undefined; + } | { + [x: string]: unknown; + type: "tool_result"; + toolUseId: string; + content: ({ + type: "text"; + text: string; + _meta?: Record | undefined; + } | { + type: "image"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "audio"; + data: string; + mimeType: string; + _meta?: Record | undefined; + } | { + type: "resource"; + resource: { + uri: string; + text: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + } | { + uri: string; + blob: string; + mimeType?: string | undefined; + _meta?: Record | undefined; + }; + _meta?: Record | undefined; + } | { + uri: string; + name: string; + type: "resource_link"; + description?: string | undefined; + mimeType?: string | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + icons?: { + src: string; + mimeType?: string | undefined; + sizes?: string[] | undefined; + }[] | undefined; + title?: string | undefined; + })[]; + structuredContent?: { + [x: string]: unknown; + } | undefined; + isError?: boolean | undefined; + _meta?: { + [x: string]: unknown; + } | undefined; + })[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + stopReason?: string | undefined; + }>; + /** + * Creates an elicitation request for the given parameters. + * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`. + * @param params The parameters for the elicitation request. + * @param options Optional request options. + * @returns The result of the elicitation request. + */ + elicitInput(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise; + /** + * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete` + * notification for the specified elicitation ID. + * + * @param elicitationId The ID of the elicitation to mark as complete. + * @param options Optional notification options. Useful when the completion notification should be related to a prior request. + * @returns A function that emits the completion notification when awaited. + */ + createElicitationCompletionNotifier(elicitationId: string, options?: NotificationOptions): () => Promise; + listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<{ + [x: string]: unknown; + roots: { + uri: string; + name?: string | undefined; + _meta?: Record | undefined; + }[]; + _meta?: { + [x: string]: unknown; + "io.modelcontextprotocol/related-task"?: { + [x: string]: unknown; + taskId: string; + } | undefined; + } | undefined; + }>; + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise; + sendResourceUpdated(params: ResourceUpdatedNotification['params']): Promise; + sendResourceListChanged(): Promise; + sendToolListChanged(): Promise; + sendPromptListChanged(): Promise; +} +export type { SessionStore, SessionData, SessionStorageMode } from './streamableHttp.js'; +export { RedisSessionStore, InMemorySessionStore } from './session-stores/redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './session-stores/redis.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/index.d.ts.map b/dist/esm/server/index.d.ts.map new file mode 100644 index 000000000..2acfb7162 --- /dev/null +++ b/dist/esm/server/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzI,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAIjB,KAAK,cAAc,EAMnB,KAAK,gBAAgB,EAIrB,KAAK,0BAA0B,EAE/B,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,2BAA2B,EAChC,KAAK,MAAM,EACX,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EAQpB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAkB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EACH,eAAe,EAIf,YAAY,EAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO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,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAgD5H;;;;;;;OAOG;IACH,mCAAmC,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;IAiBxG,SAAS,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;IAI7E;;;;;;OAMG;IACG,kBAAkB,CAAC,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM;IAQnF,mBAAmB,CAAC,MAAM,EAAE,2BAA2B,CAAC,QAAQ,CAAC;IAOjE,uBAAuB;IAMvB,mBAAmB;IAInB,qBAAqB;CAG9B;AAGD,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACpF,YAAY,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/index.js b/dist/esm/server/index.js new file mode 100644 index 000000000..5f8c05228 --- /dev/null +++ b/dist/esm/server/index.js @@ -0,0 +1,446 @@ +import { mergeCapabilities, Protocol } from '../shared/protocol.js'; +import { CreateMessageResultSchema, ElicitResultSchema, EmptyResultSchema, ErrorCode, InitializedNotificationSchema, InitializeRequestSchema, LATEST_PROTOCOL_VERSION, ListRootsResultSchema, LoggingLevelSchema, McpError, SetLevelRequestSchema, SUPPORTED_PROTOCOL_VERSIONS, CallToolRequestSchema, CallToolResultSchema, CreateTaskResultSchema } from '../types.js'; +import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js'; +import { getObjectShape, isZ4Schema, safeParse } from './zod-compat.js'; +import { ExperimentalServerTasks } from '../experimental/tasks/server.js'; +import { assertToolsCallTaskCapability, assertClientRequestTaskCapability } from '../experimental/tasks/helpers.js'; +/** + * An MCP server on top of a pluggable transport. + * + * This server will automatically respond to the initialization flow as initiated from the client. + * + * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters: + * + * ```typescript + * // Custom schemas + * const CustomRequestSchema = RequestSchema.extend({...}) + * const CustomNotificationSchema = NotificationSchema.extend({...}) + * const CustomResultSchema = ResultSchema.extend({...}) + * + * // Type aliases + * type CustomRequest = z.infer + * type CustomNotification = z.infer + * type CustomResult = z.infer + * + * // Create typed server + * const server = new Server({ + * name: "CustomServer", + * version: "1.0.0" + * }) + * ``` + * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases. + */ +export class Server extends Protocol { + /** + * Initializes this server with the given name and version information. + */ + constructor(_serverInfo, options) { + var _a, _b; + super(options); + this._serverInfo = _serverInfo; + // Map log levels by session id + this._loggingLevels = new Map(); + // Map LogLevelSchema to severity index + this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index])); + // Is a message with the given level ignored in the log level set for the given session id? + this.isMessageIgnored = (level, sessionId) => { + const currentLevel = this._loggingLevels.get(sessionId); + return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false; + }; + this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {}; + this._instructions = options === null || options === void 0 ? void 0 : options.instructions; + this._jsonSchemaValidator = (_b = options === null || options === void 0 ? void 0 : options.jsonSchemaValidator) !== null && _b !== void 0 ? _b : new AjvJsonSchemaValidator(); + this.setRequestHandler(InitializeRequestSchema, request => this._oninitialize(request)); + this.setNotificationHandler(InitializedNotificationSchema, () => { var _a; return (_a = this.oninitialized) === null || _a === void 0 ? void 0 : _a.call(this); }); + if (this._capabilities.logging) { + this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => { + var _a; + const transportSessionId = extra.sessionId || ((_a = extra.requestInfo) === null || _a === void 0 ? void 0 : _a.headers['mcp-session-id']) || undefined; + const { level } = request.params; + const parseResult = LoggingLevelSchema.safeParse(level); + if (parseResult.success) { + this._loggingLevels.set(transportSessionId, parseResult.data); + } + return {}; + }); + } + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new ExperimentalServerTasks(this) + }; + } + return this._experimental; + } + /** + * Registers new capabilities. This can only be called before connecting to a transport. + * + * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization). + */ + registerCapabilities(capabilities) { + if (this.transport) { + throw new Error('Cannot register capabilities after connecting to transport'); + } + this._capabilities = mergeCapabilities(this._capabilities, capabilities); + } + /** + * Override request handler registration to enforce server-side validation for tools/call. + */ + setRequestHandler(requestSchema, handler) { + var _a, _b, _c; + const shape = getObjectShape(requestSchema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value using type-safe property access + let methodValue; + if (isZ4Schema(methodSchema)) { + const v4Schema = methodSchema; + const v4Def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + methodValue = (_b = v4Def === null || v4Def === void 0 ? void 0 : v4Def.value) !== null && _b !== void 0 ? _b : v4Schema.value; + } + else { + const v3Schema = methodSchema; + const legacyDef = v3Schema._def; + methodValue = (_c = legacyDef === null || legacyDef === void 0 ? void 0 : legacyDef.value) !== null && _c !== void 0 ? _c : v3Schema.value; + } + if (typeof methodValue !== 'string') { + throw new Error('Schema method literal must be a string'); + } + const method = methodValue; + if (method === 'tools/call') { + const wrappedHandler = async (request, extra) => { + const validatedRequest = safeParse(CallToolRequestSchema, request); + if (!validatedRequest.success) { + const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`); + } + const { params } = validatedRequest.data; + const result = await Promise.resolve(handler(request, extra)); + // When task creation is requested, validate and return CreateTaskResult + if (params.task) { + const taskValidationResult = safeParse(CreateTaskResultSchema, result); + if (!taskValidationResult.success) { + const errorMessage = taskValidationResult.error instanceof Error + ? taskValidationResult.error.message + : String(taskValidationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`); + } + return taskValidationResult.data; + } + // For non-task requests, validate against CallToolResultSchema + const validationResult = safeParse(CallToolResultSchema, result); + if (!validationResult.success) { + const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error); + throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`); + } + return validationResult.data; + }; + // Install the wrapped handler + return super.setRequestHandler(requestSchema, wrappedHandler); + } + // Other handlers use default behavior + return super.setRequestHandler(requestSchema, handler); + } + assertCapabilityForMethod(method) { + var _a, _b, _c; + switch (method) { + case 'sampling/createMessage': + if (!((_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling)) { + throw new Error(`Client does not support sampling (required for ${method})`); + } + break; + case 'elicitation/create': + if (!((_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation)) { + throw new Error(`Client does not support elicitation (required for ${method})`); + } + break; + case 'roots/list': + if (!((_c = this._clientCapabilities) === null || _c === void 0 ? void 0 : _c.roots)) { + throw new Error(`Client does not support listing roots (required for ${method})`); + } + break; + case 'ping': + // No specific capability required for ping + break; + } + } + assertNotificationCapability(method) { + var _a, _b; + switch (method) { + case 'notifications/message': + if (!this._capabilities.logging) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'notifications/resources/updated': + case 'notifications/resources/list_changed': + if (!this._capabilities.resources) { + throw new Error(`Server does not support notifying about resources (required for ${method})`); + } + break; + case 'notifications/tools/list_changed': + if (!this._capabilities.tools) { + throw new Error(`Server does not support notifying of tool list changes (required for ${method})`); + } + break; + case 'notifications/prompts/list_changed': + if (!this._capabilities.prompts) { + throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`); + } + break; + case 'notifications/elicitation/complete': + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) { + throw new Error(`Client does not support URL elicitation (required for ${method})`); + } + break; + case 'notifications/cancelled': + // Cancellation notifications are always allowed + break; + case 'notifications/progress': + // Progress notifications are always allowed + break; + } + } + assertRequestHandlerCapability(method) { + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + switch (method) { + case 'completion/complete': + if (!this._capabilities.completions) { + throw new Error(`Server does not support completions (required for ${method})`); + } + break; + case 'logging/setLevel': + if (!this._capabilities.logging) { + throw new Error(`Server does not support logging (required for ${method})`); + } + break; + case 'prompts/get': + case 'prompts/list': + if (!this._capabilities.prompts) { + throw new Error(`Server does not support prompts (required for ${method})`); + } + break; + case 'resources/list': + case 'resources/templates/list': + case 'resources/read': + if (!this._capabilities.resources) { + throw new Error(`Server does not support resources (required for ${method})`); + } + break; + case 'tools/call': + case 'tools/list': + if (!this._capabilities.tools) { + throw new Error(`Server does not support tools (required for ${method})`); + } + break; + case 'tasks/get': + case 'tasks/list': + case 'tasks/result': + case 'tasks/cancel': + if (!this._capabilities.tasks) { + throw new Error(`Server does not support tasks capability (required for ${method})`); + } + break; + case 'ping': + case 'initialize': + // No specific capability required for these methods + break; + } + } + assertTaskCapability(method) { + var _a, _b; + assertClientRequestTaskCapability((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.requests, method, 'Client'); + } + assertTaskHandlerCapability(method) { + var _a; + // Task handlers are registered in Protocol constructor before _capabilities is initialized + // Skip capability check for task methods during initialization + if (!this._capabilities) { + return; + } + assertToolsCallTaskCapability((_a = this._capabilities.tasks) === null || _a === void 0 ? void 0 : _a.requests, method, 'Server'); + } + async _oninitialize(request) { + const requestedVersion = request.params.protocolVersion; + this._clientCapabilities = request.params.capabilities; + this._clientVersion = request.params.clientInfo; + const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION; + return { + protocolVersion, + capabilities: this.getCapabilities(), + serverInfo: this._serverInfo, + ...(this._instructions && { instructions: this._instructions }) + }; + } + /** + * After initialization has completed, this will be populated with the client's reported capabilities. + */ + getClientCapabilities() { + return this._clientCapabilities; + } + /** + * After initialization has completed, this will be populated with information about the client's name and version. + */ + getClientVersion() { + return this._clientVersion; + } + getCapabilities() { + return this._capabilities; + } + async ping() { + return this.request({ method: 'ping' }, EmptyResultSchema); + } + async createMessage(params, options) { + var _a, _b; + // Capability check - only required when tools/toolChoice are provided + if (params.tools || params.toolChoice) { + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.sampling) === null || _b === void 0 ? void 0 : _b.tools)) { + throw new Error('Client does not support sampling tools capability.'); + } + } + // Message structure validation - always validate tool_use/tool_result pairs. + // These may appear even without tools/toolChoice in the current request when + // a previous sampling request returned tool_use and this is a follow-up with results. + if (params.messages.length > 0) { + const lastMessage = params.messages[params.messages.length - 1]; + const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content]; + const hasToolResults = lastContent.some(c => c.type === 'tool_result'); + const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : undefined; + const previousContent = previousMessage + ? Array.isArray(previousMessage.content) + ? previousMessage.content + : [previousMessage.content] + : []; + const hasPreviousToolUse = previousContent.some(c => c.type === 'tool_use'); + if (hasToolResults) { + if (lastContent.some(c => c.type !== 'tool_result')) { + throw new Error('The last message must contain only tool_result content if any is present'); + } + if (!hasPreviousToolUse) { + throw new Error('tool_result blocks are not matching any tool_use from the previous message'); + } + } + if (hasPreviousToolUse) { + const toolUseIds = new Set(previousContent.filter(c => c.type === 'tool_use').map(c => c.id)); + const toolResultIds = new Set(lastContent.filter(c => c.type === 'tool_result').map(c => c.toolUseId)); + if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every(id => toolResultIds.has(id))) { + throw new Error('ids of tool_result blocks and tool_use blocks from previous message do not match'); + } + } + } + return this.request({ method: 'sampling/createMessage', params }, CreateMessageResultSchema, options); + } + /** + * Creates an elicitation request for the given parameters. + * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`. + * @param params The parameters for the elicitation request. + * @param options Optional request options. + * @returns The result of the elicitation request. + */ + async elicitInput(params, options) { + var _a, _b, _c, _d, _e; + const mode = ((_a = params.mode) !== null && _a !== void 0 ? _a : 'form'); + switch (mode) { + case 'url': { + if (!((_c = (_b = this._clientCapabilities) === null || _b === void 0 ? void 0 : _b.elicitation) === null || _c === void 0 ? void 0 : _c.url)) { + throw new Error('Client does not support url elicitation.'); + } + const urlParams = params; + return this.request({ method: 'elicitation/create', params: urlParams }, ElicitResultSchema, options); + } + case 'form': { + if (!((_e = (_d = this._clientCapabilities) === null || _d === void 0 ? void 0 : _d.elicitation) === null || _e === void 0 ? void 0 : _e.form)) { + throw new Error('Client does not support form elicitation.'); + } + const formParams = params.mode === 'form' ? params : { ...params, mode: 'form' }; + const result = await this.request({ method: 'elicitation/create', params: formParams }, ElicitResultSchema, options); + if (result.action === 'accept' && result.content && formParams.requestedSchema) { + try { + const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema); + const validationResult = validator(result.content); + if (!validationResult.valid) { + throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`); + } + } + catch (error) { + if (error instanceof McpError) { + throw error; + } + throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`); + } + } + return result; + } + } + } + /** + * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete` + * notification for the specified elicitation ID. + * + * @param elicitationId The ID of the elicitation to mark as complete. + * @param options Optional notification options. Useful when the completion notification should be related to a prior request. + * @returns A function that emits the completion notification when awaited. + */ + createElicitationCompletionNotifier(elicitationId, options) { + var _a, _b; + if (!((_b = (_a = this._clientCapabilities) === null || _a === void 0 ? void 0 : _a.elicitation) === null || _b === void 0 ? void 0 : _b.url)) { + throw new Error('Client does not support URL elicitation (required for notifications/elicitation/complete)'); + } + return () => this.notification({ + method: 'notifications/elicitation/complete', + params: { + elicitationId + } + }, options); + } + async listRoots(params, options) { + return this.request({ method: 'roots/list', params }, ListRootsResultSchema, options); + } + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + async sendLoggingMessage(params, sessionId) { + if (this._capabilities.logging) { + if (!this.isMessageIgnored(params.level, sessionId)) { + return this.notification({ method: 'notifications/message', params }); + } + } + } + async sendResourceUpdated(params) { + return this.notification({ + method: 'notifications/resources/updated', + params + }); + } + async sendResourceListChanged() { + return this.notification({ + method: 'notifications/resources/list_changed' + }); + } + async sendToolListChanged() { + return this.notification({ method: 'notifications/tools/list_changed' }); + } + async sendPromptListChanged() { + return this.notification({ method: 'notifications/prompts/list_changed' }); + } +} +export { RedisSessionStore, InMemorySessionStore } from './session-stores/redis.js'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/server/index.js.map b/dist/esm/server/index.js.map new file mode 100644 index 000000000..0d16e6f23 --- /dev/null +++ b/dist/esm/server/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAuE,MAAM,uBAAuB,CAAC;AACzI,OAAO,EAGH,yBAAyB,EAIzB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EAET,6BAA6B,EAE7B,uBAAuB,EAEvB,uBAAuB,EAEvB,qBAAqB,EAErB,kBAAkB,EAElB,QAAQ,EASR,qBAAqB,EACrB,2BAA2B,EAG3B,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACzB,MAAM,aAAa,CAAC;AACrB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 index 000000000..1bc0c6829 --- /dev/null +++ b/dist/esm/server/mcp.d.ts @@ -0,0 +1,364 @@ +import { Server, ServerOptions } from './index.js'; +import { AnySchema, AnyObjectSchema, ZodRawShapeCompat, SchemaOutput, ShapeOutput } from './zod-compat.js'; +import { Implementation, CallToolResult, Resource, ListResourcesResult, GetPromptResult, ReadResourceResult, ServerRequest, ServerNotification, ToolAnnotations, LoggingMessageNotification, Result, ToolExecution } from '../types.js'; +import { UriTemplate, Variables } from '../shared/uriTemplate.js'; +import { RequestHandlerExtra } from '../shared/protocol.js'; +import { Transport } from '../shared/transport.js'; +import { ExperimentalMcpServerTasks } from '../experimental/tasks/mcp-server.js'; +import type { ToolTaskHandler } from '../experimental/tasks/interfaces.js'; +/** + * High-level MCP server that provides a simpler API for working with resources, tools, and prompts. + * For advanced usage (like sending notifications or setting custom request handlers), use the underlying + * Server instance available via the `server` property. + */ +export declare class McpServer { + /** + * The underlying Server instance, useful for advanced operations like sending notifications. + */ + readonly server: Server; + private _registeredResources; + private _registeredResourceTemplates; + private _registeredTools; + private _registeredPrompts; + private _experimental?; + constructor(serverInfo: Implementation, options?: ServerOptions); + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental(): { + tasks: ExperimentalMcpServerTasks; + }; + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + connect(transport: Transport): Promise; + /** + * Closes the connection. + */ + close(): Promise; + private _toolHandlersInitialized; + private setToolRequestHandlers; + /** + * Creates a tool error result. + * + * @param errorMessage - The error message. + * @returns The tool error result. + */ + private createToolError; + /** + * Validates tool input arguments against the tool's input schema. + */ + private validateToolInput; + /** + * Validates tool output against the tool's output schema. + */ + private validateToolOutput; + /** + * Executes a tool handler (either regular or task-based). + */ + private executeToolHandler; + /** + * Handles automatic task polling for tools with taskSupport 'optional'. + */ + private handleAutomaticTaskPolling; + private _completionHandlerInitialized; + private setCompletionRequestHandler; + private handlePromptCompletion; + private handleResourceCompletion; + private _resourceHandlersInitialized; + private setResourceRequestHandlers; + private _promptHandlersInitialized; + private setPromptRequestHandlers; + /** + * Registers a resource `name` at a fixed URI, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, uri: string, readCallback: ReadResourceCallback): RegisteredResource; + /** + * Registers a resource `name` at a fixed URI with metadata, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, uri: string, metadata: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; + /** + * Registers a resource `name` with a template pattern, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, template: ResourceTemplate, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + /** + * Registers a resource `name` with a template pattern and metadata, which will use the given callback to respond to read requests. + * @deprecated Use `registerResource` instead. + */ + resource(name: string, template: ResourceTemplate, metadata: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + /** + * Registers a resource with a config object and callback. + * For static resources, use a URI string. For dynamic resources, use a ResourceTemplate. + */ + registerResource(name: string, uriOrTemplate: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; + registerResource(name: string, uriOrTemplate: ResourceTemplate, config: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; + private _createRegisteredResource; + private _createRegisteredResourceTemplate; + private _createRegisteredPrompt; + private _createRegisteredTool; + /** + * Registers a zero-argument tool `name`, which will run the given function when the client calls it. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, cb: ToolCallback): RegisteredTool; + /** + * Registers a zero-argument tool `name` (with a description) which will run the given function when the client calls it. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool taking either a parameter schema for validation or annotations for additional metadata. + * This unified overload handles both `tool(name, paramsSchema, cb)` and `tool(name, annotations, cb)` cases. + * + * Note: We use a union type for the second parameter because TypeScript cannot reliably disambiguate + * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool `name` (with a description) taking either parameter schema or annotations. + * This unified overload handles both `tool(name, description, paramsSchema, cb)` and + * `tool(name, description, annotations, cb)` cases. + * + * Note: We use a union type for the third parameter because TypeScript cannot reliably disambiguate + * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with both parameter schema and annotations. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with description, parameter schema, and annotations. + * @deprecated Use `registerTool` instead. + */ + tool(name: string, description: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback): RegisteredTool; + /** + * Registers a tool with a config object and callback. + */ + registerTool(name: string, config: { + title?: string; + description?: string; + inputSchema?: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + _meta?: Record; + }, cb: ToolCallback): RegisteredTool; + /** + * Registers a zero-argument prompt `name`, which will run the given function when the client calls it. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a zero-argument prompt `name` (with a description) which will run the given function when the client calls it. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, description: string, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, argsSchema: Args, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. + * @deprecated Use `registerPrompt` instead. + */ + prompt(name: string, description: string, argsSchema: Args, cb: PromptCallback): RegisteredPrompt; + /** + * Registers a prompt with a config object and callback. + */ + registerPrompt(name: string, config: { + title?: string; + description?: string; + argsSchema?: Args; + }, cb: PromptCallback): RegisteredPrompt; + /** + * Checks if the server is connected to a transport. + * @returns True if the server is connected + */ + isConnected(): boolean; + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise; + /** + * Sends a resource list changed event to the client, if connected. + */ + sendResourceListChanged(): void; + /** + * Sends a tool list changed event to the client, if connected. + */ + sendToolListChanged(): void; + /** + * Sends a prompt list changed event to the client, if connected. + */ + sendPromptListChanged(): void; +} +/** + * A callback to complete one variable within a resource template's URI template. + */ +export type CompleteResourceTemplateCallback = (value: string, context?: { + arguments?: Record; +}) => string[] | Promise; +/** + * A resource template combines a URI pattern with optional functionality to enumerate + * all resources matching that pattern. + */ +export declare class ResourceTemplate { + private _callbacks; + private _uriTemplate; + constructor(uriTemplate: string | UriTemplate, _callbacks: { + /** + * A callback to list all resources matching this template. This is required to specified, even if `undefined`, to avoid accidentally forgetting resource listing. + */ + list: ListResourcesCallback | undefined; + /** + * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values. + */ + complete?: { + [variable: string]: CompleteResourceTemplateCallback; + }; + }); + /** + * Gets the URI template pattern. + */ + get uriTemplate(): UriTemplate; + /** + * Gets the list callback, if one was provided. + */ + get listCallback(): ListResourcesCallback | undefined; + /** + * Gets the callback for completing a specific URI template variable, if one was provided. + */ + completeCallback(variable: string): CompleteResourceTemplateCallback | undefined; +} +export type BaseToolCallback, Args extends undefined | ZodRawShapeCompat | AnySchema> = Args extends ZodRawShapeCompat ? (args: ShapeOutput, extra: Extra) => SendResultT | Promise : Args extends AnySchema ? (args: SchemaOutput, extra: Extra) => SendResultT | Promise : (extra: Extra) => SendResultT | Promise; +/** + * Callback for a tool handler registered with Server.tool(). + * + * Parameters will include tool arguments, if applicable, as well as other request handler context. + * + * The callback should return: + * - `structuredContent` if the tool has an outputSchema defined + * - `content` if the tool does not have an outputSchema + * - Both fields are optional but typically one should be provided + */ +export type ToolCallback = BaseToolCallback, Args>; +/** + * Supertype that can handle both regular tools (simple callback) and task-based tools (task handler object). + */ +export type AnyToolHandler = ToolCallback | ToolTaskHandler; +export type RegisteredTool = { + title?: string; + description?: string; + inputSchema?: AnySchema; + outputSchema?: AnySchema; + annotations?: ToolAnnotations; + execution?: ToolExecution; + _meta?: Record; + handler: AnyToolHandler; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + description?: string; + paramsSchema?: InputArgs; + outputSchema?: OutputArgs; + annotations?: ToolAnnotations; + _meta?: Record; + callback?: ToolCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +/** + * Additional, optional information for annotating a resource. + */ +export type ResourceMetadata = Omit; +/** + * Callback to list all resources matching a given template. + */ +export type ListResourcesCallback = (extra: RequestHandlerExtra) => ListResourcesResult | Promise; +/** + * Callback to read a resource at a given URI. + */ +export type ReadResourceCallback = (uri: URL, extra: RequestHandlerExtra) => ReadResourceResult | Promise; +export type RegisteredResource = { + name: string; + title?: string; + metadata?: ResourceMetadata; + readCallback: ReadResourceCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string; + title?: string; + uri?: string | null; + metadata?: ResourceMetadata; + callback?: ReadResourceCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +/** + * Callback to read a resource at a given URI, following a filled-in URI template. + */ +export type ReadResourceTemplateCallback = (uri: URL, variables: Variables, extra: RequestHandlerExtra) => ReadResourceResult | Promise; +export type RegisteredResourceTemplate = { + resourceTemplate: ResourceTemplate; + title?: string; + metadata?: ResourceMetadata; + readCallback: ReadResourceTemplateCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + template?: ResourceTemplate; + metadata?: ResourceMetadata; + callback?: ReadResourceTemplateCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +type PromptArgsRawShape = ZodRawShapeCompat; +export type PromptCallback = Args extends PromptArgsRawShape ? (args: ShapeOutput, extra: RequestHandlerExtra) => GetPromptResult | Promise : (extra: RequestHandlerExtra) => GetPromptResult | Promise; +export type RegisteredPrompt = { + title?: string; + description?: string; + argsSchema?: AnyObjectSchema; + callback: PromptCallback; + enabled: boolean; + enable(): void; + disable(): void; + update(updates: { + name?: string | null; + title?: string; + description?: string; + argsSchema?: Args; + callback?: PromptCallback; + enabled?: boolean; + }): void; + remove(): void; +}; +export {}; +//# sourceMappingURL=mcp.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/mcp.d.ts.map b/dist/esm/server/mcp.d.ts.map new file mode 100644 index 000000000..d5815c38a --- /dev/null +++ b/dist/esm/server/mcp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACH,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,WAAW,EASd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,cAAc,EAGd,cAAc,EAOd,QAAQ,EACR,mBAAmB,EAYnB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,0BAA0B,EAE1B,MAAM,EAMN,aAAa,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,M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C,EAAE,IAAI,CAAC;QAClB,QAAQ,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,IAAI,CAAC;IACT,MAAM,IAAI,IAAI,CAAC;CAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/mcp.js b/dist/esm/server/mcp.js new file mode 100644 index 000000000..65b2a39b9 --- /dev/null +++ b/dist/esm/server/mcp.js @@ -0,0 +1,870 @@ +import { Server } from './index.js'; +import { normalizeObjectSchema, safeParseAsync, getObjectShape, objectFromShape, getParseErrorMessage, getSchemaDescription, isSchemaOptional, getLiteralValue } from './zod-compat.js'; +import { toJsonSchemaCompat } from './zod-json-schema-compat.js'; +import { McpError, ErrorCode, ListResourceTemplatesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, CompleteRequestSchema, assertCompleteRequestPrompt, assertCompleteRequestResourceTemplate } from '../types.js'; +import { isCompletable, getCompleter } from './completable.js'; +import { UriTemplate } from '../shared/uriTemplate.js'; +import { validateAndWarnToolName } from '../shared/toolNameValidation.js'; +import { ExperimentalMcpServerTasks } from '../experimental/tasks/mcp-server.js'; +/** + * High-level MCP server that provides a simpler API for working with resources, tools, and prompts. + * For advanced usage (like sending notifications or setting custom request handlers), use the underlying + * Server instance available via the `server` property. + */ +export class McpServer { + constructor(serverInfo, options) { + this._registeredResources = {}; + this._registeredResourceTemplates = {}; + this._registeredTools = {}; + this._registeredPrompts = {}; + this._toolHandlersInitialized = false; + this._completionHandlerInitialized = false; + this._resourceHandlersInitialized = false; + this._promptHandlersInitialized = false; + this.server = new Server(serverInfo, options); + } + /** + * Access experimental features. + * + * WARNING: These APIs are experimental and may change without notice. + * + * @experimental + */ + get experimental() { + if (!this._experimental) { + this._experimental = { + tasks: new ExperimentalMcpServerTasks(this) + }; + } + return this._experimental; + } + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + async connect(transport) { + return await this.server.connect(transport); + } + /** + * Closes the connection. + */ + async close() { + await this.server.close(); + } + setToolRequestHandlers() { + if (this._toolHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(ListToolsRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(CallToolRequestSchema)); + this.server.registerCapabilities({ + tools: { + listChanged: true + } + }); + this.server.setRequestHandler(ListToolsRequestSchema, () => ({ + tools: Object.entries(this._registeredTools) + .filter(([, tool]) => tool.enabled) + .map(([name, tool]) => { + const toolDefinition = { + name, + title: tool.title, + description: tool.description, + inputSchema: (() => { + const obj = normalizeObjectSchema(tool.inputSchema); + return obj + ? toJsonSchemaCompat(obj, { + strictUnions: true, + pipeStrategy: 'input' + }) + : EMPTY_OBJECT_JSON_SCHEMA; + })(), + annotations: tool.annotations, + execution: tool.execution, + _meta: tool._meta + }; + if (tool.outputSchema) { + const obj = normalizeObjectSchema(tool.outputSchema); + if (obj) { + toolDefinition.outputSchema = toJsonSchemaCompat(obj, { + strictUnions: true, + pipeStrategy: 'output' + }); + } + } + return toolDefinition; + }) + })); + this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { + var _a; + try { + const tool = this._registeredTools[request.params.name]; + if (!tool) { + throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} not found`); + } + if (!tool.enabled) { + throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`); + } + const isTaskRequest = !!request.params.task; + const taskSupport = (_a = tool.execution) === null || _a === void 0 ? void 0 : _a.taskSupport; + const isTaskHandler = 'createTask' in tool.handler; + // Validate task hint configuration + if ((taskSupport === 'required' || taskSupport === 'optional') && !isTaskHandler) { + throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`); + } + // Handle taskSupport 'required' without task augmentation + if (taskSupport === 'required' && !isTaskRequest) { + throw new McpError(ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`); + } + // Handle taskSupport 'optional' without task augmentation - automatic polling + if (taskSupport === 'optional' && !isTaskRequest && isTaskHandler) { + return await this.handleAutomaticTaskPolling(tool, request, extra); + } + // Normal execution path + const args = await this.validateToolInput(tool, request.params.arguments, request.params.name); + const result = await this.executeToolHandler(tool, args, extra); + // Return CreateTaskResult immediately for task requests + if (isTaskRequest) { + return result; + } + // Validate output schema for non-task requests + await this.validateToolOutput(tool, result, request.params.name); + return result; + } + catch (error) { + if (error instanceof McpError) { + if (error.code === ErrorCode.UrlElicitationRequired) { + throw error; // Return the error to the caller without wrapping in CallToolResult + } + } + return this.createToolError(error instanceof Error ? error.message : String(error)); + } + }); + this._toolHandlersInitialized = true; + } + /** + * Creates a tool error result. + * + * @param errorMessage - The error message. + * @returns The tool error result. + */ + createToolError(errorMessage) { + return { + content: [ + { + type: 'text', + text: errorMessage + } + ], + isError: true + }; + } + /** + * Validates tool input arguments against the tool's input schema. + */ + async validateToolInput(tool, args, toolName) { + if (!tool.inputSchema) { + return undefined; + } + // Try to normalize to object schema first (for raw shapes and object schemas) + // If that fails, use the schema directly (for union/intersection/etc) + const inputObj = normalizeObjectSchema(tool.inputSchema); + const schemaToParse = inputObj !== null && inputObj !== void 0 ? inputObj : tool.inputSchema; + const parseResult = await safeParseAsync(schemaToParse, args); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = getParseErrorMessage(error); + throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`); + } + return parseResult.data; + } + /** + * Validates tool output against the tool's output schema. + */ + async validateToolOutput(tool, result, toolName) { + if (!tool.outputSchema) { + return; + } + // Only validate CallToolResult, not CreateTaskResult + if (!('content' in result)) { + return; + } + if (result.isError) { + return; + } + if (!result.structuredContent) { + throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`); + } + // if the tool has an output schema, validate structured content + const outputObj = normalizeObjectSchema(tool.outputSchema); + const parseResult = await safeParseAsync(outputObj, result.structuredContent); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = getParseErrorMessage(error); + throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`); + } + } + /** + * Executes a tool handler (either regular or task-based). + */ + async executeToolHandler(tool, args, extra) { + const handler = tool.handler; + const isTaskHandler = 'createTask' in handler; + if (isTaskHandler) { + if (!extra.taskStore) { + throw new Error('No task store provided.'); + } + const taskExtra = { ...extra, taskStore: extra.taskStore }; + if (tool.inputSchema) { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler.createTask(args, taskExtra)); + } + else { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler.createTask(taskExtra)); + } + } + if (tool.inputSchema) { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler(args, extra)); + } + else { + const typedHandler = handler; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(typedHandler(extra)); + } + } + /** + * Handles automatic task polling for tools with taskSupport 'optional'. + */ + async handleAutomaticTaskPolling(tool, request, extra) { + var _a; + if (!extra.taskStore) { + throw new Error('No task store provided for task-capable tool.'); + } + // Validate input and create task + const args = await this.validateToolInput(tool, request.params.arguments, request.params.name); + const handler = tool.handler; + const taskExtra = { ...extra, taskStore: extra.taskStore }; + const createTaskResult = args // undefined only if tool.inputSchema is undefined + ? await Promise.resolve(handler.createTask(args, taskExtra)) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any + await Promise.resolve(handler.createTask(taskExtra)); + // Poll until completion + const taskId = createTaskResult.task.taskId; + let task = createTaskResult.task; + const pollInterval = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : 5000; + while (task.status !== 'completed' && task.status !== 'failed' && task.status !== 'cancelled') { + await new Promise(resolve => setTimeout(resolve, pollInterval)); + const updatedTask = await extra.taskStore.getTask(taskId); + if (!updatedTask) { + throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`); + } + task = updatedTask; + } + // Return the final result + return (await extra.taskStore.getTaskResult(taskId)); + } + setCompletionRequestHandler() { + if (this._completionHandlerInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(CompleteRequestSchema)); + this.server.registerCapabilities({ + completions: {} + }); + this.server.setRequestHandler(CompleteRequestSchema, async (request) => { + switch (request.params.ref.type) { + case 'ref/prompt': + assertCompleteRequestPrompt(request); + return this.handlePromptCompletion(request, request.params.ref); + case 'ref/resource': + assertCompleteRequestResourceTemplate(request); + return this.handleResourceCompletion(request, request.params.ref); + default: + throw new McpError(ErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`); + } + }); + this._completionHandlerInitialized = true; + } + async handlePromptCompletion(request, ref) { + const prompt = this._registeredPrompts[ref.name]; + if (!prompt) { + throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} not found`); + } + if (!prompt.enabled) { + throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} disabled`); + } + if (!prompt.argsSchema) { + return EMPTY_COMPLETION_RESULT; + } + const promptShape = getObjectShape(prompt.argsSchema); + const field = promptShape === null || promptShape === void 0 ? void 0 : promptShape[request.params.argument.name]; + if (!isCompletable(field)) { + return EMPTY_COMPLETION_RESULT; + } + const completer = getCompleter(field); + if (!completer) { + return EMPTY_COMPLETION_RESULT; + } + const suggestions = await completer(request.params.argument.value, request.params.context); + return createCompletionResult(suggestions); + } + async handleResourceCompletion(request, ref) { + const template = Object.values(this._registeredResourceTemplates).find(t => t.resourceTemplate.uriTemplate.toString() === ref.uri); + if (!template) { + if (this._registeredResources[ref.uri]) { + // Attempting to autocomplete a fixed resource URI is not an error in the spec (but probably should be). + return EMPTY_COMPLETION_RESULT; + } + throw new McpError(ErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`); + } + const completer = template.resourceTemplate.completeCallback(request.params.argument.name); + if (!completer) { + return EMPTY_COMPLETION_RESULT; + } + const suggestions = await completer(request.params.argument.value, request.params.context); + return createCompletionResult(suggestions); + } + setResourceRequestHandlers() { + if (this._resourceHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(ListResourcesRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(ListResourceTemplatesRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(ReadResourceRequestSchema)); + this.server.registerCapabilities({ + resources: { + listChanged: true + } + }); + this.server.setRequestHandler(ListResourcesRequestSchema, async (request, extra) => { + const resources = Object.entries(this._registeredResources) + .filter(([_, resource]) => resource.enabled) + .map(([uri, resource]) => ({ + uri, + name: resource.name, + ...resource.metadata + })); + const templateResources = []; + for (const template of Object.values(this._registeredResourceTemplates)) { + if (!template.resourceTemplate.listCallback) { + continue; + } + const result = await template.resourceTemplate.listCallback(extra); + for (const resource of result.resources) { + templateResources.push({ + ...template.metadata, + // the defined resource metadata should override the template metadata if present + ...resource + }); + } + } + return { resources: [...resources, ...templateResources] }; + }); + this.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => { + const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({ + name, + uriTemplate: template.resourceTemplate.uriTemplate.toString(), + ...template.metadata + })); + return { resourceTemplates }; + }); + this.server.setRequestHandler(ReadResourceRequestSchema, async (request, extra) => { + const uri = new URL(request.params.uri); + // First check for exact resource match + const resource = this._registeredResources[uri.toString()]; + if (resource) { + if (!resource.enabled) { + throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} disabled`); + } + return resource.readCallback(uri, extra); + } + // Then check templates + for (const template of Object.values(this._registeredResourceTemplates)) { + const variables = template.resourceTemplate.uriTemplate.match(uri.toString()); + if (variables) { + return template.readCallback(uri, variables, extra); + } + } + throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`); + }); + this.setCompletionRequestHandler(); + this._resourceHandlersInitialized = true; + } + setPromptRequestHandlers() { + if (this._promptHandlersInitialized) { + return; + } + this.server.assertCanSetRequestHandler(getMethodValue(ListPromptsRequestSchema)); + this.server.assertCanSetRequestHandler(getMethodValue(GetPromptRequestSchema)); + this.server.registerCapabilities({ + prompts: { + listChanged: true + } + }); + this.server.setRequestHandler(ListPromptsRequestSchema, () => ({ + prompts: Object.entries(this._registeredPrompts) + .filter(([, prompt]) => prompt.enabled) + .map(([name, prompt]) => { + return { + name, + title: prompt.title, + description: prompt.description, + arguments: prompt.argsSchema ? promptArgumentsFromSchema(prompt.argsSchema) : undefined + }; + }) + })); + this.server.setRequestHandler(GetPromptRequestSchema, async (request, extra) => { + const prompt = this._registeredPrompts[request.params.name]; + if (!prompt) { + throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} not found`); + } + if (!prompt.enabled) { + throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`); + } + if (prompt.argsSchema) { + const argsObj = normalizeObjectSchema(prompt.argsSchema); + const parseResult = await safeParseAsync(argsObj, request.params.arguments); + if (!parseResult.success) { + const error = 'error' in parseResult ? parseResult.error : 'Unknown error'; + const errorMessage = getParseErrorMessage(error); + throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`); + } + const args = parseResult.data; + const cb = prompt.callback; + return await Promise.resolve(cb(args, extra)); + } + else { + const cb = prompt.callback; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await Promise.resolve(cb(extra)); + } + }); + this.setCompletionRequestHandler(); + this._promptHandlersInitialized = true; + } + resource(name, uriOrTemplate, ...rest) { + let metadata; + if (typeof rest[0] === 'object') { + metadata = rest.shift(); + } + const readCallback = rest[0]; + if (typeof uriOrTemplate === 'string') { + if (this._registeredResources[uriOrTemplate]) { + throw new Error(`Resource ${uriOrTemplate} is already registered`); + } + const registeredResource = this._createRegisteredResource(name, undefined, uriOrTemplate, metadata, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResource; + } + else { + if (this._registeredResourceTemplates[name]) { + throw new Error(`Resource template ${name} is already registered`); + } + const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, undefined, uriOrTemplate, metadata, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResourceTemplate; + } + } + registerResource(name, uriOrTemplate, config, readCallback) { + if (typeof uriOrTemplate === 'string') { + if (this._registeredResources[uriOrTemplate]) { + throw new Error(`Resource ${uriOrTemplate} is already registered`); + } + const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, config, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResource; + } + else { + if (this._registeredResourceTemplates[name]) { + throw new Error(`Resource template ${name} is already registered`); + } + const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, config, readCallback); + this.setResourceRequestHandlers(); + this.sendResourceListChanged(); + return registeredResourceTemplate; + } + } + _createRegisteredResource(name, title, uri, metadata, readCallback) { + const registeredResource = { + name, + title, + metadata, + readCallback, + enabled: true, + disable: () => registeredResource.update({ enabled: false }), + enable: () => registeredResource.update({ enabled: true }), + remove: () => registeredResource.update({ uri: null }), + update: updates => { + if (typeof updates.uri !== 'undefined' && updates.uri !== uri) { + delete this._registeredResources[uri]; + if (updates.uri) + this._registeredResources[updates.uri] = registeredResource; + } + if (typeof updates.name !== 'undefined') + registeredResource.name = updates.name; + if (typeof updates.title !== 'undefined') + registeredResource.title = updates.title; + if (typeof updates.metadata !== 'undefined') + registeredResource.metadata = updates.metadata; + if (typeof updates.callback !== 'undefined') + registeredResource.readCallback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredResource.enabled = updates.enabled; + this.sendResourceListChanged(); + } + }; + this._registeredResources[uri] = registeredResource; + return registeredResource; + } + _createRegisteredResourceTemplate(name, title, template, metadata, readCallback) { + const registeredResourceTemplate = { + resourceTemplate: template, + title, + metadata, + readCallback, + enabled: true, + disable: () => registeredResourceTemplate.update({ enabled: false }), + enable: () => registeredResourceTemplate.update({ enabled: true }), + remove: () => registeredResourceTemplate.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + delete this._registeredResourceTemplates[name]; + if (updates.name) + this._registeredResourceTemplates[updates.name] = registeredResourceTemplate; + } + if (typeof updates.title !== 'undefined') + registeredResourceTemplate.title = updates.title; + if (typeof updates.template !== 'undefined') + registeredResourceTemplate.resourceTemplate = updates.template; + if (typeof updates.metadata !== 'undefined') + registeredResourceTemplate.metadata = updates.metadata; + if (typeof updates.callback !== 'undefined') + registeredResourceTemplate.readCallback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredResourceTemplate.enabled = updates.enabled; + this.sendResourceListChanged(); + } + }; + this._registeredResourceTemplates[name] = registeredResourceTemplate; + return registeredResourceTemplate; + } + _createRegisteredPrompt(name, title, description, argsSchema, callback) { + const registeredPrompt = { + title, + description, + argsSchema: argsSchema === undefined ? undefined : objectFromShape(argsSchema), + callback, + enabled: true, + disable: () => registeredPrompt.update({ enabled: false }), + enable: () => registeredPrompt.update({ enabled: true }), + remove: () => registeredPrompt.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + delete this._registeredPrompts[name]; + if (updates.name) + this._registeredPrompts[updates.name] = registeredPrompt; + } + if (typeof updates.title !== 'undefined') + registeredPrompt.title = updates.title; + if (typeof updates.description !== 'undefined') + registeredPrompt.description = updates.description; + if (typeof updates.argsSchema !== 'undefined') + registeredPrompt.argsSchema = objectFromShape(updates.argsSchema); + if (typeof updates.callback !== 'undefined') + registeredPrompt.callback = updates.callback; + if (typeof updates.enabled !== 'undefined') + registeredPrompt.enabled = updates.enabled; + this.sendPromptListChanged(); + } + }; + this._registeredPrompts[name] = registeredPrompt; + return registeredPrompt; + } + _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) { + // Validate tool name according to SEP specification + validateAndWarnToolName(name); + const registeredTool = { + title, + description, + inputSchema: getZodSchemaObject(inputSchema), + outputSchema: getZodSchemaObject(outputSchema), + annotations, + execution, + _meta, + handler: handler, + enabled: true, + disable: () => registeredTool.update({ enabled: false }), + enable: () => registeredTool.update({ enabled: true }), + remove: () => registeredTool.update({ name: null }), + update: updates => { + if (typeof updates.name !== 'undefined' && updates.name !== name) { + if (typeof updates.name === 'string') { + validateAndWarnToolName(updates.name); + } + delete this._registeredTools[name]; + if (updates.name) + this._registeredTools[updates.name] = registeredTool; + } + if (typeof updates.title !== 'undefined') + registeredTool.title = updates.title; + if (typeof updates.description !== 'undefined') + registeredTool.description = updates.description; + if (typeof updates.paramsSchema !== 'undefined') + registeredTool.inputSchema = objectFromShape(updates.paramsSchema); + if (typeof updates.callback !== 'undefined') + registeredTool.handler = updates.callback; + if (typeof updates.annotations !== 'undefined') + registeredTool.annotations = updates.annotations; + if (typeof updates._meta !== 'undefined') + registeredTool._meta = updates._meta; + if (typeof updates.enabled !== 'undefined') + registeredTool.enabled = updates.enabled; + this.sendToolListChanged(); + } + }; + this._registeredTools[name] = registeredTool; + this.setToolRequestHandlers(); + this.sendToolListChanged(); + return registeredTool; + } + /** + * tool() implementation. Parses arguments passed to overrides defined above. + */ + tool(name, ...rest) { + if (this._registeredTools[name]) { + throw new Error(`Tool ${name} is already registered`); + } + let description; + let inputSchema; + let outputSchema; + let annotations; + // Tool properties are passed as separate arguments, with omissions allowed. + // Support for this style is frozen as of protocol version 2025-03-26. Future additions + // to tool definition should *NOT* be added. + if (typeof rest[0] === 'string') { + description = rest.shift(); + } + // Handle the different overload combinations + if (rest.length > 1) { + // We have at least one more arg before the callback + const firstArg = rest[0]; + if (isZodRawShapeCompat(firstArg)) { + // We have a params schema as the first arg + inputSchema = rest.shift(); + // Check if the next arg is potentially annotations + if (rest.length > 1 && typeof rest[0] === 'object' && rest[0] !== null && !isZodRawShapeCompat(rest[0])) { + // Case: tool(name, paramsSchema, annotations, cb) + // Or: tool(name, description, paramsSchema, annotations, cb) + annotations = rest.shift(); + } + } + else if (typeof firstArg === 'object' && firstArg !== null) { + // Not a ZodRawShapeCompat, so must be annotations in this position + // Case: tool(name, annotations, cb) + // Or: tool(name, description, annotations, cb) + annotations = rest.shift(); + } + } + const callback = rest[0]; + return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, undefined, callback); + } + /** + * Registers a tool with a config object and callback. + */ + registerTool(name, config, cb) { + if (this._registeredTools[name]) { + throw new Error(`Tool ${name} is already registered`); + } + const { title, description, inputSchema, outputSchema, annotations, _meta } = config; + return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, _meta, cb); + } + prompt(name, ...rest) { + if (this._registeredPrompts[name]) { + throw new Error(`Prompt ${name} is already registered`); + } + let description; + if (typeof rest[0] === 'string') { + description = rest.shift(); + } + let argsSchema; + if (rest.length > 1) { + argsSchema = rest.shift(); + } + const cb = rest[0]; + const registeredPrompt = this._createRegisteredPrompt(name, undefined, description, argsSchema, cb); + this.setPromptRequestHandlers(); + this.sendPromptListChanged(); + return registeredPrompt; + } + /** + * Registers a prompt with a config object and callback. + */ + registerPrompt(name, config, cb) { + if (this._registeredPrompts[name]) { + throw new Error(`Prompt ${name} is already registered`); + } + const { title, description, argsSchema } = config; + const registeredPrompt = this._createRegisteredPrompt(name, title, description, argsSchema, cb); + this.setPromptRequestHandlers(); + this.sendPromptListChanged(); + return registeredPrompt; + } + /** + * Checks if the server is connected to a transport. + * @returns True if the server is connected + */ + isConnected() { + return this.server.transport !== undefined; + } + /** + * Sends a logging message to the client, if connected. + * Note: You only need to send the parameters object, not the entire JSON RPC message + * @see LoggingMessageNotification + * @param params + * @param sessionId optional for stateless and backward compatibility + */ + async sendLoggingMessage(params, sessionId) { + return this.server.sendLoggingMessage(params, sessionId); + } + /** + * Sends a resource list changed event to the client, if connected. + */ + sendResourceListChanged() { + if (this.isConnected()) { + this.server.sendResourceListChanged(); + } + } + /** + * Sends a tool list changed event to the client, if connected. + */ + sendToolListChanged() { + if (this.isConnected()) { + this.server.sendToolListChanged(); + } + } + /** + * Sends a prompt list changed event to the client, if connected. + */ + sendPromptListChanged() { + if (this.isConnected()) { + this.server.sendPromptListChanged(); + } + } +} +/** + * A resource template combines a URI pattern with optional functionality to enumerate + * all resources matching that pattern. + */ +export class ResourceTemplate { + constructor(uriTemplate, _callbacks) { + this._callbacks = _callbacks; + this._uriTemplate = typeof uriTemplate === 'string' ? new UriTemplate(uriTemplate) : uriTemplate; + } + /** + * Gets the URI template pattern. + */ + get uriTemplate() { + return this._uriTemplate; + } + /** + * Gets the list callback, if one was provided. + */ + get listCallback() { + return this._callbacks.list; + } + /** + * Gets the callback for completing a specific URI template variable, if one was provided. + */ + completeCallback(variable) { + var _a; + return (_a = this._callbacks.complete) === null || _a === void 0 ? void 0 : _a[variable]; + } +} +const EMPTY_OBJECT_JSON_SCHEMA = { + type: 'object', + properties: {} +}; +// Helper to check if an object is a Zod schema (ZodRawShapeCompat) +function isZodRawShapeCompat(obj) { + if (typeof obj !== 'object' || obj === null) + return false; + const isEmptyObject = Object.keys(obj).length === 0; + // Check if object is empty or at least one property is a ZodType instance + // Note: use heuristic check to avoid instanceof failure across different Zod versions + return isEmptyObject || Object.values(obj).some(isZodTypeLike); +} +function isZodTypeLike(value) { + return (value !== null && + typeof value === 'object' && + 'parse' in value && + typeof value.parse === 'function' && + 'safeParse' in value && + typeof value.safeParse === 'function'); +} +/** + * Converts a provided Zod schema to a Zod object if it is a ZodRawShapeCompat, + * otherwise returns the schema as is. + */ +function getZodSchemaObject(schema) { + if (!schema) { + return undefined; + } + if (isZodRawShapeCompat(schema)) { + return objectFromShape(schema); + } + return schema; +} +function promptArgumentsFromSchema(schema) { + const shape = getObjectShape(schema); + if (!shape) + return []; + return Object.entries(shape).map(([name, field]) => { + // Get description - works for both v3 and v4 + const description = getSchemaDescription(field); + // Check if optional - works for both v3 and v4 + const isOptional = isSchemaOptional(field); + return { + name, + description, + required: !isOptional + }; + }); +} +function getMethodValue(schema) { + const shape = getObjectShape(schema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + // Extract literal value - works for both v3 and v4 + const value = getLiteralValue(methodSchema); + if (typeof value === 'string') { + return value; + } + throw new Error('Schema method literal must be a string'); +} +function createCompletionResult(suggestions) { + return { + completion: { + values: suggestions.slice(0, 100), + total: suggestions.length, + hasMore: suggestions.length > 100 + } + }; +} +const EMPTY_COMPLETION_RESULT = { + completion: { + values: [], + hasMore: false + } +}; +//# sourceMappingURL=mcp.js.map \ No newline at end of file diff --git a/dist/esm/server/mcp.js.map b/dist/esm/server/mcp.js.map new file mode 100644 index 000000000..8cffa85d7 --- /dev/null +++ b/dist/esm/server/mcp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AACnD,OAAO,EAMH,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAKH,QAAQ,EACR,SAAS,EAOT,kCAAkC,EAClC,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EAcrB,2BAA2B,EAC3B,qCAAqC,EAGxC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAa,MAAM,0BAA0B,CAAC;AAIlE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC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;IACnD,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,sBAAsB,CAAC,WAAqB;IACjD,OAAO;QACH,UAAU,EAAE;YACR,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;YACjC,KAAK,EAAE,WAAW,CAAC,MAAM;YACzB,OAAO,EAAE,WAAW,CAAC,MAAM,GAAG,GAAG;SACpC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,uBAAuB,GAAmB;IAC5C,UAAU,EAAE;QACR,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,KAAK;KACjB;CACJ,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/session-stores/index.d.ts b/dist/esm/server/session-stores/index.d.ts new file mode 100644 index 000000000..a430e4410 --- /dev/null +++ b/dist/esm/server/session-stores/index.d.ts @@ -0,0 +1,6 @@ +/** + * Session Store implementations for distributed MCP deployments + */ +export { RedisSessionStore, InMemorySessionStore } from './redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './redis.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/session-stores/index.d.ts.map b/dist/esm/server/session-stores/index.d.ts.map new file mode 100644 index 000000000..fc5fbf1dc --- /dev/null +++ b/dist/esm/server/session-stores/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/session-stores/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/session-stores/index.js b/dist/esm/server/session-stores/index.js new file mode 100644 index 000000000..22b1ba441 --- /dev/null +++ b/dist/esm/server/session-stores/index.js @@ -0,0 +1,5 @@ +/** + * Session Store implementations for distributed MCP deployments + */ +export { RedisSessionStore, InMemorySessionStore } from './redis.js'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/server/session-stores/index.js.map b/dist/esm/server/session-stores/index.js.map new file mode 100644 index 000000000..6cbc1be6b --- /dev/null +++ b/dist/esm/server/session-stores/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/server/session-stores/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/session-stores/redis.d.ts b/dist/esm/server/session-stores/redis.d.ts new file mode 100644 index 000000000..1a0975a5c --- /dev/null +++ b/dist/esm/server/session-stores/redis.d.ts @@ -0,0 +1,122 @@ +/** + * Redis Session Store Implementation + * + * This module provides a Redis-based implementation of the SessionStore interface + * for distributed MCP server deployments. + * + * Usage: + * ```typescript + * import Redis from 'ioredis'; + * import { RedisSessionStore } from '@modelcontextprotocol/sdk/server/session-stores/redis.js'; + * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; + * + * const redis = new Redis({ + * host: 'redis.example.com', + * port: 6379, + * password: 'your-password' + * }); + * + * const sessionStore = new RedisSessionStore({ + * redis, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 // 1 hour + * }); + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore + * }); + * ``` + */ +import { SessionStore, SessionData } from '../streamableHttp.js'; +/** + * Generic Redis client interface + * Compatible with ioredis, node-redis, and other Redis clients + */ +export interface RedisClient { + get(key: string): Promise; + setex(key: string, seconds: number, value: string): Promise; + del(key: string | string[]): Promise; + exists(key: string | string[]): Promise; + expire(key: string, seconds: number): Promise; +} +/** + * Configuration options for RedisSessionStore + */ +export interface RedisSessionStoreOptions { + /** + * Redis client instance (ioredis, node-redis, or compatible) + */ + redis: RedisClient; + /** + * Key prefix for session data in Redis + * @default 'mcp:session:' + */ + keyPrefix?: string; + /** + * Session TTL in seconds + * @default 3600 (1 hour) + */ + ttlSeconds?: number; + /** + * Optional callback for logging + */ + onLog?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: unknown[]) => void; +} +/** + * Redis-based session store for distributed MCP deployments + * + * Features: + * - Automatic TTL management with activity-based refresh + * - Cross-pod session sharing + * - Graceful handling of Redis connection issues + */ +export declare class RedisSessionStore implements SessionStore { + private readonly redis; + private readonly keyPrefix; + private readonly ttlSeconds; + private readonly log; + constructor(options: RedisSessionStoreOptions); + /** + * Get the Redis key for a session + */ + private getKey; + /** + * Store session data in Redis + */ + storeSession(sessionId: string, data: SessionData): Promise; + /** + * Retrieve session data from Redis + */ + getSession(sessionId: string): Promise; + /** + * Update session activity timestamp and refresh TTL + */ + updateSessionActivity(sessionId: string): Promise; + /** + * Delete a session from Redis + */ + deleteSession(sessionId: string): Promise; + /** + * Check if a session exists in Redis + */ + sessionExists(sessionId: string): Promise; +} +/** + * In-Memory Session Store (for development/testing) + * + * NOT suitable for production multi-pod deployments! + * Use RedisSessionStore or implement your own SessionStore for production. + */ +export declare class InMemorySessionStore implements SessionStore { + private sessions; + private readonly ttlMs; + constructor(ttlSeconds?: number); + storeSession(sessionId: string, data: SessionData): Promise; + getSession(sessionId: string): Promise; + updateSessionActivity(sessionId: string): Promise; + deleteSession(sessionId: string): Promise; + sessionExists(sessionId: string): Promise; + private cleanup; +} +//# sourceMappingURL=redis.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/session-stores/redis.d.ts.map b/dist/esm/server/session-stores/redis.d.ts.map new file mode 100644 index 000000000..faa297e98 --- /dev/null +++ b/dist/esm/server/session-stores/redis.d.ts.map @@ -0,0 +1 @@ +{"version":3,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C,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA4F;gBAEpG,OAAO,EAAE,wBAAwB;IAO7C;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvE;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmBhE;;OAEG;IACG,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB7D;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAU3D;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACrD,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,UAAU,GAAE,MAAa;IAO/B,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAa1D,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD,OAAO,CAAC,OAAO;CAQlB"} \ No newline at end of file diff --git a/dist/esm/server/session-stores/redis.js b/dist/esm/server/session-stores/redis.js new file mode 100644 index 000000000..7cfca1c11 --- /dev/null +++ b/dist/esm/server/session-stores/redis.js @@ -0,0 +1,187 @@ +/** + * Redis Session Store Implementation + * + * This module provides a Redis-based implementation of the SessionStore interface + * for distributed MCP server deployments. + * + * Usage: + * ```typescript + * import Redis from 'ioredis'; + * import { RedisSessionStore } from '@modelcontextprotocol/sdk/server/session-stores/redis.js'; + * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; + * + * const redis = new Redis({ + * host: 'redis.example.com', + * port: 6379, + * password: 'your-password' + * }); + * + * const sessionStore = new RedisSessionStore({ + * redis, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 // 1 hour + * }); + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore + * }); + * ``` + */ +/** + * Redis-based session store for distributed MCP deployments + * + * Features: + * - Automatic TTL management with activity-based refresh + * - Cross-pod session sharing + * - Graceful handling of Redis connection issues + */ +export class RedisSessionStore { + constructor(options) { + var _a, _b, _c; + this.redis = options.redis; + this.keyPrefix = (_a = options.keyPrefix) !== null && _a !== void 0 ? _a : 'mcp:session:'; + this.ttlSeconds = (_b = options.ttlSeconds) !== null && _b !== void 0 ? _b : 3600; + this.log = (_c = options.onLog) !== null && _c !== void 0 ? _c : (() => { }); + } + /** + * Get the Redis key for a session + */ + getKey(sessionId) { + return `${this.keyPrefix}${sessionId}`; + } + /** + * Store session data in Redis + */ + async storeSession(sessionId, data) { + try { + const key = this.getKey(sessionId); + const serialized = JSON.stringify(data); + await this.redis.setex(key, this.ttlSeconds, serialized); + this.log('debug', `Session stored: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to store session ${sessionId}:`, error); + throw error; + } + } + /** + * Retrieve session data from Redis + */ + async getSession(sessionId) { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + if (!data) { + this.log('debug', `Session not found: ${sessionId}`); + return null; + } + const parsed = JSON.parse(data); + this.log('debug', `Session retrieved: ${sessionId}`); + return parsed; + } + catch (error) { + this.log('error', `Failed to get session ${sessionId}:`, error); + throw error; + } + } + /** + * Update session activity timestamp and refresh TTL + */ + async updateSessionActivity(sessionId) { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + if (!data) { + this.log('warn', `Cannot update activity for non-existent session: ${sessionId}`); + return; + } + const parsed = JSON.parse(data); + parsed.lastActivity = Date.now(); + await this.redis.setex(key, this.ttlSeconds, JSON.stringify(parsed)); + this.log('debug', `Session activity updated: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to update session activity ${sessionId}:`, error); + // Don't throw - activity update failures shouldn't break the request + } + } + /** + * Delete a session from Redis + */ + async deleteSession(sessionId) { + try { + const key = this.getKey(sessionId); + await this.redis.del(key); + this.log('debug', `Session deleted: ${sessionId}`); + } + catch (error) { + this.log('error', `Failed to delete session ${sessionId}:`, error); + throw error; + } + } + /** + * Check if a session exists in Redis + */ + async sessionExists(sessionId) { + try { + const key = this.getKey(sessionId); + const exists = await this.redis.exists(key); + return exists === 1; + } + catch (error) { + this.log('error', `Failed to check session existence ${sessionId}:`, error); + throw error; + } + } +} +/** + * In-Memory Session Store (for development/testing) + * + * NOT suitable for production multi-pod deployments! + * Use RedisSessionStore or implement your own SessionStore for production. + */ +export class InMemorySessionStore { + constructor(ttlSeconds = 3600) { + this.sessions = new Map(); + this.ttlMs = ttlSeconds * 1000; + // Cleanup expired sessions every minute + setInterval(() => this.cleanup(), 60000); + } + async storeSession(sessionId, data) { + this.sessions.set(sessionId, data); + } + async getSession(sessionId) { + const data = this.sessions.get(sessionId); + if (!data) + return null; + // Check if expired + if (Date.now() - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + return null; + } + return data; + } + async updateSessionActivity(sessionId) { + const data = this.sessions.get(sessionId); + if (data) { + data.lastActivity = Date.now(); + } + } + async deleteSession(sessionId) { + this.sessions.delete(sessionId); + } + async sessionExists(sessionId) { + const data = await this.getSession(sessionId); + return data !== null; + } + cleanup() { + const now = Date.now(); + for (const [sessionId, data] of this.sessions) { + if (now - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + } + } + } +} +//# sourceMappingURL=redis.js.map \ No newline at end of file diff --git a/dist/esm/server/session-stores/redis.js.map b/dist/esm/server/session-stores/redis.js.map new file mode 100644 index 000000000..fd43f9049 --- /dev/null +++ b/dist/esm/server/session-stores/redis.js.map @@ -0,0 +1 @@ +{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../../src/server/session-stores/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA2CH;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAM1B,YAAY,OAAiC;;QACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,cAAc,CAAC;QACrD,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,GAAG,GAAG,MAAA,OAAO,CAAC,KAAK,mCAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,SAAiB;QAC5B,OAAO,GAAG,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,SAAiB,EAAE,IAAiB;QACnD,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACxC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACzD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,mBAAmB,SAAS,EAAE,CAAC,CAAC;QACt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AAC,SAAiB;QACjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC9C,OAAO,IAAI,KAAK,IAAI,CAAC;IACzB,CAAC;IAEO,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;gBACvC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACpC,CAAC;QACL,CAAC;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/server/sse.d.ts b/dist/esm/server/sse.d.ts new file mode 100644 index 000000000..aba8d5120 --- /dev/null +++ b/dist/esm/server/sse.d.ts @@ -0,0 +1,76 @@ +import { IncomingMessage, ServerResponse } from 'node:http'; +import { Transport } from '../shared/transport.js'; +import { JSONRPCMessage, MessageExtraInfo } from '../types.js'; +import { AuthInfo } from './auth/types.js'; +/** + * Configuration options for SSEServerTransport. + */ +export interface SSEServerTransportOptions { + /** + * List of allowed host header values for DNS rebinding protection. + * If not specified, host validation is disabled. + */ + allowedHosts?: string[]; + /** + * List of allowed origin header values for DNS rebinding protection. + * If not specified, origin validation is disabled. + */ + allowedOrigins?: string[]; + /** + * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured). + * Default is false for backwards compatibility. + */ + enableDnsRebindingProtection?: boolean; +} +/** + * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests. + * + * This transport is only available in Node.js environments. + * @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead. + */ +export declare class SSEServerTransport implements Transport { + private _endpoint; + private res; + private _sseResponse?; + private _sessionId; + private _options; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void; + /** + * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`. + */ + constructor(_endpoint: string, res: ServerResponse, options?: SSEServerTransportOptions); + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + private validateRequestHeaders; + /** + * Handles the initial SSE connection request. + * + * This should be called when a GET request is made to establish the SSE stream. + */ + start(): Promise; + /** + * Handles incoming POST messages. + * + * This should be called when a POST request is made to send a message to the server. + */ + handlePostMessage(req: IncomingMessage & { + auth?: AuthInfo; + }, res: ServerResponse, parsedBody?: unknown): Promise; + /** + * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST. + */ + handleMessage(message: unknown, extra?: MessageExtraInfo): Promise; + close(): Promise; + send(message: JSONRPCMessage): Promise; + /** + * Returns the session ID for this transport. + * + * This can be used to route incoming POST requests. + */ + get sessionId(): string; +} +//# sourceMappingURL=sse.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/sse.d.ts.map b/dist/esm/server/sse.d.ts.map new file mode 100644 index 000000000..c3c267cd8 --- /dev/null +++ b/dist/esm/server/sse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAwB,gBAAgB,EAAe,MAAM,aAAa,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,M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server/sse.js b/dist/esm/server/sse.js new file mode 100644 index 000000000..3011ec433 --- /dev/null +++ b/dist/esm/server/sse.js @@ -0,0 +1,161 @@ +import { randomUUID } from 'node:crypto'; +import { JSONRPCMessageSchema } from '../types.js'; +import getRawBody from 'raw-body'; +import contentType from 'content-type'; +import { URL } from 'node:url'; +const MAXIMUM_MESSAGE_SIZE = '4mb'; +/** + * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests. + * + * This transport is only available in Node.js environments. + * @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead. + */ +export class SSEServerTransport { + /** + * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`. + */ + constructor(_endpoint, res, options) { + this._endpoint = _endpoint; + this.res = res; + this._sessionId = randomUUID(); + this._options = options || { enableDnsRebindingProtection: false }; + } + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + validateRequestHeaders(req) { + // Skip validation if protection is not enabled + if (!this._options.enableDnsRebindingProtection) { + return undefined; + } + // Validate Host header if allowedHosts is configured + if (this._options.allowedHosts && this._options.allowedHosts.length > 0) { + const hostHeader = req.headers.host; + if (!hostHeader || !this._options.allowedHosts.includes(hostHeader)) { + return `Invalid Host header: ${hostHeader}`; + } + } + // Validate Origin header if allowedOrigins is configured + if (this._options.allowedOrigins && this._options.allowedOrigins.length > 0) { + const originHeader = req.headers.origin; + if (!originHeader || !this._options.allowedOrigins.includes(originHeader)) { + return `Invalid Origin header: ${originHeader}`; + } + } + return undefined; + } + /** + * Handles the initial SSE connection request. + * + * This should be called when a GET request is made to establish the SSE stream. + */ + async start() { + if (this._sseResponse) { + throw new Error('SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.'); + } + this.res.writeHead(200, { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }); + // Send the endpoint event + // Use a dummy base URL because this._endpoint is relative. + // This allows using URL/URLSearchParams for robust parameter handling. + const dummyBase = 'http://localhost'; // Any valid base works + const endpointUrl = new URL(this._endpoint, dummyBase); + endpointUrl.searchParams.set('sessionId', this._sessionId); + // Reconstruct the relative URL string (pathname + search + hash) + const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash; + this.res.write(`event: endpoint\ndata: ${relativeUrlWithSession}\n\n`); + this._sseResponse = this.res; + this.res.on('close', () => { + var _a; + this._sseResponse = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + }); + } + /** + * Handles incoming POST messages. + * + * This should be called when a POST request is made to send a message to the server. + */ + async handlePostMessage(req, res, parsedBody) { + var _a, _b, _c, _d; + if (!this._sseResponse) { + const message = 'SSE connection not established'; + res.writeHead(500).end(message); + throw new Error(message); + } + // Validate request headers for DNS rebinding protection + const validationError = this.validateRequestHeaders(req); + if (validationError) { + res.writeHead(403).end(validationError); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(validationError)); + return; + } + const authInfo = req.auth; + const requestInfo = { headers: req.headers }; + let body; + try { + const ct = contentType.parse((_b = req.headers['content-type']) !== null && _b !== void 0 ? _b : ''); + if (ct.type !== 'application/json') { + throw new Error(`Unsupported content-type: ${ct.type}`); + } + body = + parsedBody !== null && parsedBody !== void 0 ? parsedBody : (await getRawBody(req, { + limit: MAXIMUM_MESSAGE_SIZE, + encoding: (_c = ct.parameters.charset) !== null && _c !== void 0 ? _c : 'utf-8' + })); + } + catch (error) { + res.writeHead(400).end(String(error)); + (_d = this.onerror) === null || _d === void 0 ? void 0 : _d.call(this, error); + return; + } + try { + await this.handleMessage(typeof body === 'string' ? JSON.parse(body) : body, { requestInfo, authInfo }); + } + catch (_e) { + res.writeHead(400).end(`Invalid message: ${body}`); + return; + } + res.writeHead(202).end('Accepted'); + } + /** + * Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST. + */ + async handleMessage(message, extra) { + var _a, _b; + let parsedMessage; + try { + parsedMessage = JSONRPCMessageSchema.parse(message); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + throw error; + } + (_b = this.onmessage) === null || _b === void 0 ? void 0 : _b.call(this, parsedMessage, extra); + } + async close() { + var _a, _b; + (_a = this._sseResponse) === null || _a === void 0 ? void 0 : _a.end(); + this._sseResponse = undefined; + (_b = this.onclose) === null || _b === void 0 ? void 0 : _b.call(this); + } + async send(message) { + if (!this._sseResponse) { + throw new Error('Not connected'); + } + this._sseResponse.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`); + } + /** + * Returns the session ID for this transport. + * + * This can be used to route incoming POST requests. + */ + get sessionId() { + return this._sessionId; + } +} +//# sourceMappingURL=sse.js.map \ No newline at end of file diff --git a/dist/esm/server/sse.js.map b/dist/esm/server/sse.js.map new file mode 100644 index 000000000..2335a7280 --- /dev/null +++ b/dist/esm/server/sse.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAkB,oBAAoB,EAAiC,MAAM,aAAa,CAAC;AAClG,OAAO,UAAU,MAAM,UAAU,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAyBnC;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAQ3B;;OAEG;IACH,YACY,SAAiB,EACjB,GAAmB,EAC3B,OAAmC;QAF3B,cAAS,GAAT,SAAS,CAAQ;QACjB,QAAG,GAAH,GAAG,CAAgB;QAG3B,IAAI,CAAC,UAAU,GAAG,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,EAAE,4BAA4B,EAAE,KAAK,EAAE,CAAC;IACvE,CAAC;IAED;;;OAGG;IACK,sB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ACX,CAAC;QAED,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAAgB,EAAE,KAAwB;;QAC1D,IAAI,aAA6B,CAAC;QAClC,IAAI,CAAC;YACD,aAAa,GAAG,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAc,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;QAChB,CAAC;QAED,MAAA,IAAI,CAAC,SAAS,qDAAG,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,KAAK;;QACP,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAuB;QAC9B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/server/stdio.d.ts b/dist/esm/server/stdio.d.ts new file mode 100644 index 000000000..df3029d0d --- /dev/null +++ b/dist/esm/server/stdio.d.ts @@ -0,0 +1,28 @@ +import { Readable, Writable } from 'node:stream'; +import { JSONRPCMessage } from '../types.js'; +import { Transport } from '../shared/transport.js'; +/** + * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout. + * + * This transport is only available in Node.js environments. + */ +export declare class StdioServerTransport implements Transport { + private _stdin; + private _stdout; + private _readBuffer; + private _started; + constructor(_stdin?: Readable, _stdout?: Writable); + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage) => void; + _ondata: (chunk: Buffer) => void; + _onerror: (error: Error) => void; + /** + * Starts listening for messages on stdin. + */ + start(): Promise; + private processReadBuffer; + close(): Promise; + send(message: JSONRPCMessage): Promise; +} +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/stdio.d.ts.map b/dist/esm/server/stdio.d.ts.map new file mode 100644 index 000000000..fdd2dfe48 --- /dev/null +++ b/dist/esm/server/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/server/stdio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IAK9C,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IALnB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,QAAQ,CAAS;gBAGb,MAAM,GAAE,QAAwB,EAChC,OAAO,GAAE,QAAyB;IAG9C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAG9C,OAAO,UAAW,MAAM,UAGtB;IACF,QAAQ,UAAW,KAAK,UAEtB;IAEF;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B,OAAO,CAAC,iBAAiB;IAenB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAU/C"} \ No newline at end of file diff --git a/dist/esm/server/stdio.js b/dist/esm/server/stdio.js new file mode 100644 index 000000000..98a3467ed --- /dev/null +++ b/dist/esm/server/stdio.js @@ -0,0 +1,78 @@ +import process from 'node:process'; +import { ReadBuffer, serializeMessage } from '../shared/stdio.js'; +/** + * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout. + * + * This transport is only available in Node.js environments. + */ +export class StdioServerTransport { + constructor(_stdin = process.stdin, _stdout = process.stdout) { + this._stdin = _stdin; + this._stdout = _stdout; + this._readBuffer = new ReadBuffer(); + this._started = false; + // Arrow functions to bind `this` properly, while maintaining function identity. + this._ondata = (chunk) => { + this._readBuffer.append(chunk); + this.processReadBuffer(); + }; + this._onerror = (error) => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }; + } + /** + * Starts listening for messages on stdin. + */ + async start() { + if (this._started) { + throw new Error('StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.'); + } + this._started = true; + this._stdin.on('data', this._ondata); + this._stdin.on('error', this._onerror); + } + processReadBuffer() { + var _a, _b; + while (true) { + try { + const message = this._readBuffer.readMessage(); + if (message === null) { + break; + } + (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message); + } + catch (error) { + (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error); + } + } + } + async close() { + var _a; + // Remove our event listeners first + this._stdin.off('data', this._ondata); + this._stdin.off('error', this._onerror); + // Check if we were the only data listener + const remainingDataListeners = this._stdin.listenerCount('data'); + if (remainingDataListeners === 0) { + // Only pause stdin if we were the only listener + // This prevents interfering with other parts of the application that might be using stdin + this._stdin.pause(); + } + // Clear the buffer and notify closure + this._readBuffer.clear(); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + send(message) { + return new Promise(resolve => { + const json = serializeMessage(message); + if (this._stdout.write(json)) { + resolve(); + } + else { + this._stdout.once('drain', resolve); + } + }); + } +} +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/esm/server/stdio.js.map b/dist/esm/server/stdio.js.map new file mode 100644 index 000000000..f2d202de7 --- /dev/null +++ b/dist/esm/server/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/server/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAIlE;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAI7B,YACY,SAAmB,OAAO,CAAC,KAAK,EAChC,UAAoB,OAAO,CAAC,MAAM;QADlC,WAAM,GAAN,MAAM,CAA0B;QAChC,YAAO,GAAP,OAAO,CAA2B;QALtC,gBAAW,GAAe,IAAI,UAAU,EAAE,CAAC;QAC3C,aAAQ,GAAG,KAAK,CAAC;QAWzB,gFAAgF;QAChF,YAAO,GAAG,CAAC,KAAa,EAAE,EAAE;YACxB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC;QACF,aAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;;YACxB,MAAA,IAAI,CAAC,OAAO,qDAAG,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IAbC,CAAC;IAeJ;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACX,+GAA+G,CAClH,CAAC;QACN,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,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AO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACd,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACxC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/server/streamableHttp.d.ts b/dist/esm/server/streamableHttp.d.ts new file mode 100644 index 000000000..97291ab3b --- /dev/null +++ b/dist/esm/server/streamableHttp.d.ts @@ -0,0 +1,369 @@ +import { IncomingMessage, ServerResponse } from 'node:http'; +import { Transport } from '../shared/transport.js'; +import { MessageExtraInfo, JSONRPCMessage, RequestId } from '../types.js'; +import { AuthInfo } from './auth/types.js'; +export type StreamId = string; +export type EventId = string; +/** + * Interface for resumability support via event storage + */ +export interface EventStore { + /** + * Stores an event for later retrieval + * @param streamId ID of the stream the event belongs to + * @param message The JSON-RPC message to store + * @returns The generated event ID for the stored event + */ + storeEvent(streamId: StreamId, message: JSONRPCMessage): Promise; + /** + * Get the stream ID associated with a given event ID. + * @param eventId The event ID to look up + * @returns The stream ID, or undefined if not found + * + * Optional: If not provided, the SDK will use the streamId returned by + * replayEventsAfter for stream mapping. + */ + getStreamIdForEventId?(eventId: EventId): Promise; + replayEventsAfter(lastEventId: EventId, { send }: { + send: (eventId: EventId, message: JSONRPCMessage) => Promise; + }): Promise; +} +/** + * Session data structure for distributed session storage + */ +export interface SessionData { + /** + * The unique session identifier + */ + sessionId: string; + /** + * Whether the session has been initialized (received initialize request) + */ + initialized: boolean; + /** + * Timestamp when the session was created (Unix ms) + */ + createdAt: number; + /** + * Timestamp of last activity (Unix ms) + */ + lastActivity: number; + /** + * Optional metadata for custom use cases (e.g., serverId, userId) + */ + metadata?: Record; +} +/** + * Interface for distributed session storage (e.g., Redis, PostgreSQL, etc.) + * + * This interface enables multi-node/multi-pod deployments where session state + * must be shared across multiple server instances. Without this, sessions are + * stored in-memory and requests routed to different pods will fail. + * + * Usage example with Redis: + * ```typescript + * const sessionStore: SessionStore = { + * async storeSession(sessionId, data) { + * await redis.setex(`mcp:session:${sessionId}`, 3600, JSON.stringify(data)); + * }, + * async getSession(sessionId) { + * const data = await redis.get(`mcp:session:${sessionId}`); + * return data ? JSON.parse(data) : null; + * }, + * async updateSessionActivity(sessionId) { + * const data = await this.getSession(sessionId); + * if (data) { + * data.lastActivity = Date.now(); + * await this.storeSession(sessionId, data); + * } + * }, + * async deleteSession(sessionId) { + * await redis.del(`mcp:session:${sessionId}`); + * }, + * async sessionExists(sessionId) { + * return await redis.exists(`mcp:session:${sessionId}`) === 1; + * } + * }; + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: sessionStore + * }); + * ``` + */ +export interface SessionStore { + /** + * Store session data + * @param sessionId The session identifier + * @param data The session data to store + */ + storeSession(sessionId: string, data: SessionData): Promise; + /** + * Retrieve session data + * @param sessionId The session identifier + * @returns The session data, or null if not found + */ + getSession(sessionId: string): Promise; + /** + * Update session activity timestamp (e.g., refresh TTL) + * @param sessionId The session identifier + */ + updateSessionActivity(sessionId: string): Promise; + /** + * Delete a session + * @param sessionId The session identifier + */ + deleteSession(sessionId: string): Promise; + /** + * Check if a session exists + * @param sessionId The session identifier + * @returns true if the session exists + */ + sessionExists(sessionId: string): Promise; +} +/** + * Session storage mode for the transport + */ +export type SessionStorageMode = 'memory' | 'external'; +/** + * Configuration options for StreamableHTTPServerTransport + */ +export interface StreamableHTTPServerTransportOptions { + /** + * Function that generates a session ID for the transport. + * The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash) + * + * Return undefined to disable session management. + */ + sessionIdGenerator: (() => string) | undefined; + /** + * A callback for session initialization events + * This is called when the server initializes a new session. + * Useful in cases when you need to register multiple mcp sessions + * and need to keep track of them. + * @param sessionId The generated session ID + */ + onsessioninitialized?: (sessionId: string) => void | Promise; + /** + * A callback for session close events + * This is called when the server closes a session due to a DELETE request. + * Useful in cases when you need to clean up resources associated with the session. + * Note that this is different from the transport closing, if you are handling + * HTTP requests from multiple nodes you might want to close each + * StreamableHTTPServerTransport after a request is completed while still keeping the + * session open/running. + * @param sessionId The session ID that was closed + */ + onsessionclosed?: (sessionId: string) => void | Promise; + /** + * If true, the server will return JSON responses instead of starting an SSE stream. + * This can be useful for simple request/response scenarios without streaming. + * Default is false (SSE streams are preferred). + */ + enableJsonResponse?: boolean; + /** + * Event store for resumability support + * If provided, resumability will be enabled, allowing clients to reconnect and resume messages + */ + eventStore?: EventStore; + /** + * Session storage mode - explicitly choose between in-memory and external storage. + * + * - 'memory': Sessions stored in process memory (single-node only, default) + * - 'external': Sessions stored in external store (requires sessionStore option) + * + * When 'external' is selected but sessionStore is not provided, an error will be thrown. + * + * @default 'memory' + */ + sessionStorageMode?: SessionStorageMode; + /** + * Session store for distributed session management. + * Required when sessionStorageMode is 'external'. + * + * This enables multi-node/multi-pod deployments where requests may be routed + * to different server instances. + * + * When sessionStore is provided with mode 'external': + * - Session validation checks the external store instead of local memory + * - Session data is persisted across server restarts + * - Multiple server instances can share session state + * - Cross-pod session recovery is handled automatically + * + * @example + * ```typescript + * // Redis session store for multi-pod deployment + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStorageMode: 'external', + * sessionStore: new RedisSessionStore({ + * redis: redisClient, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 + * }) + * }); + * ``` + */ + sessionStore?: SessionStore; + /** + * List of allowed host header values for DNS rebinding protection. + * If not specified, host validation is disabled. + */ + allowedHosts?: string[]; + /** + * List of allowed origin header values for DNS rebinding protection. + * If not specified, origin validation is disabled. + */ + allowedOrigins?: string[]; + /** + * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured). + * Default is false for backwards compatibility. + */ + enableDnsRebindingProtection?: boolean; + /** + * Retry interval in milliseconds to suggest to clients in SSE retry field. + * When set, the server will send a retry field in SSE priming events to control + * client reconnection timing for polling behavior. + */ + retryInterval?: number; +} +/** + * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It supports both SSE streaming and direct HTTP responses. + * + * Usage example: + * + * ```typescript + * // Stateful mode - server sets the session ID + * const statefulTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * }); + * + * // Stateless mode - explicitly set session ID to undefined + * const statelessTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: undefined, + * }); + * + * // Using with pre-parsed request body + * app.post('/mcp', (req, res) => { + * transport.handleRequest(req, res, req.body); + * }); + * + * // With distributed session store (Redis) for multi-pod deployments + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: myRedisSessionStore + * }); + * ``` + * + * In stateful mode: + * - Session ID is generated and included in response headers + * - Session ID is always included in initialization responses + * - Requests with invalid session IDs are rejected with 404 Not Found + * - Non-initialization requests without a session ID are rejected with 400 Bad Request + * - State is maintained in-memory (connections, message history) or externally via sessionStore + * + * In stateless mode: + * - No Session ID is included in any responses + * - No session validation is performed + */ +export declare class StreamableHTTPServerTransport implements Transport { + private sessionIdGenerator; + private _started; + private _streamMapping; + private _requestToStreamMapping; + private _requestResponseMap; + private _initialized; + private _enableJsonResponse; + private _standaloneSseStreamId; + private _eventStore?; + private _sessionStorageMode; + private _sessionStore?; + private _onsessioninitialized?; + private _onsessionclosed?; + private _allowedHosts?; + private _allowedOrigins?; + private _enableDnsRebindingProtection; + private _retryInterval?; + sessionId?: string; + onclose?: () => void; + onerror?: (error: Error) => void; + onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void; + constructor(options: StreamableHTTPServerTransportOptions); + /** + * Returns the current session storage mode + */ + get sessionStorageMode(): SessionStorageMode; + /** + * Returns true if using external session storage + */ + get isUsingExternalSessionStore(): boolean; + /** + * Starts the transport. This is required by the Transport interface but is a no-op + * for the Streamable HTTP transport as connections are managed per-request. + */ + start(): Promise; + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + private validateRequestHeaders; + /** + * Handles an incoming HTTP request, whether GET or POST + */ + handleRequest(req: IncomingMessage & { + auth?: AuthInfo; + }, res: ServerResponse, parsedBody?: unknown): Promise; + /** + * Writes a priming event to establish resumption capability. + * Only sends if eventStore is configured (opt-in for resumability). + */ + private _maybeWritePrimingEvent; + /** + * Handles GET requests for SSE stream + */ + private handleGetRequest; + /** + * Replays events that would have been sent after the specified event ID + * Only used when resumability is enabled + */ + private replayEvents; + /** + * Writes an event to the SSE stream with proper formatting + */ + private writeSSEEvent; + /** + * Handles unsupported requests (PUT, PATCH, etc.) + */ + private handleUnsupportedRequest; + /** + * Handles POST requests containing JSON-RPC messages + */ + private handlePostRequest; + /** + * Handles DELETE requests to terminate sessions + */ + private handleDeleteRequest; + /** + * Validates session ID for non-initialization requests. + * + * When sessionStore is provided, validation checks the external store, + * enabling multi-node deployments where different pods may handle requests + * for the same session. + * + * Returns true if the session is valid, false otherwise. + */ + private validateSession; + private validateProtocolVersion; + close(): Promise; + /** + * Close an SSE stream for a specific request, triggering client reconnection. + * Use this to implement polling behavior during long-running operations - + * client will reconnect after the retry interval specified in the priming event. + */ + closeSSEStream(requestId: RequestId): void; + send(message: JSONRPCMessage, options?: { + relatedRequestId?: RequestId; + }): Promise; +} +//# sourceMappingURL=streamableHttp.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/streamableHttp.d.ts.map b/dist/esm/server/streamableHttp.d.ts.map new file mode 100644 index 000000000..907ee061f --- /dev/null +++ b/dist/esm/server/streamableHttp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.d.ts","sourceRoot":"","sources":["../../../src/server/streamableHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACH,gBAA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AAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BzH;;;OAGG;YACW,uBAAuB;IAcrC;;OAEG;YACW,gBAAgB;IAiF9B;;;OAGG;YACW,YAAY;IA6E1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;YACW,wBAAwB;IAetC;;OAEG;YACW,iBAAiB;IAiN/B;;OAEG;YACW,mBAAmB;IAkBjC;;;;;;;;OAQG;YACW,eAAe;IAyI7B,OAAO,CAAC,uBAAuB;IAsBzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B;;;;OAIG;IACH,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAWpC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA+FjG"} \ No newline at end of file diff --git a/dist/esm/server/streamableHttp.js b/dist/esm/server/streamableHttp.js new file mode 100644 index 000000000..a550c7f20 --- /dev/null +++ b/dist/esm/server/streamableHttp.js @@ -0,0 +1,801 @@ +import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from '../types.js'; +import getRawBody from 'raw-body'; +import contentType from 'content-type'; +import { randomUUID } from 'node:crypto'; +const MAXIMUM_MESSAGE_SIZE = '4mb'; +/** + * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. + * It supports both SSE streaming and direct HTTP responses. + * + * Usage example: + * + * ```typescript + * // Stateful mode - server sets the session ID + * const statefulTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * }); + * + * // Stateless mode - explicitly set session ID to undefined + * const statelessTransport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: undefined, + * }); + * + * // Using with pre-parsed request body + * app.post('/mcp', (req, res) => { + * transport.handleRequest(req, res, req.body); + * }); + * + * // With distributed session store (Redis) for multi-pod deployments + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: myRedisSessionStore + * }); + * ``` + * + * In stateful mode: + * - Session ID is generated and included in response headers + * - Session ID is always included in initialization responses + * - Requests with invalid session IDs are rejected with 404 Not Found + * - Non-initialization requests without a session ID are rejected with 400 Bad Request + * - State is maintained in-memory (connections, message history) or externally via sessionStore + * + * In stateless mode: + * - No Session ID is included in any responses + * - No session validation is performed + */ +export class StreamableHTTPServerTransport { + constructor(options) { + var _a, _b, _c; + this._started = false; + this._streamMapping = new Map(); + this._requestToStreamMapping = new Map(); + this._requestResponseMap = new Map(); + this._initialized = false; + this._enableJsonResponse = false; + this._standaloneSseStreamId = '_GET_stream'; + this.sessionIdGenerator = options.sessionIdGenerator; + this._enableJsonResponse = (_a = options.enableJsonResponse) !== null && _a !== void 0 ? _a : false; + this._eventStore = options.eventStore; + this._sessionStorageMode = (_b = options.sessionStorageMode) !== null && _b !== void 0 ? _b : 'memory'; + this._sessionStore = options.sessionStore; + this._onsessioninitialized = options.onsessioninitialized; + this._onsessionclosed = options.onsessionclosed; + this._allowedHosts = options.allowedHosts; + this._allowedOrigins = options.allowedOrigins; + this._enableDnsRebindingProtection = (_c = options.enableDnsRebindingProtection) !== null && _c !== void 0 ? _c : false; + this._retryInterval = options.retryInterval; + // Validate configuration + if (this._sessionStorageMode === 'external' && !this._sessionStore) { + throw new Error('SessionStore is required when sessionStorageMode is "external". ' + + 'Please provide a sessionStore implementation (e.g., RedisSessionStore) or use sessionStorageMode: "memory".'); + } + } + /** + * Returns the current session storage mode + */ + get sessionStorageMode() { + return this._sessionStorageMode; + } + /** + * Returns true if using external session storage + */ + get isUsingExternalSessionStore() { + return this._sessionStorageMode === 'external' && this._sessionStore !== undefined; + } + /** + * Starts the transport. This is required by the Transport interface but is a no-op + * for the Streamable HTTP transport as connections are managed per-request. + */ + async start() { + if (this._started) { + throw new Error('Transport already started'); + } + this._started = true; + } + /** + * Validates request headers for DNS rebinding protection. + * @returns Error message if validation fails, undefined if validation passes. + */ + validateRequestHeaders(req) { + // Skip validation if protection is not enabled + if (!this._enableDnsRebindingProtection) { + return undefined; + } + // Validate Host header if allowedHosts is configured + if (this._allowedHosts && this._allowedHosts.length > 0) { + const hostHeader = req.headers.host; + if (!hostHeader || !this._allowedHosts.includes(hostHeader)) { + return `Invalid Host header: ${hostHeader}`; + } + } + // Validate Origin header if allowedOrigins is configured + if (this._allowedOrigins && this._allowedOrigins.length > 0) { + const originHeader = req.headers.origin; + if (!originHeader || !this._allowedOrigins.includes(originHeader)) { + return `Invalid Origin header: ${originHeader}`; + } + } + return undefined; + } + /** + * Handles an incoming HTTP request, whether GET or POST + */ + async handleRequest(req, res, parsedBody) { + var _a; + // Validate request headers for DNS rebinding protection + const validationError = this.validateRequestHeaders(req); + if (validationError) { + res.writeHead(403).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: validationError + }, + id: null + })); + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error(validationError)); + return; + } + if (req.method === 'POST') { + await this.handlePostRequest(req, res, parsedBody); + } + else if (req.method === 'GET') { + await this.handleGetRequest(req, res); + } + else if (req.method === 'DELETE') { + await this.handleDeleteRequest(req, res); + } + else { + await this.handleUnsupportedRequest(res); + } + } + /** + * Writes a priming event to establish resumption capability. + * Only sends if eventStore is configured (opt-in for resumability). + */ + async _maybeWritePrimingEvent(res, streamId) { + if (!this._eventStore) { + return; + } + const primingEventId = await this._eventStore.storeEvent(streamId, {}); + let primingEvent = `id: ${primingEventId}\ndata: \n\n`; + if (this._retryInterval !== undefined) { + primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`; + } + res.write(primingEvent); + } + /** + * Handles GET requests for SSE stream + */ + async handleGetRequest(req, res) { + // The client MUST include an Accept header, listing text/event-stream as a supported content type. + const acceptHeader = req.headers.accept; + if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('text/event-stream'))) { + res.writeHead(406).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Not Acceptable: Client must accept text/event-stream' + }, + id: null + })); + return; + } + // If an Mcp-Session-Id is returned by the server during initialization, + // clients using the Streamable HTTP transport MUST include it + // in the Mcp-Session-Id header on all of their subsequent HTTP requests. + if (!await this.validateSession(req, res)) { + return; + } + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Handle resumability: check for Last-Event-ID header + if (this._eventStore) { + const lastEventId = req.headers['last-event-id']; + if (lastEventId) { + await this.replayEvents(lastEventId, res); + return; + } + } + // The server MUST either return Content-Type: text/event-stream in response to this HTTP GET, + // or else return HTTP 405 Method Not Allowed + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }; + // After initialization, always include the session ID if we have one + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + // Check if there's already an active standalone SSE stream for this session + if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) { + // Only one GET SSE stream is allowed per session + res.writeHead(409).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Conflict: Only one SSE stream is allowed per session' + }, + id: null + })); + return; + } + // We need to send headers immediately as messages will arrive much later, + // otherwise the client will just wait for the first message + res.writeHead(200, headers).flushHeaders(); + // Assign the response to the standalone SSE stream + this._streamMapping.set(this._standaloneSseStreamId, res); + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(this._standaloneSseStreamId); + }); + // Add error handler for standalone SSE stream + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + } + /** + * Replays events that would have been sent after the specified event ID + * Only used when resumability is enabled + */ + async replayEvents(lastEventId, res) { + var _a; + if (!this._eventStore) { + return; + } + try { + // If getStreamIdForEventId is available, use it for conflict checking + let streamId; + if (this._eventStore.getStreamIdForEventId) { + streamId = await this._eventStore.getStreamIdForEventId(lastEventId); + if (!streamId) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Invalid event ID format' + }, + id: null + })); + return; + } + // Check conflict with the SAME streamId we'll use for mapping + if (this._streamMapping.get(streamId) !== undefined) { + res.writeHead(409).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Conflict: Stream already has an active connection' + }, + id: null + })); + return; + } + } + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + Connection: 'keep-alive' + }; + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + res.writeHead(200, headers).flushHeaders(); + // Replay events - returns the streamId for backwards compatibility + const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, { + send: async (eventId, message) => { + var _a; + if (!this.writeSSEEvent(res, message, eventId)) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, new Error('Failed replay events')); + res.end(); + } + } + }); + this._streamMapping.set(replayedStreamId, res); + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(replayedStreamId); + }); + // Add error handler for replay stream + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + } + catch (error) { + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + } + } + /** + * Writes an event to the SSE stream with proper formatting + */ + writeSSEEvent(res, message, eventId) { + let eventData = `event: message\n`; + // Include event ID if provided - this is important for resumability + if (eventId) { + eventData += `id: ${eventId}\n`; + } + eventData += `data: ${JSON.stringify(message)}\n\n`; + return res.write(eventData); + } + /** + * Handles unsupported requests (PUT, PATCH, etc.) + */ + async handleUnsupportedRequest(res) { + res.writeHead(405, { + Allow: 'GET, POST, DELETE' + }).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Method not allowed.' + }, + id: null + })); + } + /** + * Handles POST requests containing JSON-RPC messages + */ + async handlePostRequest(req, res, parsedBody) { + var _a, _b, _c, _d, _e; + try { + // Validate the Accept header + const acceptHeader = req.headers.accept; + // The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types. + if (!(acceptHeader === null || acceptHeader === void 0 ? void 0 : acceptHeader.includes('application/json')) || !acceptHeader.includes('text/event-stream')) { + res.writeHead(406).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Not Acceptable: Client must accept both application/json and text/event-stream' + }, + id: null + })); + return; + } + const ct = req.headers['content-type']; + if (!ct || !ct.includes('application/json')) { + res.writeHead(415).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Unsupported Media Type: Content-Type must be application/json' + }, + id: null + })); + return; + } + const authInfo = req.auth; + const requestInfo = { headers: req.headers }; + let rawMessage; + if (parsedBody !== undefined) { + rawMessage = parsedBody; + } + else { + const parsedCt = contentType.parse(ct); + const body = await getRawBody(req, { + limit: MAXIMUM_MESSAGE_SIZE, + encoding: (_a = parsedCt.parameters.charset) !== null && _a !== void 0 ? _a : 'utf-8' + }); + rawMessage = JSON.parse(body.toString()); + } + let messages; + // handle batch and single messages + if (Array.isArray(rawMessage)) { + messages = rawMessage.map(msg => JSONRPCMessageSchema.parse(msg)); + } + else { + messages = [JSONRPCMessageSchema.parse(rawMessage)]; + } + // Check if this is an initialization request + // https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/ + const isInitializationRequest = messages.some(isInitializeRequest); + if (isInitializationRequest) { + // Check if session already exists (either in-memory or in session store) + let sessionAlreadyExists = this._initialized && this.sessionId !== undefined; + // If using external session storage, also check there + if (!sessionAlreadyExists && this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + sessionAlreadyExists = await this._sessionStore.sessionExists(this.sessionId); + } + // If it's a server with session management and the session ID is already set we should reject the request + // to avoid re-initialization. + if (sessionAlreadyExists) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32600, + message: 'Invalid Request: Server already initialized' + }, + id: null + })); + return; + } + if (messages.length > 1) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32600, + message: 'Invalid Request: Only one initialization request is allowed' + }, + id: null + })); + return; + } + this.sessionId = (_b = this.sessionIdGenerator) === null || _b === void 0 ? void 0 : _b.call(this); + this._initialized = true; + // Store session in external store if using external storage mode + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + const sessionData = { + sessionId: this.sessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + await this._sessionStore.storeSession(this.sessionId, sessionData); + } + // If we have a session ID and an onsessioninitialized handler, call it immediately + // This is needed in cases where the server needs to keep track of multiple sessions + if (this.sessionId && this._onsessioninitialized) { + await Promise.resolve(this._onsessioninitialized(this.sessionId)); + } + } + if (!isInitializationRequest) { + // If an Mcp-Session-Id is returned by the server during initialization, + // clients using the Streamable HTTP transport MUST include it + // in the Mcp-Session-Id header on all of their subsequent HTTP requests. + if (!await this.validateSession(req, res)) { + return; + } + // Mcp-Protocol-Version header is required for all requests after initialization. + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Update session activity if using external session storage + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.updateSessionActivity(this.sessionId); + } + } + // check if it contains requests + const hasRequests = messages.some(isJSONRPCRequest); + if (!hasRequests) { + // if it only contains notifications or responses, return 202 + res.writeHead(202).end(); + // handle each message + for (const message of messages) { + (_c = this.onmessage) === null || _c === void 0 ? void 0 : _c.call(this, message, { authInfo, requestInfo }); + } + } + else if (hasRequests) { + // The default behavior is to use SSE streaming + // but in some cases server will return JSON responses + const streamId = randomUUID(); + if (!this._enableJsonResponse) { + const headers = { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache', + Connection: 'keep-alive' + }; + // After initialization, always include the session ID if we have one + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + res.writeHead(200, headers); + await this._maybeWritePrimingEvent(res, streamId); + } + // Store the response for this request to send messages back through this connection + // We need to track by request ID to maintain the connection + for (const message of messages) { + if (isJSONRPCRequest(message)) { + this._streamMapping.set(streamId, res); + this._requestToStreamMapping.set(message.id, streamId); + } + } + // Set up close handler for client disconnects + res.on('close', () => { + this._streamMapping.delete(streamId); + }); + // Add error handler for stream write errors + res.on('error', error => { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + }); + // handle each message + for (const message of messages) { + (_d = this.onmessage) === null || _d === void 0 ? void 0 : _d.call(this, message, { authInfo, requestInfo }); + } + // The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses + // This will be handled by the send() method when responses are ready + } + } + catch (error) { + // return JSON-RPC formatted error + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32700, + message: 'Parse error', + data: String(error) + }, + id: null + })); + (_e = this.onerror) === null || _e === void 0 ? void 0 : _e.call(this, error); + } + } + /** + * Handles DELETE requests to terminate sessions + */ + async handleDeleteRequest(req, res) { + var _a; + if (!await this.validateSession(req, res)) { + return; + } + if (!this.validateProtocolVersion(req, res)) { + return; + } + // Delete session from external store if using external storage mode + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.deleteSession(this.sessionId); + } + await Promise.resolve((_a = this._onsessionclosed) === null || _a === void 0 ? void 0 : _a.call(this, this.sessionId)); + await this.close(); + res.writeHead(200).end(); + } + /** + * Validates session ID for non-initialization requests. + * + * When sessionStore is provided, validation checks the external store, + * enabling multi-node deployments where different pods may handle requests + * for the same session. + * + * Returns true if the session is valid, false otherwise. + */ + async validateSession(req, res) { + if (this.sessionIdGenerator === undefined) { + // If the sessionIdGenerator ID is not set, the session management is disabled + // and we don't need to validate the session ID + return true; + } + const requestSessionId = req.headers['mcp-session-id']; + // If using external session storage mode, check external store + if (this._sessionStorageMode === 'external' && this._sessionStore) { + if (!requestSessionId) { + // Non-initialization requests without a session ID should return 400 Bad Request + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header is required' + }, + id: null + })); + return false; + } + else if (Array.isArray(requestSessionId)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header must be a single value' + }, + id: null + })); + return false; + } + // Check if session exists in external store + const sessionData = await this._sessionStore.getSession(requestSessionId); + if (!sessionData) { + res.writeHead(404).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32001, + message: 'Session not found' + }, + id: null + })); + return false; + } + if (!sessionData.initialized) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Server not initialized' + }, + id: null + })); + return false; + } + // Session is valid - update local state if needed + // This enables cross-pod session recovery + if (this.sessionId !== requestSessionId) { + this.sessionId = requestSessionId; + this._initialized = true; + } + return true; + } + // Original in-memory validation logic (no session store) + if (!this._initialized) { + // If the server has not been initialized yet, reject all requests + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Server not initialized' + }, + id: null + })); + return false; + } + if (!requestSessionId) { + // Non-initialization requests without a session ID should return 400 Bad Request + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header is required' + }, + id: null + })); + return false; + } + else if (Array.isArray(requestSessionId)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header must be a single value' + }, + id: null + })); + return false; + } + else if (requestSessionId !== this.sessionId) { + // Reject requests with invalid session ID with 404 Not Found + res.writeHead(404).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32001, + message: 'Session not found' + }, + id: null + })); + return false; + } + return true; + } + validateProtocolVersion(req, res) { + var _a; + let protocolVersion = (_a = req.headers['mcp-protocol-version']) !== null && _a !== void 0 ? _a : DEFAULT_NEGOTIATED_PROTOCOL_VERSION; + if (Array.isArray(protocolVersion)) { + protocolVersion = protocolVersion[protocolVersion.length - 1]; + } + if (!SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) { + res.writeHead(400).end(JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: `Bad Request: Unsupported protocol version (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})` + }, + id: null + })); + return false; + } + return true; + } + async close() { + var _a; + // Close all SSE connections + this._streamMapping.forEach(response => { + response.end(); + }); + this._streamMapping.clear(); + // Clear any pending responses + this._requestResponseMap.clear(); + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + } + /** + * Close an SSE stream for a specific request, triggering client reconnection. + * Use this to implement polling behavior during long-running operations - + * client will reconnect after the retry interval specified in the priming event. + */ + closeSSEStream(requestId) { + const streamId = this._requestToStreamMapping.get(requestId); + if (!streamId) + return; + const stream = this._streamMapping.get(streamId); + if (stream) { + stream.end(); + this._streamMapping.delete(streamId); + } + } + async send(message, options) { + let requestId = options === null || options === void 0 ? void 0 : options.relatedRequestId; + if (isJSONRPCResponse(message) || isJSONRPCError(message)) { + // If the message is a response, use the request ID from the message + requestId = message.id; + } + // Check if this message should be sent on the standalone SSE stream (no request ID) + // Ignore notifications from tools (which have relatedRequestId set) + // Those will be sent via dedicated response SSE streams + if (requestId === undefined) { + // For standalone SSE streams, we can only send requests and notifications + if (isJSONRPCResponse(message) || isJSONRPCError(message)) { + throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request'); + } + const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId); + if (standaloneSse === undefined) { + // The spec says the server MAY send messages on the stream, so it's ok to discard if no stream + return; + } + // Generate and store event ID if event store is provided + let eventId; + if (this._eventStore) { + // Stores the event and gets the generated event ID + eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message); + } + // Send the message to the standalone SSE stream + this.writeSSEEvent(standaloneSse, message, eventId); + return; + } + // Get the response for this request + const streamId = this._requestToStreamMapping.get(requestId); + const response = this._streamMapping.get(streamId); + if (!streamId) { + throw new Error(`No connection established for request ID: ${String(requestId)}`); + } + if (!this._enableJsonResponse) { + // For SSE responses, generate event ID if event store is provided + let eventId; + if (this._eventStore) { + eventId = await this._eventStore.storeEvent(streamId, message); + } + if (response) { + // Write the event to the response stream + this.writeSSEEvent(response, message, eventId); + } + } + if (isJSONRPCResponse(message) || isJSONRPCError(message)) { + this._requestResponseMap.set(requestId, message); + const relatedIds = Array.from(this._requestToStreamMapping.entries()) + .filter(([_, streamId]) => this._streamMapping.get(streamId) === response) + .map(([id]) => id); + // Check if we have responses for all requests using this connection + const allResponsesReady = relatedIds.every(id => this._requestResponseMap.has(id)); + if (allResponsesReady) { + if (!response) { + throw new Error(`No connection established for request ID: ${String(requestId)}`); + } + if (this._enableJsonResponse) { + // All responses ready, send as JSON + const headers = { + 'Content-Type': 'application/json' + }; + if (this.sessionId !== undefined) { + headers['mcp-session-id'] = this.sessionId; + } + const responses = relatedIds.map(id => this._requestResponseMap.get(id)); + response.writeHead(200, headers); + if (responses.length === 1) { + response.end(JSON.stringify(responses[0])); + } + else { + response.end(JSON.stringify(responses)); + } + } + else { + // End the SSE stream + response.end(); + } + // Clean up + for (const id of relatedIds) { + this._requestResponseMap.delete(id); + this._requestToStreamMapping.delete(id); + } + } + } + } +} +//# sourceMappingURL=streamableHttp.js.map \ No newline at end of file diff --git a/dist/esm/server/streamableHttp.js.map b/dist/esm/server/streamableHttp.js.map new file mode 100644 index 000000000..77df8c6e5 --- /dev/null +++ b/dist/esm/server/streamableHttp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"streamableHttp.js","sourceRoot":"","sources":["../../../src/server/streamableHttp.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAEjB,oBAAoB,EAEpB,2BAA2B,EAC3B,mCAAmC,EACtC,MAAM,aAAa,CAAC;AACrB,OAAO,U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AAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;oBAC5C,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,qBAAqB;oBACrB,QAAQ,CAAC,GAAG,EAAE,CAAC;gBACnB,CAAC;gBACD,WAAW;gBACX,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;oBAC1B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACpC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC5C,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/server/zod-compat.d.ts b/dist/esm/server/zod-compat.d.ts new file mode 100644 index 000000000..13fb9723c --- /dev/null +++ b/dist/esm/server/zod-compat.d.ts @@ -0,0 +1,82 @@ +import type * as z3 from 'zod/v3'; +import type * as z4 from 'zod/v4/core'; +export type AnySchema = z3.ZodTypeAny | z4.$ZodType; +export type AnyObjectSchema = z3.AnyZodObject | z4.$ZodObject | AnySchema; +export type ZodRawShapeCompat = Record; +export interface ZodV3Internal { + _def?: { + typeName?: string; + value?: unknown; + values?: unknown[]; + shape?: Record | (() => Record); + description?: string; + }; + shape?: Record | (() => Record); + value?: unknown; +} +export interface ZodV4Internal { + _zod?: { + def?: { + typeName?: string; + value?: unknown; + values?: unknown[]; + shape?: Record | (() => Record); + description?: string; + }; + }; + value?: unknown; +} +export type SchemaOutput = S extends z3.ZodTypeAny ? z3.infer : S extends z4.$ZodType ? z4.output : never; +export type SchemaInput = S extends z3.ZodTypeAny ? z3.input : S extends z4.$ZodType ? z4.input : never; +/** + * Infers the output type from a ZodRawShapeCompat (raw shape object). + * Maps over each key in the shape and infers the output type from each schema. + */ +export type ShapeOutput = { + [K in keyof Shape]: SchemaOutput; +}; +export declare function isZ4Schema(s: AnySchema): s is z4.$ZodType; +export declare function objectFromShape(shape: ZodRawShapeCompat): AnyObjectSchema; +export declare function safeParse(schema: S, data: unknown): { + success: true; + data: SchemaOutput; +} | { + success: false; + error: unknown; +}; +export declare function safeParseAsync(schema: S, data: unknown): Promise<{ + success: true; + data: SchemaOutput; +} | { + success: false; + error: unknown; +}>; +export declare function getObjectShape(schema: AnyObjectSchema | undefined): Record | undefined; +/** + * Normalizes a schema to an object schema. Handles both: + * - Already-constructed object schemas (v3 or v4) + * - Raw shapes that need to be wrapped into object schemas + */ +export declare function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | undefined): AnyObjectSchema | undefined; +/** + * Safely extracts an error message from a parse result error. + * Zod errors can have different structures, so we handle various cases. + */ +export declare function getParseErrorMessage(error: unknown): string; +/** + * Gets the description from a schema, if available. + * Works with both Zod v3 and v4. + */ +export declare function getSchemaDescription(schema: AnySchema): string | undefined; +/** + * Checks if a schema is optional. + * Works with both Zod v3 and v4. + */ +export declare function isSchemaOptional(schema: AnySchema): boolean; +/** + * Gets the literal value from a schema, if it's a literal schema. + * Works with both Zod v3 and v4. + * Returns undefined if the schema is not a literal or the value cannot be determined. + */ +export declare function getLiteralValue(schema: AnySchema): unknown; +//# sourceMappingURL=zod-compat.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/zod-compat.d.ts.map b/dist/esm/server/zod-compat.d.ts.map new file mode 100644 index 000000000..608ca930c --- /dev/null +++ b/dist/esm/server/zod-compat.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-compat.d.ts","sourceRoot":"","sources":["../../../src/server/zod-compat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAMvC,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC,YAAY,GAAG,EAAE,CAAC,UAAU,GAAG,SAAS,CAAC;AAC1E,MAAM,MAAM,iBA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Ae,GAAG,SAAS,CAiDpH;AAGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAoB3D;AAGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAQ1E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAW3D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAwB1D"} \ No newline at end of file diff --git a/dist/esm/server/zod-compat.js b/dist/esm/server/zod-compat.js new file mode 100644 index 000000000..0ff17cc10 --- /dev/null +++ b/dist/esm/server/zod-compat.js @@ -0,0 +1,217 @@ +// zod-compat.ts +// ---------------------------------------------------- +// Unified types + helpers to accept Zod v3 and v4 (Mini) +// ---------------------------------------------------- +import * as z3rt from 'zod/v3'; +import * as z4mini from 'zod/v4-mini'; +// --- Runtime detection --- +export function isZ4Schema(s) { + // Present on Zod 4 (Classic & Mini) schemas; absent on Zod 3 + const schema = s; + return !!schema._zod; +} +// --- Schema construction --- +export function objectFromShape(shape) { + const values = Object.values(shape); + if (values.length === 0) + return z4mini.object({}); // default to v4 Mini + const allV4 = values.every(isZ4Schema); + const allV3 = values.every(s => !isZ4Schema(s)); + if (allV4) + return z4mini.object(shape); + if (allV3) + return z3rt.object(shape); + throw new Error('Mixed Zod versions detected in object shape.'); +} +// --- Unified parsing --- +export function safeParse(schema, data) { + if (isZ4Schema(schema)) { + // Mini exposes top-level safeParse + const result = z4mini.safeParse(schema, data); + return result; + } + const v3Schema = schema; + const result = v3Schema.safeParse(data); + return result; +} +export async function safeParseAsync(schema, data) { + if (isZ4Schema(schema)) { + // Mini exposes top-level safeParseAsync + const result = await z4mini.safeParseAsync(schema, data); + return result; + } + const v3Schema = schema; + const result = await v3Schema.safeParseAsync(data); + return result; +} +// --- Shape extraction --- +export function getObjectShape(schema) { + var _a, _b; + if (!schema) + return undefined; + // Zod v3 exposes `.shape`; Zod v4 keeps the shape on `_zod.def.shape` + let rawShape; + if (isZ4Schema(schema)) { + const v4Schema = schema; + rawShape = (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.shape; + } + else { + const v3Schema = schema; + rawShape = v3Schema.shape; + } + if (!rawShape) + return undefined; + if (typeof rawShape === 'function') { + try { + return rawShape(); + } + catch (_c) { + return undefined; + } + } + return rawShape; +} +// --- Schema normalization --- +/** + * Normalizes a schema to an object schema. Handles both: + * - Already-constructed object schemas (v3 or v4) + * - Raw shapes that need to be wrapped into object schemas + */ +export function normalizeObjectSchema(schema) { + var _a; + if (!schema) + return undefined; + // First check if it's a raw shape (Record) + // Raw shapes don't have _def or _zod properties and aren't schemas themselves + if (typeof schema === 'object') { + // Check if it's actually a ZodRawShapeCompat (not a schema instance) + // by checking if it lacks schema-like internal properties + const asV3 = schema; + const asV4 = schema; + // If it's not a schema instance (no _def or _zod), it might be a raw shape + if (!asV3._def && !asV4._zod) { + // Check if all values are schemas (heuristic to confirm it's a raw shape) + const values = Object.values(schema); + if (values.length > 0 && + values.every(v => typeof v === 'object' && + v !== null && + (v._def !== undefined || + v._zod !== undefined || + typeof v.parse === 'function'))) { + return objectFromShape(schema); + } + } + } + // If we get here, it should be an AnySchema (not a raw shape) + // Check if it's already an object schema + if (isZ4Schema(schema)) { + // Check if it's a v4 object + const v4Schema = schema; + const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + if (def && (def.typeName === 'object' || def.shape !== undefined)) { + return schema; + } + } + else { + // Check if it's a v3 object + const v3Schema = schema; + if (v3Schema.shape !== undefined) { + return schema; + } + } + return undefined; +} +// --- Error message extraction --- +/** + * Safely extracts an error message from a parse result error. + * Zod errors can have different structures, so we handle various cases. + */ +export function getParseErrorMessage(error) { + if (error && typeof error === 'object') { + // Try common error structures + if ('message' in error && typeof error.message === 'string') { + return error.message; + } + if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) { + const firstIssue = error.issues[0]; + if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) { + return String(firstIssue.message); + } + } + // Fallback: try to stringify the error + try { + return JSON.stringify(error); + } + catch (_a) { + return String(error); + } + } + return String(error); +} +// --- Schema metadata access --- +/** + * Gets the description from a schema, if available. + * Works with both Zod v3 and v4. + */ +export function getSchemaDescription(schema) { + var _a, _b, _c, _d; + if (isZ4Schema(schema)) { + const v4Schema = schema; + return (_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.description; + } + const v3Schema = schema; + // v3 may have description on the schema itself or in _def + return (_c = schema.description) !== null && _c !== void 0 ? _c : (_d = v3Schema._def) === null || _d === void 0 ? void 0 : _d.description; +} +/** + * Checks if a schema is optional. + * Works with both Zod v3 and v4. + */ +export function isSchemaOptional(schema) { + var _a, _b, _c; + if (isZ4Schema(schema)) { + const v4Schema = schema; + return ((_b = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def) === null || _b === void 0 ? void 0 : _b.typeName) === 'ZodOptional'; + } + const v3Schema = schema; + // v3 has isOptional() method + if (typeof schema.isOptional === 'function') { + return schema.isOptional(); + } + return ((_c = v3Schema._def) === null || _c === void 0 ? void 0 : _c.typeName) === 'ZodOptional'; +} +/** + * Gets the literal value from a schema, if it's a literal schema. + * Works with both Zod v3 and v4. + * Returns undefined if the schema is not a literal or the value cannot be determined. + */ +export function getLiteralValue(schema) { + var _a; + if (isZ4Schema(schema)) { + const v4Schema = schema; + const def = (_a = v4Schema._zod) === null || _a === void 0 ? void 0 : _a.def; + if (def) { + // Try various ways to get the literal value + if (def.value !== undefined) + return def.value; + if (Array.isArray(def.values) && def.values.length > 0) { + return def.values[0]; + } + } + } + const v3Schema = schema; + const def = v3Schema._def; + if (def) { + if (def.value !== undefined) + return def.value; + if (Array.isArray(def.values) && def.values.length > 0) { + return def.values[0]; + } + } + // Fallback: check for direct value property (some Zod versions) + const directValue = schema.value; + if (directValue !== undefined) + return directValue; + return undefined; +} +//# sourceMappingURL=zod-compat.js.map \ No newline at end of file diff --git a/dist/esm/server/zod-compat.js.map b/dist/esm/server/zod-compat.js.map new file mode 100644 index 000000000..df880a39d --- /dev/null +++ b/dist/esm/server/zod-compat.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-compat.js","sourceRoot":"","sources":["../../../src/server/zod-compat.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,uDAAuD;AACvD,yDAAyD;AACzD,uDAAuD;AAKvD,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AA+CtC,4BAA4B;AAC5B,MAAM,UAAU,UAAU,CAAC,CAAY;IACnC,6DAA6D;IAC7D,MAAM,MAAM,GAAG,CAA6B,CAAC;IAC7C,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;AACzB,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,eAAe,CAAC,KAAwB;IACpD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,qBAAqB;IAExE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,IAAI,KAAK;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,KAAoC,CAAC,CAAC;IACtE,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAsC,CAAC,CAAC;IAEtE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;AACpE,CAA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YACN,4CAA4C;YAC5C,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;gBAAE,OAAO,GAAG,CAAC,KAAK,CAAC;YAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,MAAkC,CAAC;IACpD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC1B,IAAI,GAAG,EAAE,CAAC;QACN,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;IACL,CAAC;IACD,gEAAgE;IAChE,MAAM,WAAW,GAAI,MAA8B,CAAC,KAAK,CAAC;IAC1D,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAClD,OAAO,SAAS,CAAC;AACrB,CAAC"} \ No newline at end of file diff --git a/dist/esm/server/zod-json-schema-compat.d.ts b/dist/esm/server/zod-json-schema-compat.d.ts new file mode 100644 index 000000000..3a04452b4 --- /dev/null +++ b/dist/esm/server/zod-json-schema-compat.d.ts @@ -0,0 +1,12 @@ +import { AnySchema, AnyObjectSchema } from './zod-compat.js'; +type JsonSchema = Record; +type CommonOpts = { + strictUnions?: boolean; + pipeStrategy?: 'input' | 'output'; + target?: 'jsonSchema7' | 'draft-7' | 'jsonSchema2019-09' | 'draft-2020-12'; +}; +export declare function toJsonSchemaCompat(schema: AnyObjectSchema, opts?: CommonOpts): JsonSchema; +export declare function getMethodLiteral(schema: AnyObjectSchema): string; +export declare function parseWithCompat(schema: AnySchema, data: unknown): unknown; +export {}; +//# sourceMappingURL=zod-json-schema-compat.d.ts.map \ No newline at end of file diff --git a/dist/esm/server/zod-json-schema-compat.d.ts.map b/dist/esm/server/zod-json-schema-compat.d.ts.map new file mode 100644 index 000000000..0b851bf50 --- /dev/null +++ b/dist/esm/server/zod-json-schema-compat.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-json-schema-compat.d.ts","sourceRoot":"","sources":["../../../src/server/zod-json-schema-compat.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,eAAe,EAA0D,MAAM,iBAAiB,CAAC;AAGrH,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAG1C,KAAK,UAAU,GAAG;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,mBAAmB,GAAG,eAAe,CAAC;CAC9E,CAAC;AASF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,CAczF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAahE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAMzE"} \ No newline at end of file diff --git a/dist/esm/server/zod-json-schema-compat.js b/dist/esm/server/zod-json-schema-compat.js new file mode 100644 index 000000000..bd2a25f20 --- /dev/null +++ b/dist/esm/server/zod-json-schema-compat.js @@ -0,0 +1,52 @@ +// zod-json-schema-compat.ts +// ---------------------------------------------------- +// JSON Schema conversion for both Zod v3 and Zod v4 (Mini) +// v3 uses your vendored converter; v4 uses Mini's toJSONSchema +// ---------------------------------------------------- +import * as z4mini from 'zod/v4-mini'; +import { getObjectShape, safeParse, isZ4Schema, getLiteralValue } from './zod-compat.js'; +import { zodToJsonSchema } from 'zod-to-json-schema'; +function mapMiniTarget(t) { + if (!t) + return 'draft-7'; + if (t === 'jsonSchema7' || t === 'draft-7') + return 'draft-7'; + if (t === 'jsonSchema2019-09' || t === 'draft-2020-12') + return 'draft-2020-12'; + return 'draft-7'; // fallback +} +export function toJsonSchemaCompat(schema, opts) { + var _a, _b, _c; + if (isZ4Schema(schema)) { + // v4 branch — use Mini's built-in toJSONSchema + return z4mini.toJSONSchema(schema, { + target: mapMiniTarget(opts === null || opts === void 0 ? void 0 : opts.target), + io: (_a = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _a !== void 0 ? _a : 'input' + }); + } + // v3 branch — use vendored converter + return zodToJsonSchema(schema, { + strictUnions: (_b = opts === null || opts === void 0 ? void 0 : opts.strictUnions) !== null && _b !== void 0 ? _b : true, + pipeStrategy: (_c = opts === null || opts === void 0 ? void 0 : opts.pipeStrategy) !== null && _c !== void 0 ? _c : 'input' + }); +} +export function getMethodLiteral(schema) { + const shape = getObjectShape(schema); + const methodSchema = shape === null || shape === void 0 ? void 0 : shape.method; + if (!methodSchema) { + throw new Error('Schema is missing a method literal'); + } + const value = getLiteralValue(methodSchema); + if (typeof value !== 'string') { + throw new Error('Schema method literal must be a string'); + } + return value; +} +export function parseWithCompat(schema, data) { + const result = safeParse(schema, data); + if (!result.success) { + throw result.error; + } + return result.data; +} +//# sourceMappingURL=zod-json-schema-compat.js.map \ No newline at end of file diff --git a/dist/esm/server/zod-json-schema-compat.js.map b/dist/esm/server/zod-json-schema-compat.js.map new file mode 100644 index 000000000..d6973cb1c --- /dev/null +++ b/dist/esm/server/zod-json-schema-compat.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zod-json-schema-compat.js","sourceRoot":"","sources":["../../../src/server/zod-json-schema-compat.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,uDAAuD;AACvD,2DA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AAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAA+B,CAAC;IAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,IAAa;IAC5D,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,MAAM,CAAC,KAAK,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACvB,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/auth-utils.d.ts b/dist/esm/shared/auth-utils.d.ts new file mode 100644 index 000000000..c966e30e7 --- /dev/null +++ b/dist/esm/shared/auth-utils.d.ts @@ -0,0 +1,23 @@ +/** + * Utilities for handling OAuth resource URIs. + */ +/** + * Converts a server URL to a resource URL by removing the fragment. + * RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component". + * Keeps everything else unchanged (scheme, domain, port, path, query). + */ +export declare function resourceUrlFromServerUrl(url: URL | string): URL; +/** + * Checks if a requested resource URL matches a configured resource URL. + * A requested resource matches if it has the same scheme, domain, port, + * and its path starts with the configured resource's path. + * + * @param requestedResource The resource URL being requested + * @param configuredResource The resource URL that has been configured + * @returns true if the requested resource matches the configured resource, false otherwise + */ +export declare function checkResourceAllowed({ requestedResource, configuredResource }: { + requestedResource: URL | string; + configuredResource: URL | string; +}): boolean; +//# sourceMappingURL=auth-utils.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/auth-utils.d.ts.map b/dist/esm/shared/auth-utils.d.ts.map new file mode 100644 index 000000000..30873de55 --- /dev/null +++ b/dist/esm/shared/auth-utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../../src/shared/auth-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,CAI/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EACjC,iBAAiB,EACjB,kBAAkB,EACrB,EAAE;IACC,iBAAiB,EAAE,GAAG,GAAG,MAAM,CAAC;IAChC,kBAAkB,EAAE,GAAG,GAAG,MAAM,CAAC;CACpC,GAAG,OAAO,CAwBV"} \ No newline at end of file diff --git a/dist/esm/shared/auth-utils.js b/dist/esm/shared/auth-utils.js new file mode 100644 index 000000000..1883885e4 --- /dev/null +++ b/dist/esm/shared/auth-utils.js @@ -0,0 +1,44 @@ +/** + * Utilities for handling OAuth resource URIs. + */ +/** + * Converts a server URL to a resource URL by removing the fragment. + * RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component". + * Keeps everything else unchanged (scheme, domain, port, path, query). + */ +export function resourceUrlFromServerUrl(url) { + const resourceURL = typeof url === 'string' ? new URL(url) : new URL(url.href); + resourceURL.hash = ''; // Remove fragment + return resourceURL; +} +/** + * Checks if a requested resource URL matches a configured resource URL. + * A requested resource matches if it has the same scheme, domain, port, + * and its path starts with the configured resource's path. + * + * @param requestedResource The resource URL being requested + * @param configuredResource The resource URL that has been configured + * @returns true if the requested resource matches the configured resource, false otherwise + */ +export function checkResourceAllowed({ requestedResource, configuredResource }) { + const requested = typeof requestedResource === 'string' ? new URL(requestedResource) : new URL(requestedResource.href); + const configured = typeof configuredResource === 'string' ? new URL(configuredResource) : new URL(configuredResource.href); + // Compare the origin (scheme, domain, and port) + if (requested.origin !== configured.origin) { + return false; + } + // Handle cases like requested=/foo and configured=/foo/ + if (requested.pathname.length < configured.pathname.length) { + return false; + } + // Check if the requested path starts with the configured path + // Ensure both paths end with / for proper comparison + // This ensures that if we have paths like "/api" and "/api/users", + // we properly detect that "/api/users" is a subpath of "/api" + // By adding a trailing slash if missing, we avoid false positives + // where paths like "/api123" would incorrectly match "/api" + const requestedPath = requested.pathname.endsWith('/') ? requested.pathname : requested.pathname + '/'; + const configuredPath = configured.pathname.endsWith('/') ? configured.pathname : configured.pathname + '/'; + return requestedPath.startsWith(configuredPath); +} +//# sourceMappingURL=auth-utils.js.map \ No newline at end of file diff --git a/dist/esm/shared/auth-utils.js.map b/dist/esm/shared/auth-utils.js.map new file mode 100644 index 000000000..3ced5af40 --- /dev/null +++ b/dist/esm/shared/auth-utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth-utils.js","sourceRoot":"","sources":["../../../src/shared/auth-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAiB;IACtD,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/E,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,kBAAkB;IACzC,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,EACjC,iBAAiB,EACjB,kBAAkB,EAIrB;IACG,MAAM,SAAS,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvH,MAAM,UAAU,GAAG,OAAO,kBAAkB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAE3H,gDAAgD;IAChD,IAAI,SAAS,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,wDAAwD;IACxD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,8DAA8D;IAC9D,qDAAqD;IACrD,mEAAmE;IACnE,8DAA8D;IAC9D,kEAAkE;IAClE,4DAA4D;IAC5D,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,GAAG,GAAG,CAAC;IACvG,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,GAAG,GAAG,CAAC;IAE3G,OAAO,aAAa,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACpD,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/auth.d.ts b/dist/esm/shared/auth.d.ts new file mode 100644 index 000000000..4e47be12b --- /dev/null +++ b/dist/esm/shared/auth.d.ts @@ -0,0 +1,240 @@ +import * as z from 'zod/v4'; +/** + * Reusable URL validation that disallows javascript: scheme + */ +export declare const SafeUrlSchema: z.ZodURL; +/** + * RFC 9728 OAuth Protected Resource Metadata + */ +export declare const OAuthProtectedResourceMetadataSchema: z.ZodObject<{ + resource: z.ZodString; + authorization_servers: z.ZodOptional>; + jwks_uri: z.ZodOptional; + scopes_supported: z.ZodOptional>; + bearer_methods_supported: z.ZodOptional>; + resource_signing_alg_values_supported: z.ZodOptional>; + resource_name: z.ZodOptional; + resource_documentation: z.ZodOptional; + resource_policy_uri: z.ZodOptional; + resource_tos_uri: z.ZodOptional; + tls_client_certificate_bound_access_tokens: z.ZodOptional; + authorization_details_types_supported: z.ZodOptional>; + dpop_signing_alg_values_supported: z.ZodOptional>; + dpop_bound_access_tokens_required: z.ZodOptional; +}, z.core.$loose>; +/** + * RFC 8414 OAuth 2.0 Authorization Server Metadata + */ +export declare const OAuthMetadataSchema: z.ZodObject<{ + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + revocation_endpoint: z.ZodOptional; + revocation_endpoint_auth_methods_supported: z.ZodOptional>; + revocation_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + introspection_endpoint: z.ZodOptional; + introspection_endpoint_auth_methods_supported: z.ZodOptional>; + introspection_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + code_challenge_methods_supported: z.ZodOptional>; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$loose>; +/** + * OpenID Connect Discovery 1.0 Provider Metadata + * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata + */ +export declare const OpenIdProviderMetadataSchema: z.ZodObject<{ + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + userinfo_endpoint: z.ZodOptional; + jwks_uri: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + acr_values_supported: z.ZodOptional>; + subject_types_supported: z.ZodArray; + id_token_signing_alg_values_supported: z.ZodArray; + id_token_encryption_alg_values_supported: z.ZodOptional>; + id_token_encryption_enc_values_supported: z.ZodOptional>; + userinfo_signing_alg_values_supported: z.ZodOptional>; + userinfo_encryption_alg_values_supported: z.ZodOptional>; + userinfo_encryption_enc_values_supported: z.ZodOptional>; + request_object_signing_alg_values_supported: z.ZodOptional>; + request_object_encryption_alg_values_supported: z.ZodOptional>; + request_object_encryption_enc_values_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + display_values_supported: z.ZodOptional>; + claim_types_supported: z.ZodOptional>; + claims_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + claims_locales_supported: z.ZodOptional>; + ui_locales_supported: z.ZodOptional>; + claims_parameter_supported: z.ZodOptional; + request_parameter_supported: z.ZodOptional; + request_uri_parameter_supported: z.ZodOptional; + require_request_uri_registration: z.ZodOptional; + op_policy_uri: z.ZodOptional; + op_tos_uri: z.ZodOptional; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$loose>; +/** + * OpenID Connect Discovery metadata that may include OAuth 2.0 fields + * This schema represents the real-world scenario where OIDC providers + * return a mix of OpenID Connect and OAuth 2.0 metadata fields + */ +export declare const OpenIdProviderDiscoveryMetadataSchema: z.ZodObject<{ + code_challenge_methods_supported: z.ZodOptional>; + issuer: z.ZodString; + authorization_endpoint: z.ZodURL; + token_endpoint: z.ZodURL; + userinfo_endpoint: z.ZodOptional; + jwks_uri: z.ZodURL; + registration_endpoint: z.ZodOptional; + scopes_supported: z.ZodOptional>; + response_types_supported: z.ZodArray; + response_modes_supported: z.ZodOptional>; + grant_types_supported: z.ZodOptional>; + acr_values_supported: z.ZodOptional>; + subject_types_supported: z.ZodArray; + id_token_signing_alg_values_supported: z.ZodArray; + id_token_encryption_alg_values_supported: z.ZodOptional>; + id_token_encryption_enc_values_supported: z.ZodOptional>; + userinfo_signing_alg_values_supported: z.ZodOptional>; + userinfo_encryption_alg_values_supported: z.ZodOptional>; + userinfo_encryption_enc_values_supported: z.ZodOptional>; + request_object_signing_alg_values_supported: z.ZodOptional>; + request_object_encryption_alg_values_supported: z.ZodOptional>; + request_object_encryption_enc_values_supported: z.ZodOptional>; + token_endpoint_auth_methods_supported: z.ZodOptional>; + token_endpoint_auth_signing_alg_values_supported: z.ZodOptional>; + display_values_supported: z.ZodOptional>; + claim_types_supported: z.ZodOptional>; + claims_supported: z.ZodOptional>; + service_documentation: z.ZodOptional; + claims_locales_supported: z.ZodOptional>; + ui_locales_supported: z.ZodOptional>; + claims_parameter_supported: z.ZodOptional; + request_parameter_supported: z.ZodOptional; + request_uri_parameter_supported: z.ZodOptional; + require_request_uri_registration: z.ZodOptional; + op_policy_uri: z.ZodOptional; + op_tos_uri: z.ZodOptional; + client_id_metadata_document_supported: z.ZodOptional; +}, z.core.$strip>; +/** + * OAuth 2.1 token response + */ +export declare const OAuthTokensSchema: z.ZodObject<{ + access_token: z.ZodString; + id_token: z.ZodOptional; + token_type: z.ZodString; + expires_in: z.ZodOptional>; + scope: z.ZodOptional; + refresh_token: z.ZodOptional; +}, z.core.$strip>; +/** + * OAuth 2.1 error response + */ +export declare const OAuthErrorResponseSchema: z.ZodObject<{ + error: z.ZodString; + error_description: z.ZodOptional; + error_uri: z.ZodOptional; +}, z.core.$strip>; +/** + * Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri + */ +export declare const OptionalSafeUrlSchema: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata + */ +export declare const OAuthClientMetadataSchema: z.ZodObject<{ + redirect_uris: z.ZodArray; + token_endpoint_auth_method: z.ZodOptional; + grant_types: z.ZodOptional>; + response_types: z.ZodOptional>; + client_name: z.ZodOptional; + client_uri: z.ZodOptional; + logo_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + scope: z.ZodOptional; + contacts: z.ZodOptional>; + tos_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + policy_uri: z.ZodOptional; + jwks_uri: z.ZodOptional; + jwks: z.ZodOptional; + software_id: z.ZodOptional; + software_version: z.ZodOptional; + software_statement: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration client information + */ +export declare const OAuthClientInformationSchema: z.ZodObject<{ + client_id: z.ZodString; + client_secret: z.ZodOptional; + client_id_issued_at: z.ZodOptional; + client_secret_expires_at: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata) + */ +export declare const OAuthClientInformationFullSchema: z.ZodObject<{ + redirect_uris: z.ZodArray; + token_endpoint_auth_method: z.ZodOptional; + grant_types: z.ZodOptional>; + response_types: z.ZodOptional>; + client_name: z.ZodOptional; + client_uri: z.ZodOptional; + logo_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + scope: z.ZodOptional; + contacts: z.ZodOptional>; + tos_uri: z.ZodUnion<[z.ZodOptional, z.ZodPipe, z.ZodTransform>]>; + policy_uri: z.ZodOptional; + jwks_uri: z.ZodOptional; + jwks: z.ZodOptional; + software_id: z.ZodOptional; + software_version: z.ZodOptional; + software_statement: z.ZodOptional; + client_id: z.ZodString; + client_secret: z.ZodOptional; + client_id_issued_at: z.ZodOptional; + client_secret_expires_at: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration error response + */ +export declare const OAuthClientRegistrationErrorSchema: z.ZodObject<{ + error: z.ZodString; + error_description: z.ZodOptional; +}, z.core.$strip>; +/** + * RFC 7009 OAuth 2.0 Token Revocation request + */ +export declare const OAuthTokenRevocationRequestSchema: z.ZodObject<{ + token: z.ZodString; + token_type_hint: z.ZodOptional; +}, z.core.$strip>; +export type OAuthMetadata = z.infer; +export type OpenIdProviderMetadata = z.infer; +export type OpenIdProviderDiscoveryMetadata = z.infer; +export type OAuthTokens = z.infer; +export type OAuthErrorResponse = z.infer; +export type OAuthClientMetadata = z.infer; +export type OAuthClientInformation = z.infer; +export type OAuthClientInformationFull = z.infer; +export type OAuthClientInformationMixed = OAuthClientInformation | OAuthClientInformationFull; +export type OAuthClientRegistrationError = z.infer; +export type OAuthTokenRevocationRequest = z.infer; +export type OAuthProtectedResourceMetadata = z.infer; +export type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetadata; +//# sourceMappingURL=auth.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/auth.d.ts.map b/dist/esm/shared/auth.d.ts.map new file mode 100644 index 000000000..031a88fb9 --- /dev/null +++ b/dist/esm/shared/auth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/shared/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,aAAa,UAmBrB,CAAC;AAEN;;GAEG;AACH,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;iBAe/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;iBAoB9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCvC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAKhD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;iBASlB,CAAC;AAEb;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,mGAAwE,CAAC;AAE3G;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;iBAmB1B,CAAC;AAEb;;GAEG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,2BAA2B,GAAG,aAAa,GAAG,+BAA+B,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/auth.js b/dist/esm/shared/auth.js new file mode 100644 index 000000000..04f38eb88 --- /dev/null +++ b/dist/esm/shared/auth.js @@ -0,0 +1,198 @@ +import * as z from 'zod/v4'; +/** + * Reusable URL validation that disallows javascript: scheme + */ +export const SafeUrlSchema = z + .url() + .superRefine((val, ctx) => { + if (!URL.canParse(val)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'URL must be parseable', + fatal: true + }); + return z.NEVER; + } +}) + .refine(url => { + const u = new URL(url); + return u.protocol !== 'javascript:' && u.protocol !== 'data:' && u.protocol !== 'vbscript:'; +}, { message: 'URL cannot use javascript:, data:, or vbscript: scheme' }); +/** + * RFC 9728 OAuth Protected Resource Metadata + */ +export const OAuthProtectedResourceMetadataSchema = z.looseObject({ + resource: z.string().url(), + authorization_servers: z.array(SafeUrlSchema).optional(), + jwks_uri: z.string().url().optional(), + scopes_supported: z.array(z.string()).optional(), + bearer_methods_supported: z.array(z.string()).optional(), + resource_signing_alg_values_supported: z.array(z.string()).optional(), + resource_name: z.string().optional(), + resource_documentation: z.string().optional(), + resource_policy_uri: z.string().url().optional(), + resource_tos_uri: z.string().url().optional(), + tls_client_certificate_bound_access_tokens: z.boolean().optional(), + authorization_details_types_supported: z.array(z.string()).optional(), + dpop_signing_alg_values_supported: z.array(z.string()).optional(), + dpop_bound_access_tokens_required: z.boolean().optional() +}); +/** + * RFC 8414 OAuth 2.0 Authorization Server Metadata + */ +export const OAuthMetadataSchema = z.looseObject({ + issuer: z.string(), + authorization_endpoint: SafeUrlSchema, + token_endpoint: SafeUrlSchema, + registration_endpoint: SafeUrlSchema.optional(), + scopes_supported: z.array(z.string()).optional(), + response_types_supported: z.array(z.string()), + response_modes_supported: z.array(z.string()).optional(), + grant_types_supported: z.array(z.string()).optional(), + token_endpoint_auth_methods_supported: z.array(z.string()).optional(), + token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + service_documentation: SafeUrlSchema.optional(), + revocation_endpoint: SafeUrlSchema.optional(), + revocation_endpoint_auth_methods_supported: z.array(z.string()).optional(), + revocation_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + introspection_endpoint: z.string().optional(), + introspection_endpoint_auth_methods_supported: z.array(z.string()).optional(), + introspection_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + code_challenge_methods_supported: z.array(z.string()).optional(), + client_id_metadata_document_supported: z.boolean().optional() +}); +/** + * OpenID Connect Discovery 1.0 Provider Metadata + * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata + */ +export const OpenIdProviderMetadataSchema = z.looseObject({ + issuer: z.string(), + authorization_endpoint: SafeUrlSchema, + token_endpoint: SafeUrlSchema, + userinfo_endpoint: SafeUrlSchema.optional(), + jwks_uri: SafeUrlSchema, + registration_endpoint: SafeUrlSchema.optional(), + scopes_supported: z.array(z.string()).optional(), + response_types_supported: z.array(z.string()), + response_modes_supported: z.array(z.string()).optional(), + grant_types_supported: z.array(z.string()).optional(), + acr_values_supported: z.array(z.string()).optional(), + subject_types_supported: z.array(z.string()), + id_token_signing_alg_values_supported: z.array(z.string()), + id_token_encryption_alg_values_supported: z.array(z.string()).optional(), + id_token_encryption_enc_values_supported: z.array(z.string()).optional(), + userinfo_signing_alg_values_supported: z.array(z.string()).optional(), + userinfo_encryption_alg_values_supported: z.array(z.string()).optional(), + userinfo_encryption_enc_values_supported: z.array(z.string()).optional(), + request_object_signing_alg_values_supported: z.array(z.string()).optional(), + request_object_encryption_alg_values_supported: z.array(z.string()).optional(), + request_object_encryption_enc_values_supported: z.array(z.string()).optional(), + token_endpoint_auth_methods_supported: z.array(z.string()).optional(), + token_endpoint_auth_signing_alg_values_supported: z.array(z.string()).optional(), + display_values_supported: z.array(z.string()).optional(), + claim_types_supported: z.array(z.string()).optional(), + claims_supported: z.array(z.string()).optional(), + service_documentation: z.string().optional(), + claims_locales_supported: z.array(z.string()).optional(), + ui_locales_supported: z.array(z.string()).optional(), + claims_parameter_supported: z.boolean().optional(), + request_parameter_supported: z.boolean().optional(), + request_uri_parameter_supported: z.boolean().optional(), + require_request_uri_registration: z.boolean().optional(), + op_policy_uri: SafeUrlSchema.optional(), + op_tos_uri: SafeUrlSchema.optional(), + client_id_metadata_document_supported: z.boolean().optional() +}); +/** + * OpenID Connect Discovery metadata that may include OAuth 2.0 fields + * This schema represents the real-world scenario where OIDC providers + * return a mix of OpenID Connect and OAuth 2.0 metadata fields + */ +export const OpenIdProviderDiscoveryMetadataSchema = z.object({ + ...OpenIdProviderMetadataSchema.shape, + ...OAuthMetadataSchema.pick({ + code_challenge_methods_supported: true + }).shape +}); +/** + * OAuth 2.1 token response + */ +export const OAuthTokensSchema = z + .object({ + access_token: z.string(), + id_token: z.string().optional(), // Optional for OAuth 2.1, but necessary in OpenID Connect + token_type: z.string(), + expires_in: z.coerce.number().optional(), + scope: z.string().optional(), + refresh_token: z.string().optional() +}) + .strip(); +/** + * OAuth 2.1 error response + */ +export const OAuthErrorResponseSchema = z.object({ + error: z.string(), + error_description: z.string().optional(), + error_uri: z.string().optional() +}); +/** + * Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri + */ +export const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(z.literal('').transform(() => undefined)); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata + */ +export const OAuthClientMetadataSchema = z + .object({ + redirect_uris: z.array(SafeUrlSchema), + token_endpoint_auth_method: z.string().optional(), + grant_types: z.array(z.string()).optional(), + response_types: z.array(z.string()).optional(), + client_name: z.string().optional(), + client_uri: SafeUrlSchema.optional(), + logo_uri: OptionalSafeUrlSchema, + scope: z.string().optional(), + contacts: z.array(z.string()).optional(), + tos_uri: OptionalSafeUrlSchema, + policy_uri: z.string().optional(), + jwks_uri: SafeUrlSchema.optional(), + jwks: z.any().optional(), + software_id: z.string().optional(), + software_version: z.string().optional(), + software_statement: z.string().optional() +}) + .strip(); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration client information + */ +export const OAuthClientInformationSchema = z + .object({ + client_id: z.string(), + client_secret: z.string().optional(), + client_id_issued_at: z.number().optional(), + client_secret_expires_at: z.number().optional() +}) + .strip(); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata) + */ +export const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema); +/** + * RFC 7591 OAuth 2.0 Dynamic Client Registration error response + */ +export const OAuthClientRegistrationErrorSchema = z + .object({ + error: z.string(), + error_description: z.string().optional() +}) + .strip(); +/** + * RFC 7009 OAuth 2.0 Token Revocation request + */ +export const OAuthTokenRevocationRequestSchema = z + .object({ + token: z.string(), + token_type_hint: z.string().optional() +}) + .strip(); +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/dist/esm/shared/auth.js.map b/dist/esm/shared/auth.js.map new file mode 100644 index 000000000..d529c24a6 --- /dev/null +++ b/dist/esm/shared/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/shared/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KACzB,GAAG,EAAE;KACL,WAAW,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACtB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,GAAG,CAAC,QAAQ,CAAC;YACT,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,uBAAuB;YAChC,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,KAAK,CAAC;IACnB,CAAC;AACL,CAAC,CAAC;KACD,MAAM,CACH,GAAG,CAAC,EAAE;IACF,MAAM,CAAC,GAAG,IAAI,GAAG,CA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AM,CAAC;IACJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACzC,CAAC;KACD,KAAK,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/metadataUtils.d.ts b/dist/esm/shared/metadataUtils.d.ts new file mode 100644 index 000000000..c0e738bab --- /dev/null +++ b/dist/esm/shared/metadataUtils.d.ts @@ -0,0 +1,16 @@ +import { BaseMetadata } from '../types.js'; +/** + * Utilities for working with BaseMetadata objects. + */ +/** + * Gets the display name for an object with BaseMetadata. + * For tools, the precedence is: title → annotations.title → name + * For other objects: title → name + * This implements the spec requirement: "if no title is provided, name should be used for display purposes" + */ +export declare function getDisplayName(metadata: BaseMetadata & { + annotations?: { + title?: string; + }; +}): string; +//# sourceMappingURL=metadataUtils.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/metadataUtils.d.ts.map b/dist/esm/shared/metadataUtils.d.ts.map new file mode 100644 index 000000000..596805eb3 --- /dev/null +++ b/dist/esm/shared/metadataUtils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"metadataUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/metadataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG;IAAE,WAAW,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,CAapG"} \ No newline at end of file diff --git a/dist/esm/shared/metadataUtils.js b/dist/esm/shared/metadataUtils.js new file mode 100644 index 000000000..61b37d9d8 --- /dev/null +++ b/dist/esm/shared/metadataUtils.js @@ -0,0 +1,23 @@ +/** + * Utilities for working with BaseMetadata objects. + */ +/** + * Gets the display name for an object with BaseMetadata. + * For tools, the precedence is: title → annotations.title → name + * For other objects: title → name + * This implements the spec requirement: "if no title is provided, name should be used for display purposes" + */ +export function getDisplayName(metadata) { + var _a; + // First check for title (not undefined and not empty string) + if (metadata.title !== undefined && metadata.title !== '') { + return metadata.title; + } + // Then check for annotations.title (only present in Tool objects) + if ((_a = metadata.annotations) === null || _a === void 0 ? void 0 : _a.title) { + return metadata.annotations.title; + } + // Finally fall back to name + return metadata.name; +} +//# sourceMappingURL=metadataUtils.js.map \ No newline at end of file diff --git a/dist/esm/shared/metadataUtils.js.map b/dist/esm/shared/metadataUtils.js.map new file mode 100644 index 000000000..a206833d9 --- /dev/null +++ b/dist/esm/shared/metadataUtils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"metadataUtils.js","sourceRoot":"","sources":["../../../src/shared/metadataUtils.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,QAA6D;;IACxF,6DAA6D;IAC7D,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;QACxD,OAAO,QAAQ,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,kEAAkE;IAClE,IAAI,MAAA,QAAQ,CAAC,WAAW,0CAAE,KAAK,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;IACtC,CAAC;IAED,4BAA4B;IAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/protocol.d.ts b/dist/esm/shared/protocol.d.ts new file mode 100644 index 000000000..f55626baa --- /dev/null +++ b/dist/esm/shared/protocol.d.ts @@ -0,0 +1,431 @@ +import { AnySchema, AnyObjectSchema, SchemaOutput } from '../server/zod-compat.js'; +import { ClientCapabilities, GetTaskRequest, GetTaskPayloadRequest, ListTasksResultSchema, CancelTaskResultSchema, JSONRPCRequest, Notification, Progress, Request, RequestId, Result, ServerCapabilities, RequestMeta, RequestInfo, GetTaskResult, TaskCreationParams, RelatedTaskMetadata, Task } from '../types.js'; +import { Transport, TransportSendOptions } from './transport.js'; +import { AuthInfo } from '../server/auth/types.js'; +import { TaskStore, TaskMessageQueue, CreateTaskOptions } from '../experimental/tasks/interfaces.js'; +import { ResponseMessage } from './responseMessage.js'; +/** + * Callback for progress notifications. + */ +export type ProgressCallback = (progress: Progress) => void; +/** + * Additional initialization options. + */ +export type ProtocolOptions = { + /** + * Whether to restrict emitted requests to only those that the remote side has indicated that they can handle, through their advertised capabilities. + * + * Note that this DOES NOT affect checking of _local_ side capabilities, as it is considered a logic error to mis-specify those. + * + * Currently this defaults to false, for backwards compatibility with SDK versions that did not advertise capabilities correctly. In future, this will default to true. + */ + enforceStrictCapabilities?: boolean; + /** + * An array of notification method names that should be automatically debounced. + * Any notifications with a method in this list will be coalesced if they + * occur in the same tick of the event loop. + * e.g., ['notifications/tools/list_changed'] + */ + debouncedNotificationMethods?: string[]; + /** + * Optional task storage implementation. If provided, enables task-related request handlers + * and provides task storage capabilities to request handlers. + */ + taskStore?: TaskStore; + /** + * Optional task message queue implementation for managing server-initiated messages + * that will be delivered through the tasks/result response stream. + */ + taskMessageQueue?: TaskMessageQueue; + /** + * Default polling interval (in milliseconds) for task status checks when no pollInterval + * is provided by the server. Defaults to 5000ms if not specified. + */ + defaultTaskPollInterval?: number; + /** + * Maximum number of messages that can be queued per task for side-channel delivery. + * If undefined, the queue size is unbounded. + * When the limit is exceeded, the TaskMessageQueue implementation's enqueue() method + * will throw an error. It's the implementation's responsibility to handle overflow + * appropriately (e.g., by failing the task, dropping messages, etc.). + */ + maxTaskQueueSize?: number; +}; +/** + * The default request timeout, in miliseconds. + */ +export declare const DEFAULT_REQUEST_TIMEOUT_MSEC = 60000; +/** + * Options that can be given per request. + */ +export type RequestOptions = { + /** + * If set, requests progress notifications from the remote end (if supported). When progress notifications are received, this callback will be invoked. + * + * For task-augmented requests: progress notifications continue after CreateTaskResult is returned and stop automatically when the task reaches a terminal status. + */ + onprogress?: ProgressCallback; + /** + * Can be used to cancel an in-flight request. This will cause an AbortError to be raised from request(). + */ + signal?: AbortSignal; + /** + * A timeout (in milliseconds) for this request. If exceeded, an McpError with code `RequestTimeout` will be raised from request(). + * + * If not specified, `DEFAULT_REQUEST_TIMEOUT_MSEC` will be used as the timeout. + */ + timeout?: number; + /** + * If true, receiving a progress notification will reset the request timeout. + * This is useful for long-running operations that send periodic progress updates. + * Default: false + */ + resetTimeoutOnProgress?: boolean; + /** + * Maximum total time (in milliseconds) to wait for a response. + * If exceeded, an McpError with code `RequestTimeout` will be raised, regardless of progress notifications. + * If not specified, there is no maximum total timeout. + */ + maxTotalTimeout?: number; + /** + * If provided, augments the request with task creation parameters to enable call-now, fetch-later execution patterns. + */ + task?: TaskCreationParams; + /** + * If provided, associates this request with a related task. + */ + relatedTask?: RelatedTaskMetadata; +} & TransportSendOptions; +/** + * Options that can be given per notification. + */ +export type NotificationOptions = { + /** + * May be used to indicate to the transport which incoming request to associate this outgoing notification with. + */ + relatedRequestId?: RequestId; + /** + * If provided, associates this notification with a related task. + */ + relatedTask?: RelatedTaskMetadata; +}; +/** + * Options that can be given per request. + */ +export type TaskRequestOptions = Omit; +/** + * Request-scoped TaskStore interface. + */ +export interface RequestTaskStore { + /** + * Creates a new task with the given creation parameters. + * The implementation generates a unique taskId and createdAt timestamp. + * + * @param taskParams - The task creation parameters from the request + * @returns The created task object + */ + createTask(taskParams: CreateTaskOptions): Promise; + /** + * Gets the current status of a task. + * + * @param taskId - The task identifier + * @returns The task object + * @throws If the task does not exist + */ + getTask(taskId: string): Promise; + /** + * Stores the result of a task and sets its final status. + * + * @param taskId - The task identifier + * @param status - The final status: 'completed' for success, 'failed' for errors + * @param result - The result to store + */ + storeTaskResult(taskId: string, status: 'completed' | 'failed', result: Result): Promise; + /** + * Retrieves the stored result of a task. + * + * @param taskId - The task identifier + * @returns The stored result + */ + getTaskResult(taskId: string): Promise; + /** + * Updates a task's status (e.g., to 'cancelled', 'failed', 'completed'). + * + * @param taskId - The task identifier + * @param status - The new status + * @param statusMessage - Optional diagnostic message for failed tasks or other status information + */ + updateTaskStatus(taskId: string, status: Task['status'], statusMessage?: string): Promise; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @param cursor - Optional cursor for pagination + * @returns An object containing the tasks array and an optional nextCursor + */ + listTasks(cursor?: string): Promise<{ + tasks: Task[]; + nextCursor?: string; + }>; +} +/** + * Extra data given to request handlers. + */ +export type RequestHandlerExtra = { + /** + * An abort signal used to communicate if the request was cancelled from the sender's side. + */ + signal: AbortSignal; + /** + * Information about a validated access token, provided to request handlers. + */ + authInfo?: AuthInfo; + /** + * The session ID from the transport, if available. + */ + sessionId?: string; + /** + * Metadata from the original request. + */ + _meta?: RequestMeta; + /** + * The JSON-RPC ID of the request being handled. + * This can be useful for tracking or logging purposes. + */ + requestId: RequestId; + taskId?: string; + taskStore?: RequestTaskStore; + taskRequestedTtl?: number | null; + /** + * The original HTTP request. + */ + requestInfo?: RequestInfo; + /** + * Sends a notification that relates to the current request being handled. + * + * This is used by certain transports to correctly associate related messages. + */ + sendNotification: (notification: SendNotificationT) => Promise; + /** + * Sends a request that relates to the current request being handled. + * + * This is used by certain transports to correctly associate related messages. + */ + sendRequest: (request: SendRequestT, resultSchema: U, options?: TaskRequestOptions) => Promise>; +}; +/** + * Implements MCP protocol framing on top of a pluggable transport, including + * features like request/response linking, notifications, and progress. + */ +export declare abstract class Protocol { + private _options?; + private _transport?; + private _requestMessageId; + private _requestHandlers; + private _requestHandlerAbortControllers; + private _notificationHandlers; + private _responseHandlers; + private _progressHandlers; + private _timeoutInfo; + private _pendingDebouncedNotifications; + private _taskProgressTokens; + private _taskStore?; + private _taskMessageQueue?; + private _requestResolvers; + /** + * Callback for when the connection is closed for any reason. + * + * This is invoked when close() is called as well. + */ + onclose?: () => void; + /** + * Callback for when an error occurs. + * + * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band. + */ + onerror?: (error: Error) => void; + /** + * A handler to invoke for any request types that do not have their own handler installed. + */ + fallbackRequestHandler?: (request: JSONRPCRequest, extra: RequestHandlerExtra) => Promise; + /** + * A handler to invoke for any notification types that do not have their own handler installed. + */ + fallbackNotificationHandler?: (notification: Notification) => Promise; + constructor(_options?: ProtocolOptions | undefined); + private _oncancel; + private _setupTimeout; + private _resetTimeout; + private _cleanupTimeout; + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + connect(transport: Transport): Promise; + private _onclose; + private _onerror; + private _onnotification; + private _onrequest; + private _onprogress; + private _onresponse; + get transport(): Transport | undefined; + /** + * Closes the connection. + */ + close(): Promise; + /** + * A method to check if a capability is supported by the remote side, for the given method to be called. + * + * This should be implemented by subclasses. + */ + protected abstract assertCapabilityForMethod(method: SendRequestT['method']): void; + /** + * A method to check if a notification is supported by the local side, for the given method to be sent. + * + * This should be implemented by subclasses. + */ + protected abstract assertNotificationCapability(method: SendNotificationT['method']): void; + /** + * A method to check if a request handler is supported by the local side, for the given method to be handled. + * + * This should be implemented by subclasses. + */ + protected abstract assertRequestHandlerCapability(method: string): void; + /** + * A method to check if task creation is supported for the given request method. + * + * This should be implemented by subclasses. + */ + protected abstract assertTaskCapability(method: string): void; + /** + * A method to check if task handler is supported by the local side, for the given method to be handled. + * + * This should be implemented by subclasses. + */ + protected abstract assertTaskHandlerCapability(method: string): void; + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * @example + * ```typescript + * const stream = protocol.requestStream(request, resultSchema, options); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Task created:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Task status:', message.task.status); + * break; + * case 'result': + * console.log('Final result:', message.result); + * break; + * case 'error': + * console.error('Error:', message.error); + * break; + * } + * } + * ``` + * + * @experimental Use `client.experimental.tasks.requestStream()` to access this method. + */ + protected requestStream(request: SendRequestT, resultSchema: T, options?: RequestOptions): AsyncGenerator>, void, void>; + /** + * Sends a request and waits for a response. + * + * Do not use this method to emit notifications! Use notification() instead. + */ + request(request: SendRequestT, resultSchema: T, options?: RequestOptions): Promise>; + /** + * Gets the current status of a task. + * + * @experimental Use `client.experimental.tasks.getTask()` to access this method. + */ + protected getTask(params: GetTaskRequest['params'], options?: RequestOptions): Promise; + /** + * Retrieves the result of a completed task. + * + * @experimental Use `client.experimental.tasks.getTaskResult()` to access this method. + */ + protected getTaskResult(params: GetTaskPayloadRequest['params'], resultSchema: T, options?: RequestOptions): Promise>; + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @experimental Use `client.experimental.tasks.listTasks()` to access this method. + */ + protected listTasks(params?: { + cursor?: string; + }, options?: RequestOptions): Promise>; + /** + * Cancels a specific task. + * + * @experimental Use `client.experimental.tasks.cancelTask()` to access this method. + */ + protected cancelTask(params: { + taskId: string; + }, options?: RequestOptions): Promise>; + /** + * Emits a notification, which is a one-way message that does not expect a response. + */ + notification(notification: SendNotificationT, options?: NotificationOptions): Promise; + /** + * Registers a handler to invoke when this protocol object receives a request with the given method. + * + * Note that this will replace any previous request handler for the same method. + */ + setRequestHandler(requestSchema: T, handler: (request: SchemaOutput, extra: RequestHandlerExtra) => SendResultT | Promise): void; + /** + * Removes the request handler for the given method. + */ + removeRequestHandler(method: string): void; + /** + * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed. + */ + assertCanSetRequestHandler(method: string): void; + /** + * Registers a handler to invoke when this protocol object receives a notification with the given method. + * + * Note that this will replace any previous notification handler for the same method. + */ + setNotificationHandler(notificationSchema: T, handler: (notification: SchemaOutput) => void | Promise): void; + /** + * Removes the notification handler for the given method. + */ + removeNotificationHandler(method: string): void; + /** + * Cleans up the progress handler associated with a task. + * This should be called when a task reaches a terminal status. + */ + private _cleanupTaskProgressHandler; + /** + * Enqueues a task-related message for side-channel delivery via tasks/result. + * @param taskId The task ID to associate the message with + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow) + * + * Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle + * the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer + * simply propagates the error. + */ + private _enqueueTaskMessage; + /** + * Clears the message queue for a task and rejects any pending request resolvers. + * @param taskId The task ID whose queue should be cleared + * @param sessionId Optional session ID for binding the operation to a specific session + */ + private _clearTaskQueue; + /** + * Waits for a task update (new messages or status change) with abort signal support. + * Uses polling to check for updates at the task's configured poll interval. + * @param taskId The task ID to wait for + * @param signal Abort signal to cancel the wait + * @returns Promise that resolves when an update occurs or rejects if aborted + */ + private _waitForTaskUpdate; + private requestTaskStore; +} +export declare function mergeCapabilities(base: ServerCapabilities, additional: Partial): ServerCapabilities; +export declare function mergeCapabilities(base: ClientCapabilities, additional: Partial): ClientCapabilities; +//# sourceMappingURL=protocol.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/protocol.d.ts.map b/dist/esm/shared/protocol.d.ts.map new file mode 100644 index 000000000..ddfe311d0 --- /dev/null +++ b/dist/esm/shared/protocol.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/shared/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAa,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EAEH,kBAAkB,EAGlB,cAAc,EAGd,qBAAqB,EAGrB,qBAAqB,EAErB,sBAAsB,EAOtB,cAAc,EAGd,YAAY,EAEZ,QAAQ,EAIR,OAAO,EACP,SAAS,EACT,MAAM,EACN,kBAAkB,EAClB,WAAW,EAEX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EAEnB,IAAI,EAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,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AAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8GjG;;;;OAIG;IACH,iBAAiB,CAAC,CAAC,SAAS,eAAe,EACvC,aAAa,EAAE,CAAC,EAChB,OAAO,EAAE,CACL,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,KAAK,EAAE,mBAAmB,CAAC,YAAY,EAAE,iBAAiB,CAAC,KAC1D,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GACxC,IAAI;IAUP;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI1C;;OAEG;IACH,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAMhD;;;;OAIG;IACH,sBAAsB,CAAC,CAAC,SAAS,eAAe,EAC5C,kBAAkB,EAAE,CAAC,EACrB,OAAO,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACjE,IAAI;IAQP;;OAEG;IACH,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/C;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAQnC;;;;;;;;;;OAUG;YACW,mBAAmB;IAUjC;;;;OAIG;YACW,eAAe;IAqB7B;;;;;;OAMG;YACW,kBAAkB;IAiChC,OAAO,CAAC,gBAAgB;CAwF3B;AAMD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AACzH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/protocol.js b/dist/esm/shared/protocol.js new file mode 100644 index 000000000..d2d766141 --- /dev/null +++ b/dist/esm/shared/protocol.js @@ -0,0 +1,1096 @@ +import { safeParse } from '../server/zod-compat.js'; +import { CancelledNotificationSchema, CreateTaskResultSchema, ErrorCode, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, isJSONRPCNotification, McpError, PingRequestSchema, ProgressNotificationSchema, RELATED_TASK_META_KEY, TaskStatusNotificationSchema } from '../types.js'; +import { isTerminal } from '../experimental/tasks/interfaces.js'; +import { getMethodLiteral, parseWithCompat } from '../server/zod-json-schema-compat.js'; +/** + * The default request timeout, in miliseconds. + */ +export const DEFAULT_REQUEST_TIMEOUT_MSEC = 60000; +/** + * Implements MCP protocol framing on top of a pluggable transport, including + * features like request/response linking, notifications, and progress. + */ +export class Protocol { + constructor(_options) { + this._options = _options; + this._requestMessageId = 0; + this._requestHandlers = new Map(); + this._requestHandlerAbortControllers = new Map(); + this._notificationHandlers = new Map(); + this._responseHandlers = new Map(); + this._progressHandlers = new Map(); + this._timeoutInfo = new Map(); + this._pendingDebouncedNotifications = new Set(); + // Maps task IDs to progress tokens to keep handlers alive after CreateTaskResult + this._taskProgressTokens = new Map(); + this._requestResolvers = new Map(); + this.setNotificationHandler(CancelledNotificationSchema, notification => { + this._oncancel(notification); + }); + this.setNotificationHandler(ProgressNotificationSchema, notification => { + this._onprogress(notification); + }); + this.setRequestHandler(PingRequestSchema, + // Automatic pong by default. + _request => ({})); + // Install task handlers if TaskStore is provided + this._taskStore = _options === null || _options === void 0 ? void 0 : _options.taskStore; + this._taskMessageQueue = _options === null || _options === void 0 ? void 0 : _options.taskMessageQueue; + if (this._taskStore) { + this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => { + const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!task) { + throw new McpError(ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found'); + } + // Per spec: tasks/get responses SHALL NOT include related-task metadata + // as the taskId parameter is the source of truth + // @ts-expect-error SendResultT cannot contain GetTaskResult, but we include it in our derived types everywhere else + return { + ...task + }; + }); + this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => { + const handleTaskResult = async () => { + var _a; + const taskId = request.params.taskId; + // Deliver queued messages + if (this._taskMessageQueue) { + let queuedMessage; + while ((queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId))) { + // Handle response and error messages by routing them to the appropriate resolver + if (queuedMessage.type === 'response' || queuedMessage.type === 'error') { + const message = queuedMessage.message; + const requestId = message.id; + // Lookup resolver in _requestResolvers map + const resolver = this._requestResolvers.get(requestId); + if (resolver) { + // Remove resolver from map after invocation + this._requestResolvers.delete(requestId); + // Invoke resolver with response or error + if (queuedMessage.type === 'response') { + resolver(message); + } + else { + // Convert JSONRPCError to McpError + const errorMessage = message; + const error = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data); + resolver(error); + } + } + else { + // Handle missing resolver gracefully with error logging + const messageType = queuedMessage.type === 'response' ? 'Response' : 'Error'; + this._onerror(new Error(`${messageType} handler missing for request ${requestId}`)); + } + // Continue to next message + continue; + } + // Send the message on the response stream by passing the relatedRequestId + // This tells the transport to write the message to the tasks/result response stream + await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.send(queuedMessage.message, { relatedRequestId: extra.requestId })); + } + } + // Now check task status + const task = await this._taskStore.getTask(taskId, extra.sessionId); + if (!task) { + throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`); + } + // Block if task is not terminal (we've already delivered all queued messages above) + if (!isTerminal(task.status)) { + // Wait for status change or new messages + await this._waitForTaskUpdate(taskId, extra.signal); + // After waking up, recursively call to deliver any new messages or result + return await handleTaskResult(); + } + // If task is terminal, return the result + if (isTerminal(task.status)) { + const result = await this._taskStore.getTaskResult(taskId, extra.sessionId); + this._clearTaskQueue(taskId); + return { + ...result, + _meta: { + ...result._meta, + [RELATED_TASK_META_KEY]: { + taskId: taskId + } + } + }; + } + return await handleTaskResult(); + }; + return await handleTaskResult(); + }); + this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => { + var _a; + try { + const { tasks, nextCursor } = await this._taskStore.listTasks((_a = request.params) === null || _a === void 0 ? void 0 : _a.cursor, extra.sessionId); + // @ts-expect-error SendResultT cannot contain ListTasksResult, but we include it in our derived types everywhere else + return { + tasks, + nextCursor, + _meta: {} + }; + } + catch (error) { + throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`); + } + }); + this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => { + try { + // Get the current task to check if it's in a terminal state, in case the implementation is not atomic + const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!task) { + throw new McpError(ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`); + } + // Reject cancellation of terminal tasks + if (isTerminal(task.status)) { + throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`); + } + await this._taskStore.updateTaskStatus(request.params.taskId, 'cancelled', 'Client cancelled task execution.', extra.sessionId); + this._clearTaskQueue(request.params.taskId); + const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId); + if (!cancelledTask) { + // Task was deleted during cancellation (e.g., cleanup happened) + throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`); + } + return { + _meta: {}, + ...cancelledTask + }; + } + catch (error) { + // Re-throw McpError as-is + if (error instanceof McpError) { + throw error; + } + throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`); + } + }); + } + } + async _oncancel(notification) { + // Handle request cancellation + const controller = this._requestHandlerAbortControllers.get(notification.params.requestId); + controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason); + } + _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) { + this._timeoutInfo.set(messageId, { + timeoutId: setTimeout(onTimeout, timeout), + startTime: Date.now(), + timeout, + maxTotalTimeout, + resetTimeoutOnProgress, + onTimeout + }); + } + _resetTimeout(messageId) { + const info = this._timeoutInfo.get(messageId); + if (!info) + return false; + const totalElapsed = Date.now() - info.startTime; + if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) { + this._timeoutInfo.delete(messageId); + throw McpError.fromError(ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', { + maxTotalTimeout: info.maxTotalTimeout, + totalElapsed + }); + } + clearTimeout(info.timeoutId); + info.timeoutId = setTimeout(info.onTimeout, info.timeout); + return true; + } + _cleanupTimeout(messageId) { + const info = this._timeoutInfo.get(messageId); + if (info) { + clearTimeout(info.timeoutId); + this._timeoutInfo.delete(messageId); + } + } + /** + * Attaches to the given transport, starts it, and starts listening for messages. + * + * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward. + */ + async connect(transport) { + var _a, _b, _c; + this._transport = transport; + const _onclose = (_a = this.transport) === null || _a === void 0 ? void 0 : _a.onclose; + this._transport.onclose = () => { + _onclose === null || _onclose === void 0 ? void 0 : _onclose(); + this._onclose(); + }; + const _onerror = (_b = this.transport) === null || _b === void 0 ? void 0 : _b.onerror; + this._transport.onerror = (error) => { + _onerror === null || _onerror === void 0 ? void 0 : _onerror(error); + this._onerror(error); + }; + const _onmessage = (_c = this._transport) === null || _c === void 0 ? void 0 : _c.onmessage; + this._transport.onmessage = (message, extra) => { + _onmessage === null || _onmessage === void 0 ? void 0 : _onmessage(message, extra); + if (isJSONRPCResponse(message) || isJSONRPCError(message)) { + this._onresponse(message); + } + else if (isJSONRPCRequest(message)) { + this._onrequest(message, extra); + } + else if (isJSONRPCNotification(message)) { + this._onnotification(message); + } + else { + this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`)); + } + }; + await this._transport.start(); + } + _onclose() { + var _a; + const responseHandlers = this._responseHandlers; + this._responseHandlers = new Map(); + this._progressHandlers.clear(); + this._taskProgressTokens.clear(); + this._pendingDebouncedNotifications.clear(); + const error = McpError.fromError(ErrorCode.ConnectionClosed, 'Connection closed'); + this._transport = undefined; + (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); + for (const handler of responseHandlers.values()) { + handler(error); + } + } + _onerror(error) { + var _a; + (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error); + } + _onnotification(notification) { + var _a; + const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler; + // Ignore notifications not being subscribed to. + if (handler === undefined) { + return; + } + // Starting with Promise.resolve() puts any synchronous errors into the monad as well. + Promise.resolve() + .then(() => handler(notification)) + .catch(error => this._onerror(new Error(`Uncaught error in notification handler: ${error}`))); + } + _onrequest(request, extra) { + var _a, _b, _c, _d, _e, _f; + const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler; + // Capture the current transport at request time to ensure responses go to the correct client + const capturedTransport = this._transport; + // Extract taskId from request metadata if present (needed early for method not found case) + const relatedTaskId = (_d = (_c = (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta) === null || _c === void 0 ? void 0 : _c[RELATED_TASK_META_KEY]) === null || _d === void 0 ? void 0 : _d.taskId; + if (handler === undefined) { + const errorResponse = { + jsonrpc: '2.0', + id: request.id, + error: { + code: ErrorCode.MethodNotFound, + message: 'Method not found' + } + }; + // Queue or send the error response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + this._enqueueTaskMessage(relatedTaskId, { + type: 'error', + message: errorResponse, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId).catch(error => this._onerror(new Error(`Failed to enqueue error response: ${error}`))); + } + else { + capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse).catch(error => this._onerror(new Error(`Failed to send an error response: ${error}`))); + } + return; + } + const abortController = new AbortController(); + this._requestHandlerAbortControllers.set(request.id, abortController); + const taskCreationParams = (_e = request.params) === null || _e === void 0 ? void 0 : _e.task; + const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId) : undefined; + const fullExtra = { + signal: abortController.signal, + sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId, + _meta: (_f = request.params) === null || _f === void 0 ? void 0 : _f._meta, + sendNotification: async (notification) => { + // Include related-task metadata if this request is part of a task + const notificationOptions = { relatedRequestId: request.id }; + if (relatedTaskId) { + notificationOptions.relatedTask = { taskId: relatedTaskId }; + } + await this.notification(notification, notificationOptions); + }, + sendRequest: async (r, resultSchema, options) => { + var _a, _b; + // Include related-task metadata if this request is part of a task + const requestOptions = { ...options, relatedRequestId: request.id }; + if (relatedTaskId && !requestOptions.relatedTask) { + requestOptions.relatedTask = { taskId: relatedTaskId }; + } + // Set task status to input_required when sending a request within a task context + // Use the taskId from options (explicit) or fall back to relatedTaskId (inherited) + const effectiveTaskId = (_b = (_a = requestOptions.relatedTask) === null || _a === void 0 ? void 0 : _a.taskId) !== null && _b !== void 0 ? _b : relatedTaskId; + if (effectiveTaskId && taskStore) { + await taskStore.updateTaskStatus(effectiveTaskId, 'input_required'); + } + return await this.request(r, resultSchema, requestOptions); + }, + authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo, + requestId: request.id, + requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo, + taskId: relatedTaskId, + taskStore: taskStore, + taskRequestedTtl: taskCreationParams === null || taskCreationParams === void 0 ? void 0 : taskCreationParams.ttl + }; + // Starting with Promise.resolve() puts any synchronous errors into the monad as well. + Promise.resolve() + .then(() => { + // If this request asked for task creation, check capability first + if (taskCreationParams) { + // Check if the request method supports task creation + this.assertTaskHandlerCapability(request.method); + } + }) + .then(() => handler(request, fullExtra)) + .then(async (result) => { + if (abortController.signal.aborted) { + // Request was cancelled + return; + } + const response = { + result, + jsonrpc: '2.0', + id: request.id + }; + // Queue or send the response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + await this._enqueueTaskMessage(relatedTaskId, { + type: 'response', + message: response, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId); + } + else { + await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(response)); + } + }, async (error) => { + var _a; + if (abortController.signal.aborted) { + // Request was cancelled + return; + } + const errorResponse = { + jsonrpc: '2.0', + id: request.id, + error: { + code: Number.isSafeInteger(error['code']) ? error['code'] : ErrorCode.InternalError, + message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Internal error', + ...(error['data'] !== undefined && { data: error['data'] }) + } + }; + // Queue or send the error response based on whether this is a task-related request + if (relatedTaskId && this._taskMessageQueue) { + await this._enqueueTaskMessage(relatedTaskId, { + type: 'error', + message: errorResponse, + timestamp: Date.now() + }, capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId); + } + else { + await (capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send(errorResponse)); + } + }) + .catch(error => this._onerror(new Error(`Failed to send response: ${error}`))) + .finally(() => { + this._requestHandlerAbortControllers.delete(request.id); + }); + } + _onprogress(notification) { + const { progressToken, ...params } = notification.params; + const messageId = Number(progressToken); + const handler = this._progressHandlers.get(messageId); + if (!handler) { + this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`)); + return; + } + const responseHandler = this._responseHandlers.get(messageId); + const timeoutInfo = this._timeoutInfo.get(messageId); + if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) { + try { + this._resetTimeout(messageId); + } + catch (error) { + // Clean up if maxTotalTimeout was exceeded + this._responseHandlers.delete(messageId); + this._progressHandlers.delete(messageId); + this._cleanupTimeout(messageId); + responseHandler(error); + return; + } + } + handler(params); + } + _onresponse(response) { + const messageId = Number(response.id); + // Check if this is a response to a queued request + const resolver = this._requestResolvers.get(messageId); + if (resolver) { + this._requestResolvers.delete(messageId); + if (isJSONRPCResponse(response)) { + resolver(response); + } + else { + const error = new McpError(response.error.code, response.error.message, response.error.data); + resolver(error); + } + return; + } + const handler = this._responseHandlers.get(messageId); + if (handler === undefined) { + this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`)); + return; + } + this._responseHandlers.delete(messageId); + this._cleanupTimeout(messageId); + // Keep progress handler alive for CreateTaskResult responses + let isTaskResponse = false; + if (isJSONRPCResponse(response) && response.result && typeof response.result === 'object') { + const result = response.result; + if (result.task && typeof result.task === 'object') { + const task = result.task; + if (typeof task.taskId === 'string') { + isTaskResponse = true; + this._taskProgressTokens.set(task.taskId, messageId); + } + } + } + if (!isTaskResponse) { + this._progressHandlers.delete(messageId); + } + if (isJSONRPCResponse(response)) { + handler(response); + } + else { + const error = McpError.fromError(response.error.code, response.error.message, response.error.data); + handler(error); + } + } + get transport() { + return this._transport; + } + /** + * Closes the connection. + */ + async close() { + var _a; + await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close()); + } + /** + * Sends a request and returns an AsyncGenerator that yields response messages. + * The generator is guaranteed to end with either a 'result' or 'error' message. + * + * @example + * ```typescript + * const stream = protocol.requestStream(request, resultSchema, options); + * for await (const message of stream) { + * switch (message.type) { + * case 'taskCreated': + * console.log('Task created:', message.task.taskId); + * break; + * case 'taskStatus': + * console.log('Task status:', message.task.status); + * break; + * case 'result': + * console.log('Final result:', message.result); + * break; + * case 'error': + * console.error('Error:', message.error); + * break; + * } + * } + * ``` + * + * @experimental Use `client.experimental.tasks.requestStream()` to access this method. + */ + async *requestStream(request, resultSchema, options) { + var _a, _b, _c, _d; + const { task } = options !== null && options !== void 0 ? options : {}; + // For non-task requests, just yield the result + if (!task) { + try { + const result = await this.request(request, resultSchema, options); + yield { type: 'result', result }; + } + catch (error) { + yield { + type: 'error', + error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error)) + }; + } + return; + } + // For task-augmented requests, we need to poll for status + // First, make the request to create the task + let taskId; + try { + // Send the request and get the CreateTaskResult + const createResult = await this.request(request, CreateTaskResultSchema, options); + // Extract taskId from the result + if (createResult.task) { + taskId = createResult.task.taskId; + yield { type: 'taskCreated', task: createResult.task }; + } + else { + throw new McpError(ErrorCode.InternalError, 'Task creation did not return a task'); + } + // Poll for task completion + while (true) { + // Get current task status + const task = await this.getTask({ taskId }, options); + yield { type: 'taskStatus', task }; + // Check if task is terminal + if (isTerminal(task.status)) { + if (task.status === 'completed') { + // Get the final result + const result = await this.getTaskResult({ taskId }, resultSchema, options); + yield { type: 'result', result }; + } + else if (task.status === 'failed') { + yield { + type: 'error', + error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`) + }; + } + else if (task.status === 'cancelled') { + yield { + type: 'error', + error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`) + }; + } + return; + } + // When input_required, call tasks/result to deliver queued messages + // (elicitation, sampling) via SSE and block until terminal + if (task.status === 'input_required') { + const result = await this.getTaskResult({ taskId }, resultSchema, options); + yield { type: 'result', result }; + return; + } + // Wait before polling again + const pollInterval = (_c = (_a = task.pollInterval) !== null && _a !== void 0 ? _a : (_b = this._options) === null || _b === void 0 ? void 0 : _b.defaultTaskPollInterval) !== null && _c !== void 0 ? _c : 1000; + await new Promise(resolve => setTimeout(resolve, pollInterval)); + // Check if cancelled + (_d = options === null || options === void 0 ? void 0 : options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted(); + } + } + catch (error) { + yield { + type: 'error', + error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error)) + }; + } + } + /** + * Sends a request and waits for a response. + * + * Do not use this method to emit notifications! Use notification() instead. + */ + request(request, resultSchema, options) { + const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options !== null && options !== void 0 ? options : {}; + // Send the request + return new Promise((resolve, reject) => { + var _a, _b, _c, _d, _e, _f, _g; + const earlyReject = (error) => { + reject(error); + }; + if (!this._transport) { + earlyReject(new Error('Not connected')); + return; + } + if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) { + try { + this.assertCapabilityForMethod(request.method); + // If task creation is requested, also check task capabilities + if (task) { + this.assertTaskCapability(request.method); + } + } + catch (e) { + earlyReject(e); + return; + } + } + (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted(); + const messageId = this._requestMessageId++; + const jsonrpcRequest = { + ...request, + jsonrpc: '2.0', + id: messageId + }; + if (options === null || options === void 0 ? void 0 : options.onprogress) { + this._progressHandlers.set(messageId, options.onprogress); + jsonrpcRequest.params = { + ...request.params, + _meta: { + ...(((_c = request.params) === null || _c === void 0 ? void 0 : _c._meta) || {}), + progressToken: messageId + } + }; + } + // Augment with task creation parameters if provided + if (task) { + jsonrpcRequest.params = { + ...jsonrpcRequest.params, + task: task + }; + } + // Augment with related task metadata if relatedTask is provided + if (relatedTask) { + jsonrpcRequest.params = { + ...jsonrpcRequest.params, + _meta: { + ...(((_d = jsonrpcRequest.params) === null || _d === void 0 ? void 0 : _d._meta) || {}), + [RELATED_TASK_META_KEY]: relatedTask + } + }; + } + const cancel = (reason) => { + var _a; + this._responseHandlers.delete(messageId); + this._progressHandlers.delete(messageId); + this._cleanupTimeout(messageId); + (_a = this._transport) === null || _a === void 0 ? void 0 : _a.send({ + jsonrpc: '2.0', + method: 'notifications/cancelled', + params: { + requestId: messageId, + reason: String(reason) + } + }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => this._onerror(new Error(`Failed to send cancellation: ${error}`))); + // Wrap the reason in an McpError if it isn't already + const error = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason)); + reject(error); + }; + this._responseHandlers.set(messageId, response => { + var _a; + if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) { + return; + } + if (response instanceof Error) { + return reject(response); + } + try { + const parseResult = safeParse(resultSchema, response.result); + if (!parseResult.success) { + // Type guard: if success is false, error is guaranteed to exist + reject(parseResult.error); + } + else { + resolve(parseResult.data); + } + } + catch (error) { + reject(error); + } + }); + (_e = options === null || options === void 0 ? void 0 : options.signal) === null || _e === void 0 ? void 0 : _e.addEventListener('abort', () => { + var _a; + cancel((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.reason); + }); + const timeout = (_f = options === null || options === void 0 ? void 0 : options.timeout) !== null && _f !== void 0 ? _f : DEFAULT_REQUEST_TIMEOUT_MSEC; + const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, 'Request timed out', { timeout })); + this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_g = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _g !== void 0 ? _g : false); + // Queue request if related to a task + const relatedTaskId = relatedTask === null || relatedTask === void 0 ? void 0 : relatedTask.taskId; + if (relatedTaskId) { + // Store the response resolver for this request so responses can be routed back + const responseResolver = (response) => { + const handler = this._responseHandlers.get(messageId); + if (handler) { + handler(response); + } + else { + // Log error when resolver is missing, but don't fail + this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`)); + } + }; + this._requestResolvers.set(messageId, responseResolver); + this._enqueueTaskMessage(relatedTaskId, { + type: 'request', + message: jsonrpcRequest, + timestamp: Date.now() + }).catch(error => { + this._cleanupTimeout(messageId); + reject(error); + }); + // Don't send through transport - queued messages are delivered via tasks/result only + // This prevents duplicate delivery for bidirectional transports + } + else { + // No related task - send through transport normally + this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => { + this._cleanupTimeout(messageId); + reject(error); + }); + } + }); + } + /** + * Gets the current status of a task. + * + * @experimental Use `client.experimental.tasks.getTask()` to access this method. + */ + async getTask(params, options) { + // @ts-expect-error SendRequestT cannot directly contain GetTaskRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/get', params }, GetTaskResultSchema, options); + } + /** + * Retrieves the result of a completed task. + * + * @experimental Use `client.experimental.tasks.getTaskResult()` to access this method. + */ + async getTaskResult(params, resultSchema, options) { + // @ts-expect-error SendRequestT cannot directly contain GetTaskPayloadRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/result', params }, resultSchema, options); + } + /** + * Lists tasks, optionally starting from a pagination cursor. + * + * @experimental Use `client.experimental.tasks.listTasks()` to access this method. + */ + async listTasks(params, options) { + // @ts-expect-error SendRequestT cannot directly contain ListTasksRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/list', params }, ListTasksResultSchema, options); + } + /** + * Cancels a specific task. + * + * @experimental Use `client.experimental.tasks.cancelTask()` to access this method. + */ + async cancelTask(params, options) { + // @ts-expect-error SendRequestT cannot directly contain CancelTaskRequest, but we ensure all type instantiations contain it anyways + return this.request({ method: 'tasks/cancel', params }, CancelTaskResultSchema, options); + } + /** + * Emits a notification, which is a one-way message that does not expect a response. + */ + async notification(notification, options) { + var _a, _b, _c, _d, _e; + if (!this._transport) { + throw new Error('Not connected'); + } + this.assertNotificationCapability(notification.method); + // Queue notification if related to a task + const relatedTaskId = (_a = options === null || options === void 0 ? void 0 : options.relatedTask) === null || _a === void 0 ? void 0 : _a.taskId; + if (relatedTaskId) { + // Build the JSONRPC notification with metadata + const jsonrpcNotification = { + ...notification, + jsonrpc: '2.0', + params: { + ...notification.params, + _meta: { + ...(((_b = notification.params) === null || _b === void 0 ? void 0 : _b._meta) || {}), + [RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + await this._enqueueTaskMessage(relatedTaskId, { + type: 'notification', + message: jsonrpcNotification, + timestamp: Date.now() + }); + // Don't send through transport - queued messages are delivered via tasks/result only + // This prevents duplicate delivery for bidirectional transports + return; + } + const debouncedMethods = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.debouncedNotificationMethods) !== null && _d !== void 0 ? _d : []; + // A notification can only be debounced if it's in the list AND it's "simple" + // (i.e., has no parameters and no related request ID or related task that could be lost). + const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !(options === null || options === void 0 ? void 0 : options.relatedRequestId) && !(options === null || options === void 0 ? void 0 : options.relatedTask); + if (canDebounce) { + // If a notification of this type is already scheduled, do nothing. + if (this._pendingDebouncedNotifications.has(notification.method)) { + return; + } + // Mark this notification type as pending. + this._pendingDebouncedNotifications.add(notification.method); + // Schedule the actual send to happen in the next microtask. + // This allows all synchronous calls in the current event loop tick to be coalesced. + Promise.resolve().then(() => { + var _a, _b; + // Un-mark the notification so the next one can be scheduled. + this._pendingDebouncedNotifications.delete(notification.method); + // SAFETY CHECK: If the connection was closed while this was pending, abort. + if (!this._transport) { + return; + } + let jsonrpcNotification = { + ...notification, + jsonrpc: '2.0' + }; + // Augment with related task metadata if relatedTask is provided + if (options === null || options === void 0 ? void 0 : options.relatedTask) { + jsonrpcNotification = { + ...jsonrpcNotification, + params: { + ...jsonrpcNotification.params, + _meta: { + ...(((_a = jsonrpcNotification.params) === null || _a === void 0 ? void 0 : _a._meta) || {}), + [RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + } + // Send the notification, but don't await it here to avoid blocking. + // Handle potential errors with a .catch(). + (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send(jsonrpcNotification, options).catch(error => this._onerror(error)); + }); + // Return immediately. + return; + } + let jsonrpcNotification = { + ...notification, + jsonrpc: '2.0' + }; + // Augment with related task metadata if relatedTask is provided + if (options === null || options === void 0 ? void 0 : options.relatedTask) { + jsonrpcNotification = { + ...jsonrpcNotification, + params: { + ...jsonrpcNotification.params, + _meta: { + ...(((_e = jsonrpcNotification.params) === null || _e === void 0 ? void 0 : _e._meta) || {}), + [RELATED_TASK_META_KEY]: options.relatedTask + } + } + }; + } + await this._transport.send(jsonrpcNotification, options); + } + /** + * Registers a handler to invoke when this protocol object receives a request with the given method. + * + * Note that this will replace any previous request handler for the same method. + */ + setRequestHandler(requestSchema, handler) { + const method = getMethodLiteral(requestSchema); + this.assertRequestHandlerCapability(method); + this._requestHandlers.set(method, (request, extra) => { + const parsed = parseWithCompat(requestSchema, request); + return Promise.resolve(handler(parsed, extra)); + }); + } + /** + * Removes the request handler for the given method. + */ + removeRequestHandler(method) { + this._requestHandlers.delete(method); + } + /** + * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed. + */ + assertCanSetRequestHandler(method) { + if (this._requestHandlers.has(method)) { + throw new Error(`A request handler for ${method} already exists, which would be overridden`); + } + } + /** + * Registers a handler to invoke when this protocol object receives a notification with the given method. + * + * Note that this will replace any previous notification handler for the same method. + */ + setNotificationHandler(notificationSchema, handler) { + const method = getMethodLiteral(notificationSchema); + this._notificationHandlers.set(method, notification => { + const parsed = parseWithCompat(notificationSchema, notification); + return Promise.resolve(handler(parsed)); + }); + } + /** + * Removes the notification handler for the given method. + */ + removeNotificationHandler(method) { + this._notificationHandlers.delete(method); + } + /** + * Cleans up the progress handler associated with a task. + * This should be called when a task reaches a terminal status. + */ + _cleanupTaskProgressHandler(taskId) { + const progressToken = this._taskProgressTokens.get(taskId); + if (progressToken !== undefined) { + this._progressHandlers.delete(progressToken); + this._taskProgressTokens.delete(taskId); + } + } + /** + * Enqueues a task-related message for side-channel delivery via tasks/result. + * @param taskId The task ID to associate the message with + * @param message The message to enqueue + * @param sessionId Optional session ID for binding the operation to a specific session + * @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow) + * + * Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle + * the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer + * simply propagates the error. + */ + async _enqueueTaskMessage(taskId, message, sessionId) { + var _a; + // Task message queues are only used when taskStore is configured + if (!this._taskStore || !this._taskMessageQueue) { + throw new Error('Cannot enqueue task message: taskStore and taskMessageQueue are not configured'); + } + const maxQueueSize = (_a = this._options) === null || _a === void 0 ? void 0 : _a.maxTaskQueueSize; + await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize); + } + /** + * Clears the message queue for a task and rejects any pending request resolvers. + * @param taskId The task ID whose queue should be cleared + * @param sessionId Optional session ID for binding the operation to a specific session + */ + async _clearTaskQueue(taskId, sessionId) { + if (this._taskMessageQueue) { + // Reject any pending request resolvers + const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId); + for (const message of messages) { + if (message.type === 'request' && isJSONRPCRequest(message.message)) { + // Extract request ID from the message + const requestId = message.message.id; + const resolver = this._requestResolvers.get(requestId); + if (resolver) { + resolver(new McpError(ErrorCode.InternalError, 'Task cancelled or completed')); + this._requestResolvers.delete(requestId); + } + else { + // Log error when resolver is missing during cleanup for better observability + this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`)); + } + } + } + } + } + /** + * Waits for a task update (new messages or status change) with abort signal support. + * Uses polling to check for updates at the task's configured poll interval. + * @param taskId The task ID to wait for + * @param signal Abort signal to cancel the wait + * @returns Promise that resolves when an update occurs or rejects if aborted + */ + async _waitForTaskUpdate(taskId, signal) { + var _a, _b, _c; + // Get the task's poll interval, falling back to default + let interval = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.defaultTaskPollInterval) !== null && _b !== void 0 ? _b : 1000; + try { + const task = await ((_c = this._taskStore) === null || _c === void 0 ? void 0 : _c.getTask(taskId)); + if (task === null || task === void 0 ? void 0 : task.pollInterval) { + interval = task.pollInterval; + } + } + catch (_d) { + // Use default interval if task lookup fails + } + return new Promise((resolve, reject) => { + if (signal.aborted) { + reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled')); + return; + } + // Wait for the poll interval, then resolve so caller can check for updates + const timeoutId = setTimeout(resolve, interval); + // Clean up timeout and reject if aborted + signal.addEventListener('abort', () => { + clearTimeout(timeoutId); + reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled')); + }, { once: true }); + }); + } + requestTaskStore(request, sessionId) { + const taskStore = this._taskStore; + if (!taskStore) { + throw new Error('No task store configured'); + } + return { + createTask: async (taskParams) => { + if (!request) { + throw new Error('No request provided'); + } + return await taskStore.createTask(taskParams, request.id, { + method: request.method, + params: request.params + }, sessionId); + }, + getTask: async (taskId) => { + const task = await taskStore.getTask(taskId, sessionId); + if (!task) { + throw new McpError(ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found'); + } + return task; + }, + storeTaskResult: async (taskId, status, result) => { + await taskStore.storeTaskResult(taskId, status, result, sessionId); + // Get updated task state and send notification + const task = await taskStore.getTask(taskId, sessionId); + if (task) { + const notification = TaskStatusNotificationSchema.parse({ + method: 'notifications/tasks/status', + params: task + }); + await this.notification(notification); + if (isTerminal(task.status)) { + this._cleanupTaskProgressHandler(taskId); + // Don't clear queue here - it will be cleared after delivery via tasks/result + } + } + }, + getTaskResult: taskId => { + return taskStore.getTaskResult(taskId, sessionId); + }, + updateTaskStatus: async (taskId, status, statusMessage) => { + // Check if task exists + const task = await taskStore.getTask(taskId, sessionId); + if (!task) { + throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`); + } + // Don't allow transitions from terminal states + if (isTerminal(task.status)) { + throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`); + } + await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId); + // Get updated task state and send notification + const updatedTask = await taskStore.getTask(taskId, sessionId); + if (updatedTask) { + const notification = TaskStatusNotificationSchema.parse({ + method: 'notifications/tasks/status', + params: updatedTask + }); + await this.notification(notification); + if (isTerminal(updatedTask.status)) { + this._cleanupTaskProgressHandler(taskId); + // Don't clear queue here - it will be cleared after delivery via tasks/result + } + } + }, + listTasks: cursor => { + return taskStore.listTasks(cursor, sessionId); + } + }; + } +} +function isPlainObject(value) { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} +export function mergeCapabilities(base, additional) { + const result = { ...base }; + for (const key in additional) { + const k = key; + const addValue = additional[k]; + if (addValue === undefined) + continue; + const baseValue = result[k]; + if (isPlainObject(baseValue) && isPlainObject(addValue)) { + result[k] = { ...baseValue, ...addValue }; + } + else { + result[k] = addValue; + } + } + return result; +} +//# sourceMappingURL=protocol.js.map \ No newline at end of file diff --git a/dist/esm/shared/protocol.js.map b/dist/esm/shared/protocol.js.map new file mode 100644 index 000000000..ec2d297a5 --- /dev/null +++ b/dist/esm/shared/protocol.js.map @@ -0,0 +1 @@ +{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/shared/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EACH,2BAA2B,EAE3B,sBAAsB,EACtB,SAAS,EAET,oBAAoB,EACpB,mBAAmB,EAEnB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EAKrB,QAAQ,EAER,iBAAiB,EAGjB,0BAA0B,EAC1B,qBAAqB,EAcrB,4BAA4B,EAC/B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,UAAU,EAAiE,MAAM,qCAAqC,CAAC;AAChI,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAoDxF;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAoMlD;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IA8C1B,YAAoB,QAA0B;QAA1B,aAAQ,GAAR,QAAQ,CAAkB;QA5CtC,sBAAiB,GAAG,CAAC,CAAC;QACtB,qBAAgB,GAGpB,IAAI,GAAG,EAAE,CAAC;QACN,oCAA+B,GAAoC,IAAI,GAAG,EAAE,CAAC;QAC7E,0BAAqB,GAAsE,IAAI,GAAG,EAAE,CAAC;QACrG,sBAAiB,GAA6D,IAAI,GAAG,EAAE,CAAC;QACxF,sBAAiB,GAAkC,IAAI,GAAG,EAAE,CAAC;QAC7D,iBAAY,GAA6B,IAAI,GAAG,EAAE,CAAC;QACnD,mCAA8B,GAAG,IAAI,GAAG,EAAU,CAAC;QAE3D,iFAAiF;QACzE,wBAAmB,GAAwB,IAAI,GAAG,EAAE,CAAC;QAKrD,sBAAiB,GAAgE,IAAI,GAAG,EAAE,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OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAClD,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AAED,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAID,MAAM,UAAU,iBAAiB,CAAoD,IAAO,EAAE,UAAsB;IAChH,MAAM,MAAM,GAAM,EAAE,GAAG,IAAI,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,GAAc,CAAC;QACzB,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAS;QACrC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,GAAI,SAAqC,EAAE,GAAI,QAAoC,EAAiB,CAAC;QACvH,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,CAAC,CAAC,GAAG,QAAuB,CAAC;QACxC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/responseMessage.d.ts b/dist/esm/shared/responseMessage.d.ts new file mode 100644 index 000000000..84354bdb7 --- /dev/null +++ b/dist/esm/shared/responseMessage.d.ts @@ -0,0 +1,45 @@ +import { Result, Task, McpError } from '../types.js'; +/** + * Base message type + */ +export interface BaseResponseMessage { + type: string; +} +/** + * Task status update message + */ +export interface TaskStatusMessage extends BaseResponseMessage { + type: 'taskStatus'; + task: Task; +} +/** + * Task created message (first message for task-augmented requests) + */ +export interface TaskCreatedMessage extends BaseResponseMessage { + type: 'taskCreated'; + task: Task; +} +/** + * Final result message (terminal) + */ +export interface ResultMessage extends BaseResponseMessage { + type: 'result'; + result: T; +} +/** + * Error message (terminal) + */ +export interface ErrorMessage extends BaseResponseMessage { + type: 'error'; + error: McpError; +} +/** + * Union type representing all possible messages that can be yielded during request processing. + * Note: Progress notifications are handled through the existing onprogress callback mechanism. + * Side-channeled messages (server requests/notifications) are handled through registered handlers. + */ +export type ResponseMessage = TaskStatusMessage | TaskCreatedMessage | ResultMessage | ErrorMessage; +export type AsyncGeneratorValue = T extends AsyncGenerator ? U : never; +export declare function toArrayAsync>(it: T): Promise[]>; +export declare function takeResult>>(it: U): Promise; +//# sourceMappingURL=responseMessage.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/responseMessage.d.ts.map b/dist/esm/shared/responseMessage.d.ts.map new file mode 100644 index 000000000..65d93bb50 --- /dev/null +++ b/dist/esm/shared/responseMessage.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"responseMessage.d.ts","sourceRoot":"","sources":["../../../src/shared/responseMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC1D,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC3D,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,mBAAmB;IACxE,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,CAAC,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACrD,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG,kBAAkB,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;AAEzH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF,wBAAsB,YAAY,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAO9G;AAED,wBAAsB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAUlH"} \ No newline at end of file diff --git a/dist/esm/shared/responseMessage.js b/dist/esm/shared/responseMessage.js new file mode 100644 index 000000000..d29e8a450 --- /dev/null +++ b/dist/esm/shared/responseMessage.js @@ -0,0 +1,19 @@ +export async function toArrayAsync(it) { + const arr = []; + for await (const o of it) { + arr.push(o); + } + return arr; +} +export async function takeResult(it) { + for await (const o of it) { + if (o.type === 'result') { + return o.result; + } + else if (o.type === 'error') { + throw o.error; + } + } + throw new Error('No result in stream.'); +} +//# sourceMappingURL=responseMessage.js.map \ No newline at end of file diff --git a/dist/esm/shared/responseMessage.js.map b/dist/esm/shared/responseMessage.js.map new file mode 100644 index 000000000..eca1ceccb --- /dev/null +++ b/dist/esm/shared/responseMessage.js.map @@ -0,0 +1 @@ +{"version":3,"file":"responseMessage.js","sourceRoot":"","sources":["../../../src/shared/responseMessage.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAC,KAAK,UAAU,YAAY,CAAoC,EAAK;IACvE,MAAM,GAAG,GAA6B,EAAE,CAAC;IACzC,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,GAAG,CAAC,IAAI,CAAC,CAA2B,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAiE,EAAK;IAClG,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC,MAAM,CAAC;QACpB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,CAAC,KAAK,CAAC;QAClB,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC5C,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/stdio.d.ts b/dist/esm/shared/stdio.d.ts new file mode 100644 index 000000000..0830a48bc --- /dev/null +++ b/dist/esm/shared/stdio.d.ts @@ -0,0 +1,13 @@ +import { JSONRPCMessage } from '../types.js'; +/** + * Buffers a continuous stdio stream into discrete JSON-RPC messages. + */ +export declare class ReadBuffer { + private _buffer?; + append(chunk: Buffer): void; + readMessage(): JSONRPCMessage | null; + clear(): void; +} +export declare function deserializeMessage(line: string): JSONRPCMessage; +export declare function serializeMessage(message: JSONRPCMessage): string; +//# sourceMappingURL=stdio.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/stdio.d.ts.map b/dist/esm/shared/stdio.d.ts.map new file mode 100644 index 000000000..8f97f2ab1 --- /dev/null +++ b/dist/esm/shared/stdio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/shared/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B,WAAW,IAAI,cAAc,GAAG,IAAI;IAepC,KAAK,IAAI,IAAI;CAGhB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAE/D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAEhE"} \ No newline at end of file diff --git a/dist/esm/shared/stdio.js b/dist/esm/shared/stdio.js new file mode 100644 index 000000000..30f299f5a --- /dev/null +++ b/dist/esm/shared/stdio.js @@ -0,0 +1,31 @@ +import { JSONRPCMessageSchema } from '../types.js'; +/** + * Buffers a continuous stdio stream into discrete JSON-RPC messages. + */ +export class ReadBuffer { + append(chunk) { + this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk; + } + readMessage() { + if (!this._buffer) { + return null; + } + const index = this._buffer.indexOf('\n'); + if (index === -1) { + return null; + } + const line = this._buffer.toString('utf8', 0, index).replace(/\r$/, ''); + this._buffer = this._buffer.subarray(index + 1); + return deserializeMessage(line); + } + clear() { + this._buffer = undefined; + } +} +export function deserializeMessage(line) { + return JSONRPCMessageSchema.parse(JSON.parse(line)); +} +export function serializeMessage(message) { + return JSON.stringify(message) + '\n'; +} +//# sourceMappingURL=stdio.js.map \ No newline at end of file diff --git a/dist/esm/shared/stdio.js.map b/dist/esm/shared/stdio.js.map new file mode 100644 index 000000000..19fdf08d8 --- /dev/null +++ b/dist/esm/shared/stdio.js.map @@ -0,0 +1 @@ +{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../../src/shared/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,UAAU;IAGnB,MAAM,CAAC,KAAa;QAChB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/E,CAAC;IAED,WAAW;QACP,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAChD,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC7B,CAAC;CACJ;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC3C,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;AAC1C,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/toolNameValidation.d.ts b/dist/esm/shared/toolNameValidation.d.ts new file mode 100644 index 000000000..3cf94bf78 --- /dev/null +++ b/dist/esm/shared/toolNameValidation.d.ts @@ -0,0 +1,31 @@ +/** + * Tool name validation utilities according to SEP: Specify Format for Tool Names + * + * Tool names SHOULD be between 1 and 128 characters in length (inclusive). + * Tool names are case-sensitive. + * Allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits + * (0-9), underscore (_), dash (-), and dot (.). + * Tool names SHOULD NOT contain spaces, commas, or other special characters. + */ +/** + * Validates a tool name according to the SEP specification + * @param name - The tool name to validate + * @returns An object containing validation result and any warnings + */ +export declare function validateToolName(name: string): { + isValid: boolean; + warnings: string[]; +}; +/** + * Issues warnings for non-conforming tool names + * @param name - The tool name that triggered the warnings + * @param warnings - Array of warning messages + */ +export declare function issueToolNameWarning(name: string, warnings: string[]): void; +/** + * Validates a tool name and issues warnings for non-conforming names + * @param name - The tool name to validate + * @returns true if the name is valid, false otherwise + */ +export declare function validateAndWarnToolName(name: string): boolean; +//# sourceMappingURL=toolNameValidation.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/toolNameValidation.d.ts.map b/dist/esm/shared/toolNameValidation.d.ts.map new file mode 100644 index 000000000..d81f0156e --- /dev/null +++ b/dist/esm/shared/toolNameValidation.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"toolNameValidation.d.ts","sourceRoot":"","sources":["../../../src/shared/toolNameValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB,CA0DA;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAY3E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO7D"} \ No newline at end of file diff --git a/dist/esm/shared/toolNameValidation.js b/dist/esm/shared/toolNameValidation.js new file mode 100644 index 000000000..34b6d19c5 --- /dev/null +++ b/dist/esm/shared/toolNameValidation.js @@ -0,0 +1,92 @@ +/** + * Tool name validation utilities according to SEP: Specify Format for Tool Names + * + * Tool names SHOULD be between 1 and 128 characters in length (inclusive). + * Tool names are case-sensitive. + * Allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits + * (0-9), underscore (_), dash (-), and dot (.). + * Tool names SHOULD NOT contain spaces, commas, or other special characters. + */ +/** + * Regular expression for valid tool names according to SEP-986 specification + */ +const TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/; +/** + * Validates a tool name according to the SEP specification + * @param name - The tool name to validate + * @returns An object containing validation result and any warnings + */ +export function validateToolName(name) { + const warnings = []; + // Check length + if (name.length === 0) { + return { + isValid: false, + warnings: ['Tool name cannot be empty'] + }; + } + if (name.length > 128) { + return { + isValid: false, + warnings: [`Tool name exceeds maximum length of 128 characters (current: ${name.length})`] + }; + } + // Check for specific problematic patterns (these are warnings, not validation failures) + if (name.includes(' ')) { + warnings.push('Tool name contains spaces, which may cause parsing issues'); + } + if (name.includes(',')) { + warnings.push('Tool name contains commas, which may cause parsing issues'); + } + // Check for potentially confusing patterns (leading/trailing dashes, dots, slashes) + if (name.startsWith('-') || name.endsWith('-')) { + warnings.push('Tool name starts or ends with a dash, which may cause parsing issues in some contexts'); + } + if (name.startsWith('.') || name.endsWith('.')) { + warnings.push('Tool name starts or ends with a dot, which may cause parsing issues in some contexts'); + } + // Check for invalid characters + if (!TOOL_NAME_REGEX.test(name)) { + const invalidChars = name + .split('') + .filter(char => !/[A-Za-z0-9._-]/.test(char)) + .filter((char, index, arr) => arr.indexOf(char) === index); // Remove duplicates + warnings.push(`Tool name contains invalid characters: ${invalidChars.map(c => `"${c}"`).join(', ')}`, 'Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)'); + return { + isValid: false, + warnings + }; + } + return { + isValid: true, + warnings + }; +} +/** + * Issues warnings for non-conforming tool names + * @param name - The tool name that triggered the warnings + * @param warnings - Array of warning messages + */ +export function issueToolNameWarning(name, warnings) { + if (warnings.length > 0) { + console.warn(`Tool name validation warning for "${name}":`); + for (const warning of warnings) { + console.warn(` - ${warning}`); + } + console.warn('Tool registration will proceed, but this may cause compatibility issues.'); + console.warn('Consider updating the tool name to conform to the MCP tool naming standard.'); + console.warn('See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.'); + } +} +/** + * Validates a tool name and issues warnings for non-conforming names + * @param name - The tool name to validate + * @returns true if the name is valid, false otherwise + */ +export function validateAndWarnToolName(name) { + const result = validateToolName(name); + // Always issue warnings for any validation issues (both invalid names and warnings) + issueToolNameWarning(name, result.warnings); + return result.isValid; +} +//# sourceMappingURL=toolNameValidation.js.map \ No newline at end of file diff --git a/dist/esm/shared/toolNameValidation.js.map b/dist/esm/shared/toolNameValidation.js.map new file mode 100644 index 000000000..9fdfcea84 --- /dev/null +++ b/dist/esm/shared/toolNameValidation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"toolNameValidation.js","sourceRoot":"","sources":["../../../src/shared/toolNameValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAElD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAIzC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,eAAe;IACf,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO;YACH,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,CAAC,2BAA2B,CAAC;SAC1C,CAAC;IACN,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACpB,OAAO;YACH,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,CAAC,gEAAgE,IAAI,CAAC,MAAM,GAAG,CAAC;SAC7F,CAAC;IACN,CAAC;IAED,wFAAwF;IACxF,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,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X,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,QAAkB;IACjE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,IAAI,CAAC,CAAC;QAC5D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;QACzF,OAAO,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAC;QAC5F,OAAO,CAAC,IAAI,CACR,oIAAoI,CACvI,CAAC;IACN,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAChD,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAEtC,oFAAoF;IACpF,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC,OAAO,CAAC;AAC1B,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/transport.d.ts b/dist/esm/shared/transport.d.ts new file mode 100644 index 000000000..7fb5efab7 --- /dev/null +++ b/dist/esm/shared/transport.d.ts @@ -0,0 +1,89 @@ +import { JSONRPCMessage, MessageExtraInfo, RequestId } from '../types.js'; +export type FetchLike = (url: string | URL, init?: RequestInit) => Promise; +/** + * Normalizes HeadersInit to a plain Record for manipulation. + * Handles Headers objects, arrays of tuples, and plain objects. + */ +export declare function normalizeHeaders(headers: HeadersInit | undefined): Record; +/** + * Creates a fetch function that includes base RequestInit options. + * This ensures requests inherit settings like credentials, mode, headers, etc. from the base init. + * + * @param baseFetch - The base fetch function to wrap (defaults to global fetch) + * @param baseInit - The base RequestInit to merge with each request + * @returns A wrapped fetch function that merges base options with call-specific options + */ +export declare function createFetchWithInit(baseFetch?: FetchLike, baseInit?: RequestInit): FetchLike; +/** + * Options for sending a JSON-RPC message. + */ +export type TransportSendOptions = { + /** + * If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with. + */ + relatedRequestId?: RequestId; + /** + * The resumption token used to continue long-running requests that were interrupted. + * + * This allows clients to reconnect and continue from where they left off, if supported by the transport. + */ + resumptionToken?: string; + /** + * A callback that is invoked when the resumption token changes, if supported by the transport. + * + * This allows clients to persist the latest token for potential reconnection. + */ + onresumptiontoken?: (token: string) => void; +}; +/** + * Describes the minimal contract for a MCP transport that a client or server can communicate over. + */ +export interface Transport { + /** + * Starts processing messages on the transport, including any connection steps that might need to be taken. + * + * This method should only be called after callbacks are installed, or else messages may be lost. + * + * NOTE: This method should not be called explicitly when using Client, Server, or Protocol classes, as they will implicitly call start(). + */ + start(): Promise; + /** + * Sends a JSON-RPC message (request or response). + * + * If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with. + */ + send(message: JSONRPCMessage, options?: TransportSendOptions): Promise; + /** + * Closes the connection. + */ + close(): Promise; + /** + * Callback for when the connection is closed for any reason. + * + * This should be invoked when close() is called as well. + */ + onclose?: () => void; + /** + * Callback for when an error occurs. + * + * Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band. + */ + onerror?: (error: Error) => void; + /** + * Callback for when a message (request or response) is received over the connection. + * + * Includes the requestInfo and authInfo if the transport is authenticated. + * + * The requestInfo can be used to get the original request information (headers, etc.) + */ + onmessage?: (message: T, extra?: MessageExtraInfo) => void; + /** + * The session ID generated for this connection. + */ + sessionId?: string; + /** + * Sets the protocol version used for the connection (called when the initialize response is received). + */ + setProtocolVersion?: (version: string) => void; +} +//# sourceMappingURL=transport.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/transport.d.ts.map b/dist/esm/shared/transport.d.ts.map new file mode 100644 index 000000000..7a3d837df --- /dev/null +++ b/dist/esm/shared/transport.d.ts.map @@ -0,0 +1 @@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,SAAS,cAAc,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAErF;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD"} \ No newline at end of file diff --git a/dist/esm/shared/transport.js b/dist/esm/shared/transport.js new file mode 100644 index 000000000..486c840dd --- /dev/null +++ b/dist/esm/shared/transport.js @@ -0,0 +1,39 @@ +/** + * Normalizes HeadersInit to a plain Record for manipulation. + * Handles Headers objects, arrays of tuples, and plain objects. + */ +export function normalizeHeaders(headers) { + if (!headers) + return {}; + if (headers instanceof Headers) { + return Object.fromEntries(headers.entries()); + } + if (Array.isArray(headers)) { + return Object.fromEntries(headers); + } + return { ...headers }; +} +/** + * Creates a fetch function that includes base RequestInit options. + * This ensures requests inherit settings like credentials, mode, headers, etc. from the base init. + * + * @param baseFetch - The base fetch function to wrap (defaults to global fetch) + * @param baseInit - The base RequestInit to merge with each request + * @returns A wrapped fetch function that merges base options with call-specific options + */ +export function createFetchWithInit(baseFetch = fetch, baseInit) { + if (!baseInit) { + return baseFetch; + } + // Return a wrapped fetch that merges base RequestInit with call-specific init + return async (url, init) => { + const mergedInit = { + ...baseInit, + ...init, + // Headers need special handling - merge instead of replace + headers: (init === null || init === void 0 ? void 0 : init.headers) ? { ...normalizeHeaders(baseInit.headers), ...normalizeHeaders(init.headers) } : baseInit.headers + }; + return baseFetch(url, mergedInit); + }; +} +//# sourceMappingURL=transport.js.map \ No newline at end of file diff --git a/dist/esm/shared/transport.js.map b/dist/esm/shared/transport.js.map new file mode 100644 index 000000000..026dddb82 --- /dev/null +++ b/dist/esm/shared/transport.js.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/shared/transport.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC7D,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,GAAI,OAAkC,EAAE,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAuB,KAAK,EAAE,QAAsB;IACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,8EAA8E;IAC9E,OAAO,KAAK,EAAE,GAAiB,EAAE,IAAkB,EAAqB,EAAE;QACtE,MAAM,UAAU,GAAgB;YAC5B,GAAG,QAAQ;YACX,GAAG,IAAI;YACP,2DAA2D;YAC3D,OAAO,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO;SAC3H,CAAC;QACF,OAAO,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/uriTemplate.d.ts b/dist/esm/shared/uriTemplate.d.ts new file mode 100644 index 000000000..175e329b6 --- /dev/null +++ b/dist/esm/shared/uriTemplate.d.ts @@ -0,0 +1,25 @@ +export type Variables = Record; +export declare class UriTemplate { + /** + * Returns true if the given string contains any URI template expressions. + * A template expression is a sequence of characters enclosed in curly braces, + * like {foo} or {?bar}. + */ + static isTemplate(str: string): boolean; + private static validateLength; + private readonly template; + private readonly parts; + get variableNames(): string[]; + constructor(template: string); + toString(): string; + private parse; + private getOperator; + private getNames; + private encodeValue; + private expandPart; + expand(variables: Variables): string; + private escapeRegExp; + private partToRegExp; + match(uri: string): Variables | null; +} +//# sourceMappingURL=uriTemplate.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/uriTemplate.d.ts.map b/dist/esm/shared/uriTemplate.d.ts.map new file mode 100644 index 000000000..052e91851 --- /dev/null +++ b/dist/esm/shared/uriTemplate.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"uriTemplate.d.ts","sourceRoot":"","sources":["../../../src/shared/uriTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAO1D,qBAAa,WAAW;IACpB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAMvC,OAAO,CAAC,MAAM,CAAC,cAAc;IAK7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyF;IAE/G,IAAI,aAAa,IAAI,MAAM,EAAE,CAE5B;gBAEW,QAAQ,EAAE,MAAM;IAM5B,QAAQ,IAAI,MAAM;IAIlB,OAAO,CAAC,KAAK;IA8Cb,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,UAAU;IAsDlB,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM;IA4BpC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;IAkDpB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAuCvC"} \ No newline at end of file diff --git a/dist/esm/shared/uriTemplate.js b/dist/esm/shared/uriTemplate.js new file mode 100644 index 000000000..2837ba826 --- /dev/null +++ b/dist/esm/shared/uriTemplate.js @@ -0,0 +1,239 @@ +// Claude-authored implementation of RFC 6570 URI Templates +const MAX_TEMPLATE_LENGTH = 1000000; // 1MB +const MAX_VARIABLE_LENGTH = 1000000; // 1MB +const MAX_TEMPLATE_EXPRESSIONS = 10000; +const MAX_REGEX_LENGTH = 1000000; // 1MB +export class UriTemplate { + /** + * Returns true if the given string contains any URI template expressions. + * A template expression is a sequence of characters enclosed in curly braces, + * like {foo} or {?bar}. + */ + static isTemplate(str) { + // Look for any sequence of characters between curly braces + // that isn't just whitespace + return /\{[^}\s]+\}/.test(str); + } + static validateLength(str, max, context) { + if (str.length > max) { + throw new Error(`${context} exceeds maximum length of ${max} characters (got ${str.length})`); + } + } + get variableNames() { + return this.parts.flatMap(part => (typeof part === 'string' ? [] : part.names)); + } + constructor(template) { + UriTemplate.validateLength(template, MAX_TEMPLATE_LENGTH, 'Template'); + this.template = template; + this.parts = this.parse(template); + } + toString() { + return this.template; + } + parse(template) { + const parts = []; + let currentText = ''; + let i = 0; + let expressionCount = 0; + while (i < template.length) { + if (template[i] === '{') { + if (currentText) { + parts.push(currentText); + currentText = ''; + } + const end = template.indexOf('}', i); + if (end === -1) + throw new Error('Unclosed template expression'); + expressionCount++; + if (expressionCount > MAX_TEMPLATE_EXPRESSIONS) { + throw new Error(`Template contains too many expressions (max ${MAX_TEMPLATE_EXPRESSIONS})`); + } + const expr = template.slice(i + 1, end); + const operator = this.getOperator(expr); + const exploded = expr.includes('*'); + const names = this.getNames(expr); + const name = names[0]; + // Validate variable name length + for (const name of names) { + UriTemplate.validateLength(name, MAX_VARIABLE_LENGTH, 'Variable name'); + } + parts.push({ name, operator, names, exploded }); + i = end + 1; + } + else { + currentText += template[i]; + i++; + } + } + if (currentText) { + parts.push(currentText); + } + return parts; + } + getOperator(expr) { + const operators = ['+', '#', '.', '/', '?', '&']; + return operators.find(op => expr.startsWith(op)) || ''; + } + getNames(expr) { + const operator = this.getOperator(expr); + return expr + .slice(operator.length) + .split(',') + .map(name => name.replace('*', '').trim()) + .filter(name => name.length > 0); + } + encodeValue(value, operator) { + UriTemplate.validateLength(value, MAX_VARIABLE_LENGTH, 'Variable value'); + if (operator === '+' || operator === '#') { + return encodeURI(value); + } + return encodeURIComponent(value); + } + expandPart(part, variables) { + if (part.operator === '?' || part.operator === '&') { + const pairs = part.names + .map(name => { + const value = variables[name]; + if (value === undefined) + return ''; + const encoded = Array.isArray(value) + ? value.map(v => this.encodeValue(v, part.operator)).join(',') + : this.encodeValue(value.toString(), part.operator); + return `${name}=${encoded}`; + }) + .filter(pair => pair.length > 0); + if (pairs.length === 0) + return ''; + const separator = part.operator === '?' ? '?' : '&'; + return separator + pairs.join('&'); + } + if (part.names.length > 1) { + const values = part.names.map(name => variables[name]).filter(v => v !== undefined); + if (values.length === 0) + return ''; + return values.map(v => (Array.isArray(v) ? v[0] : v)).join(','); + } + const value = variables[part.name]; + if (value === undefined) + return ''; + const values = Array.isArray(value) ? value : [value]; + const encoded = values.map(v => this.encodeValue(v, part.operator)); + switch (part.operator) { + case '': + return encoded.join(','); + case '+': + return encoded.join(','); + case '#': + return '#' + encoded.join(','); + case '.': + return '.' + encoded.join('.'); + case '/': + return '/' + encoded.join('/'); + default: + return encoded.join(','); + } + } + expand(variables) { + let result = ''; + let hasQueryParam = false; + for (const part of this.parts) { + if (typeof part === 'string') { + result += part; + continue; + } + const expanded = this.expandPart(part, variables); + if (!expanded) + continue; + // Convert ? to & if we already have a query parameter + if ((part.operator === '?' || part.operator === '&') && hasQueryParam) { + result += expanded.replace('?', '&'); + } + else { + result += expanded; + } + if (part.operator === '?' || part.operator === '&') { + hasQueryParam = true; + } + } + return result; + } + escapeRegExp(str) { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + partToRegExp(part) { + const patterns = []; + // Validate variable name length for matching + for (const name of part.names) { + UriTemplate.validateLength(name, MAX_VARIABLE_LENGTH, 'Variable name'); + } + if (part.operator === '?' || part.operator === '&') { + for (let i = 0; i < part.names.length; i++) { + const name = part.names[i]; + const prefix = i === 0 ? '\\' + part.operator : '&'; + patterns.push({ + pattern: prefix + this.escapeRegExp(name) + '=([^&]+)', + name + }); + } + return patterns; + } + let pattern; + const name = part.name; + switch (part.operator) { + case '': + pattern = part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)'; + break; + case '+': + case '#': + pattern = '(.+)'; + break; + case '.': + pattern = '\\.([^/,]+)'; + break; + case '/': + pattern = '/' + (part.exploded ? '([^/]+(?:,[^/]+)*)' : '([^/,]+)'); + break; + default: + pattern = '([^/]+)'; + } + patterns.push({ pattern, name }); + return patterns; + } + match(uri) { + UriTemplate.validateLength(uri, MAX_TEMPLATE_LENGTH, 'URI'); + let pattern = '^'; + const names = []; + for (const part of this.parts) { + if (typeof part === 'string') { + pattern += this.escapeRegExp(part); + } + else { + const patterns = this.partToRegExp(part); + for (const { pattern: partPattern, name } of patterns) { + pattern += partPattern; + names.push({ name, exploded: part.exploded }); + } + } + } + pattern += '$'; + UriTemplate.validateLength(pattern, MAX_REGEX_LENGTH, 'Generated regex pattern'); + const regex = new RegExp(pattern); + const match = uri.match(regex); + if (!match) + return null; + const result = {}; + for (let i = 0; i < names.length; i++) { + const { name, exploded } = names[i]; + const value = match[i + 1]; + const cleanName = name.replace('*', ''); + if (exploded && value.includes(',')) { + result[cleanName] = value.split(','); + } + else { + result[cleanName] = value; + } + } + return result; + } +} +//# sourceMappingURL=uriTemplate.js.map \ No newline at end of file diff --git a/dist/esm/shared/uriTemplate.js.map b/dist/esm/shared/uriTemplate.js.map new file mode 100644 index 000000000..2c02e92ae --- /dev/null +++ b/dist/esm/shared/uriTemplate.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uriTemplate.js","sourceRoot":"","sources":["../../../src/shared/uriTemplate.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAI3D,MAAM,mBAAmB,GAAG,OAAO,CAAC,CAAC,MAAM;AAC3C,M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AAC,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAExC,IAAI,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClC,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/shared/zodTestMatrix.d.ts b/dist/esm/shared/zodTestMatrix.d.ts new file mode 100644 index 000000000..7dafd4ce9 --- /dev/null +++ b/dist/esm/shared/zodTestMatrix.d.ts @@ -0,0 +1,16 @@ +import * as z3 from 'zod/v3'; +import * as z4 from 'zod/v4'; +export type ZNamespace = typeof z3 & typeof z4; +export declare const zodTestMatrix: readonly [{ + readonly zodVersionLabel: "Zod v3"; + readonly z: ZNamespace; + readonly isV3: true; + readonly isV4: false; +}, { + readonly zodVersionLabel: "Zod v4"; + readonly z: ZNamespace; + readonly isV3: false; + readonly isV4: true; +}]; +export type ZodMatrixEntry = (typeof zodTestMatrix)[number]; +//# sourceMappingURL=zodTestMatrix.d.ts.map \ No newline at end of file diff --git a/dist/esm/shared/zodTestMatrix.d.ts.map b/dist/esm/shared/zodTestMatrix.d.ts.map new file mode 100644 index 000000000..3842fb1c3 --- /dev/null +++ b/dist/esm/shared/zodTestMatrix.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"zodTestMatrix.d.ts","sourceRoot":"","sources":["../../../src/shared/zodTestMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG7B,MAAM,MAAM,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AAE/C,eAAO,MAAM,aAAa;;gBAGT,UAAU;;;;;gBAMV,UAAU;;;EAIjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/shared/zodTestMatrix.js b/dist/esm/shared/zodTestMatrix.js new file mode 100644 index 000000000..aafaed475 --- /dev/null +++ b/dist/esm/shared/zodTestMatrix.js @@ -0,0 +1,17 @@ +import * as z3 from 'zod/v3'; +import * as z4 from 'zod/v4'; +export const zodTestMatrix = [ + { + zodVersionLabel: 'Zod v3', + z: z3, + isV3: true, + isV4: false + }, + { + zodVersionLabel: 'Zod v4', + z: z4, + isV3: false, + isV4: true + } +]; +//# sourceMappingURL=zodTestMatrix.js.map \ No newline at end of file diff --git a/dist/esm/shared/zodTestMatrix.js.map b/dist/esm/shared/zodTestMatrix.js.map new file mode 100644 index 000000000..581a23a5b --- /dev/null +++ b/dist/esm/shared/zodTestMatrix.js.map @@ -0,0 +1 @@ +{"version":3,"file":"zodTestMatrix.js","sourceRoot":"","sources":["../../../src/shared/zodTestMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAK7B,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB;QACI,eAAe,EAAE,QAAQ;QACzB,CAAC,EAAE,EAAgB;QACnB,IAAI,EAAE,IAAa;QACnB,IAAI,EAAE,KAAc;KACvB;IACD;QACI,eAAe,EAAE,QAAQ;QACzB,CAAC,EAAE,EAAgB;QACnB,IAAI,EAAE,KAAc;QACpB,IAAI,EAAE,IAAa;KACtB;CACK,CAAC"} \ No newline at end of file diff --git a/dist/esm/spec.types.d.ts b/dist/esm/spec.types.d.ts new file mode 100644 index 000000000..86dd720a9 --- /dev/null +++ b/dist/esm/spec.types.d.ts @@ -0,0 +1,2010 @@ +/** + * This file is automatically generated from the Model Context Protocol specification. + * + * Source: https://github.com/modelcontextprotocol/modelcontextprotocol + * Pulled from: https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/draft/schema.ts + * Last updated from commit: 7dcdd69262bd488ddec071bf4eefedabf1742023 + * + * DO NOT EDIT THIS FILE MANUALLY. Changes will be overwritten by automated updates. + * To update this file, run: npm run fetch:spec-types + */ +/** + * Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent. + * + * @category JSON-RPC + */ +export type JSONRPCMessage = JSONRPCRequest | JSONRPCNotification | JSONRPCResponse | JSONRPCError; +/** @internal */ +export declare const LATEST_PROTOCOL_VERSION = "DRAFT-2025-v3"; +/** @internal */ +export declare const JSONRPC_VERSION = "2.0"; +/** + * A progress token, used to associate progress notifications with the original request. + * + * @category Common Types + */ +export type ProgressToken = string | number; +/** + * An opaque token used to represent a cursor for pagination. + * + * @category Common Types + */ +export type Cursor = string; +/** + * Common params for any request. + * + * @internal + */ +export interface RequestParams { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken?: ProgressToken; + [key: string]: unknown; + }; +} +/** @internal */ +export interface Request { + method: string; + params?: { + [key: string]: any; + }; +} +/** @internal */ +export interface NotificationParams { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** @internal */ +export interface Notification { + method: string; + params?: { + [key: string]: any; + }; +} +/** + * @category Common Types + */ +export interface Result { + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; + [key: string]: unknown; +} +/** + * @category Common Types + */ +export interface Error { + /** + * The error type that occurred. + */ + code: number; + /** + * A short description of the error. The message SHOULD be limited to a concise single sentence. + */ + message: string; + /** + * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). + */ + data?: unknown; +} +/** + * A uniquely identifying ID for a request in JSON-RPC. + * + * @category Common Types + */ +export type RequestId = string | number; +/** + * A request that expects a response. + * + * @category JSON-RPC + */ +export interface JSONRPCRequest extends Request { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; +} +/** + * A notification which does not expect a response. + * + * @category JSON-RPC + */ +export interface JSONRPCNotification extends Notification { + jsonrpc: typeof JSONRPC_VERSION; +} +/** + * A successful (non-error) response to a request. + * + * @category JSON-RPC + */ +export interface JSONRPCResponse { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; + result: Result; +} +export declare const PARSE_ERROR = -32700; +export declare const INVALID_REQUEST = -32600; +export declare const METHOD_NOT_FOUND = -32601; +export declare const INVALID_PARAMS = -32602; +export declare const INTERNAL_ERROR = -32603; +/** @internal */ +export declare const URL_ELICITATION_REQUIRED = -32042; +/** + * A response to a request that indicates an error occurred. + * + * @category JSON-RPC + */ +export interface JSONRPCError { + jsonrpc: typeof JSONRPC_VERSION; + id: RequestId; + error: Error; +} +/** + * An error response that indicates that the server requires the client to provide additional information via an elicitation request. + * + * @internal + */ +export interface URLElicitationRequiredError extends Omit { + error: Error & { + code: typeof URL_ELICITATION_REQUIRED; + data: { + elicitations: ElicitRequestURLParams[]; + [key: string]: unknown; + }; + }; +} +/** + * A response that indicates success but carries no data. + * + * @category Common Types + */ +export type EmptyResult = Result; +/** + * Parameters for a `notifications/cancelled` notification. + * + * @category `notifications/cancelled` + */ +export interface CancelledNotificationParams extends NotificationParams { + /** + * The ID of the request to cancel. + * + * This MUST correspond to the ID of a request previously issued in the same direction. + */ + requestId: RequestId; + /** + * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. + */ + reason?: string; +} +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + * + * @category `notifications/cancelled` + */ +export interface CancelledNotification extends JSONRPCNotification { + method: "notifications/cancelled"; + params: CancelledNotificationParams; +} +/** + * Parameters for an `initialize` request. + * + * @category `initialize` + */ +export interface InitializeRequestParams extends RequestParams { + /** + * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. + */ + protocolVersion: string; + capabilities: ClientCapabilities; + clientInfo: Implementation; +} +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + * + * @category `initialize` + */ +export interface InitializeRequest extends JSONRPCRequest { + method: "initialize"; + params: InitializeRequestParams; +} +/** + * After receiving an initialize request from the client, the server sends this response. + * + * @category `initialize` + */ +export interface InitializeResult extends Result { + /** + * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. + */ + protocolVersion: string; + capabilities: ServerCapabilities; + serverInfo: Implementation; + /** + * Instructions describing how to use the server and its features. + * + * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. + */ + instructions?: string; +} +/** + * This notification is sent from the client to the server after initialization has finished. + * + * @category `notifications/initialized` + */ +export interface InitializedNotification extends JSONRPCNotification { + method: "notifications/initialized"; + params?: NotificationParams; +} +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + * + * @category `initialize` + */ +export interface ClientCapabilities { + /** + * Experimental, non-standard capabilities that the client supports. + */ + experimental?: { + [key: string]: object; + }; + /** + * Present if the client supports listing roots. + */ + roots?: { + /** + * Whether the client supports notifications for changes to the roots list. + */ + listChanged?: boolean; + }; + /** + * Present if the client supports sampling from an LLM. + */ + sampling?: { + /** + * Whether the client supports context inclusion via includeContext parameter. + * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it). + */ + context?: object; + /** + * Whether the client supports tool use via tools and toolChoice parameters. + */ + tools?: object; + }; + /** + * Present if the client supports elicitation from the server. + */ + elicitation?: { + form?: object; + url?: object; + }; +} +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + * + * @category `initialize` + */ +export interface ServerCapabilities { + /** + * Experimental, non-standard capabilities that the server supports. + */ + experimental?: { + [key: string]: object; + }; + /** + * Present if the server supports sending log messages to the client. + */ + logging?: object; + /** + * Present if the server supports argument autocompletion suggestions. + */ + completions?: object; + /** + * Present if the server offers any prompt templates. + */ + prompts?: { + /** + * Whether this server supports notifications for changes to the prompt list. + */ + listChanged?: boolean; + }; + /** + * Present if the server offers any resources to read. + */ + resources?: { + /** + * Whether this server supports subscribing to resource updates. + */ + subscribe?: boolean; + /** + * Whether this server supports notifications for changes to the resource list. + */ + listChanged?: boolean; + }; + /** + * Present if the server offers any tools to call. + */ + tools?: { + /** + * Whether this server supports notifications for changes to the tool list. + */ + listChanged?: boolean; + }; +} +/** + * An optionally-sized icon that can be displayed in a user interface. + * + * @category Common Types + */ +export interface Icon { + /** + * A standard URI pointing to an icon resource. May be an HTTP/HTTPS URL or a + * `data:` URI with Base64-encoded image data. + * + * Consumers SHOULD takes steps to ensure URLs serving icons are from the + * same domain as the client/server or a trusted domain. + * + * Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain + * executable JavaScript. + * + * @format uri + */ + src: string; + /** + * Optional MIME type override if the source MIME type is missing or generic. + * For example: `"image/png"`, `"image/jpeg"`, or `"image/svg+xml"`. + */ + mimeType?: string; + /** + * Optional array of strings that specify sizes at which the icon can be used. + * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. + * + * If not provided, the client should assume that the icon can be used at any size. + */ + sizes?: string[]; + /** + * Optional specifier for the theme this icon is designed for. `light` indicates + * the icon is designed to be used with a light background, and `dark` indicates + * the icon is designed to be used with a dark background. + * + * If not provided, the client should assume the icon can be used with any theme. + */ + theme?: "light" | "dark"; +} +/** + * Base interface to add `icons` property. + * + * @internal + */ +export interface Icons { + /** + * Optional set of sized icons that the client can display in a user interface. + * + * Clients that support rendering icons MUST support at least the following MIME types: + * - `image/png` - PNG images (safe, universal compatibility) + * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) + * + * Clients that support rendering icons SHOULD also support: + * - `image/svg+xml` - SVG images (scalable but requires security precautions) + * - `image/webp` - WebP images (modern, efficient format) + */ + icons?: Icon[]; +} +/** + * Base interface for metadata with name (identifier) and title (display name) properties. + * + * @internal + */ +export interface BaseMetadata { + /** + * Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn't present). + */ + name: string; + /** + * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, + * even by those unfamiliar with domain-specific terminology. + * + * If not provided, the name should be used for display (except for Tool, + * where `annotations.title` should be given precedence over using `name`, + * if present). + */ + title?: string; +} +/** + * Describes the MCP implementation. + * + * @category `initialize` + */ +export interface Implementation extends BaseMetadata, Icons { + version: string; + /** + * An optional human-readable description of what this implementation does. + * + * This can be used by clients or servers to provide context about their purpose + * and capabilities. For example, a server might describe the types of resources + * or tools it provides, while a client might describe its intended use case. + */ + description?: string; + /** + * An optional URL of the website for this implementation. + * + * @format uri + */ + websiteUrl?: string; +} +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + * + * @category `ping` + */ +export interface PingRequest extends JSONRPCRequest { + method: "ping"; + params?: RequestParams; +} +/** + * Parameters for a `notifications/progress` notification. + * + * @category `notifications/progress` + */ +export interface ProgressNotificationParams extends NotificationParams { + /** + * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding. + */ + progressToken: ProgressToken; + /** + * The progress thus far. This should increase every time progress is made, even if the total is unknown. + * + * @TJS-type number + */ + progress: number; + /** + * Total number of items to process (or total progress required), if known. + * + * @TJS-type number + */ + total?: number; + /** + * An optional message describing the current progress. + */ + message?: string; +} +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category `notifications/progress` + */ +export interface ProgressNotification extends JSONRPCNotification { + method: "notifications/progress"; + params: ProgressNotificationParams; +} +/** + * Common parameters for paginated requests. + * + * @internal + */ +export interface PaginatedRequestParams extends RequestParams { + /** + * An opaque token representing the current pagination position. + * If provided, the server should return results starting after this cursor. + */ + cursor?: Cursor; +} +/** @internal */ +export interface PaginatedRequest extends JSONRPCRequest { + params?: PaginatedRequestParams; +} +/** @internal */ +export interface PaginatedResult extends Result { + /** + * An opaque token representing the pagination position after the last returned result. + * If present, there may be more results available. + */ + nextCursor?: Cursor; +} +/** + * Sent from the client to request a list of resources the server has. + * + * @category `resources/list` + */ +export interface ListResourcesRequest extends PaginatedRequest { + method: "resources/list"; +} +/** + * The server's response to a resources/list request from the client. + * + * @category `resources/list` + */ +export interface ListResourcesResult extends PaginatedResult { + resources: Resource[]; +} +/** + * Sent from the client to request a list of resource templates the server has. + * + * @category `resources/templates/list` + */ +export interface ListResourceTemplatesRequest extends PaginatedRequest { + method: "resources/templates/list"; +} +/** + * The server's response to a resources/templates/list request from the client. + * + * @category `resources/templates/list` + */ +export interface ListResourceTemplatesResult extends PaginatedResult { + resourceTemplates: ResourceTemplate[]; +} +/** + * Common parameters when working with resources. + * + * @internal + */ +export interface ResourceRequestParams extends RequestParams { + /** + * The URI of the resource. The URI can use any protocol; it is up to the server how to interpret it. + * + * @format uri + */ + uri: string; +} +/** + * Parameters for a `resources/read` request. + * + * @category `resources/read` + */ +export interface ReadResourceRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to the server, to read a specific resource URI. + * + * @category `resources/read` + */ +export interface ReadResourceRequest extends JSONRPCRequest { + method: "resources/read"; + params: ReadResourceRequestParams; +} +/** + * The server's response to a resources/read request from the client. + * + * @category `resources/read` + */ +export interface ReadResourceResult extends Result { + contents: (TextResourceContents | BlobResourceContents)[]; +} +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/resources/list_changed` + */ +export interface ResourceListChangedNotification extends JSONRPCNotification { + method: "notifications/resources/list_changed"; + params?: NotificationParams; +} +/** + * Parameters for a `resources/subscribe` request. + * + * @category `resources/subscribe` + */ +export interface SubscribeRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + * + * @category `resources/subscribe` + */ +export interface SubscribeRequest extends JSONRPCRequest { + method: "resources/subscribe"; + params: SubscribeRequestParams; +} +/** + * Parameters for a `resources/unsubscribe` request. + * + * @category `resources/unsubscribe` + */ +export interface UnsubscribeRequestParams extends ResourceRequestParams { +} +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + * + * @category `resources/unsubscribe` + */ +export interface UnsubscribeRequest extends JSONRPCRequest { + method: "resources/unsubscribe"; + params: UnsubscribeRequestParams; +} +/** + * Parameters for a `notifications/resources/updated` notification. + * + * @category `notifications/resources/updated` + */ +export interface ResourceUpdatedNotificationParams extends NotificationParams { + /** + * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. + * + * @format uri + */ + uri: string; +} +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + * + * @category `notifications/resources/updated` + */ +export interface ResourceUpdatedNotification extends JSONRPCNotification { + method: "notifications/resources/updated"; + params: ResourceUpdatedNotificationParams; +} +/** + * A known resource that the server is capable of reading. + * + * @category `resources/list` + */ +export interface Resource extends BaseMetadata, Icons { + /** + * The URI of this resource. + * + * @format uri + */ + uri: string; + /** + * A description of what this resource represents. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * The MIME type of this resource, if known. + */ + mimeType?: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known. + * + * This can be used by Hosts to display file sizes and estimate context window usage. + */ + size?: number; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A template description for resources available on the server. + * + * @category `resources/templates/list` + */ +export interface ResourceTemplate extends BaseMetadata, Icons { + /** + * A URI template (according to RFC 6570) that can be used to construct resource URIs. + * + * @format uri-template + */ + uriTemplate: string; + /** + * A description of what this template is for. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type. + */ + mimeType?: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The contents of a specific resource or sub-resource. + * + * @internal + */ +export interface ResourceContents { + /** + * The URI of this resource. + * + * @format uri + */ + uri: string; + /** + * The MIME type of this resource, if known. + */ + mimeType?: string; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * @category Content + */ +export interface TextResourceContents extends ResourceContents { + /** + * The text of the item. This must only be set if the item can actually be represented as text (not binary data). + */ + text: string; +} +/** + * @category Content + */ +export interface BlobResourceContents extends ResourceContents { + /** + * A base64-encoded string representing the binary data of the item. + * + * @format byte + */ + blob: string; +} +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + * + * @category `prompts/list` + */ +export interface ListPromptsRequest extends PaginatedRequest { + method: "prompts/list"; +} +/** + * The server's response to a prompts/list request from the client. + * + * @category `prompts/list` + */ +export interface ListPromptsResult extends PaginatedResult { + prompts: Prompt[]; +} +/** + * Parameters for a `prompts/get` request. + * + * @category `prompts/get` + */ +export interface GetPromptRequestParams extends RequestParams { + /** + * The name of the prompt or prompt template. + */ + name: string; + /** + * Arguments to use for templating the prompt. + */ + arguments?: { + [key: string]: string; + }; +} +/** + * Used by the client to get a prompt provided by the server. + * + * @category `prompts/get` + */ +export interface GetPromptRequest extends JSONRPCRequest { + method: "prompts/get"; + params: GetPromptRequestParams; +} +/** + * The server's response to a prompts/get request from the client. + * + * @category `prompts/get` + */ +export interface GetPromptResult extends Result { + /** + * An optional description for the prompt. + */ + description?: string; + messages: PromptMessage[]; +} +/** + * A prompt or prompt template that the server offers. + * + * @category `prompts/list` + */ +export interface Prompt extends BaseMetadata, Icons { + /** + * An optional description of what this prompt provides + */ + description?: string; + /** + * A list of arguments to use for templating the prompt. + */ + arguments?: PromptArgument[]; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Describes an argument that a prompt can accept. + * + * @category `prompts/list` + */ +export interface PromptArgument extends BaseMetadata { + /** + * A human-readable description of the argument. + */ + description?: string; + /** + * Whether this argument must be provided. + */ + required?: boolean; +} +/** + * The sender or recipient of messages and data in a conversation. + * + * @category Common Types + */ +export type Role = "user" | "assistant"; +/** + * Describes a message returned as part of a prompt. + * + * This is similar to `SamplingMessage`, but also supports the embedding of + * resources from the MCP server. + * + * @category `prompts/get` + */ +export interface PromptMessage { + role: Role; + content: ContentBlock; +} +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + * + * @category Content + */ +export interface ResourceLink extends Resource { + type: "resource_link"; +} +/** + * The contents of a resource, embedded into a prompt or tool call result. + * + * It is up to the client how best to render embedded resources for the benefit + * of the LLM and/or the user. + * + * @category Content + */ +export interface EmbeddedResource { + type: "resource"; + resource: TextResourceContents | BlobResourceContents; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/prompts/list_changed` + */ +export interface PromptListChangedNotification extends JSONRPCNotification { + method: "notifications/prompts/list_changed"; + params?: NotificationParams; +} +/** + * Sent from the client to request a list of tools the server has. + * + * @category `tools/list` + */ +export interface ListToolsRequest extends PaginatedRequest { + method: "tools/list"; +} +/** + * The server's response to a tools/list request from the client. + * + * @category `tools/list` + */ +export interface ListToolsResult extends PaginatedResult { + tools: Tool[]; +} +/** + * The server's response to a tool call. + * + * @category `tools/call` + */ +export interface CallToolResult extends Result { + /** + * A list of content objects that represent the unstructured result of the tool call. + */ + content: ContentBlock[]; + /** + * An optional JSON object that represents the structured result of the tool call. + */ + structuredContent?: { + [key: string]: unknown; + }; + /** + * Whether the tool call ended in an error. + * + * If not set, this is assumed to be false (the call was successful). + * + * Any errors that originate from the tool SHOULD be reported inside the result + * object, with `isError` set to true, _not_ as an MCP protocol-level error + * response. Otherwise, the LLM would not be able to see that an error occurred + * and self-correct. + * + * However, any errors in _finding_ the tool, an error indicating that the + * server does not support tool calls, or any other exceptional conditions, + * should be reported as an MCP error response. + */ + isError?: boolean; +} +/** + * Parameters for a `tools/call` request. + * + * @category `tools/call` + */ +export interface CallToolRequestParams extends RequestParams { + /** + * The name of the tool. + */ + name: string; + /** + * Arguments to use for the tool call. + */ + arguments?: { + [key: string]: unknown; + }; +} +/** + * Used by the client to invoke a tool provided by the server. + * + * @category `tools/call` + */ +export interface CallToolRequest extends JSONRPCRequest { + method: "tools/call"; + params: CallToolRequestParams; +} +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + * + * @category `notifications/tools/list_changed` + */ +export interface ToolListChangedNotification extends JSONRPCNotification { + method: "notifications/tools/list_changed"; + params?: NotificationParams; +} +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + * + * @category `tools/list` + */ +export interface ToolAnnotations { + /** + * A human-readable title for the tool. + */ + title?: string; + /** + * If true, the tool does not modify its environment. + * + * Default: false + */ + readOnlyHint?: boolean; + /** + * If true, the tool may perform destructive updates to its environment. + * If false, the tool performs only additive updates. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: true + */ + destructiveHint?: boolean; + /** + * If true, calling the tool repeatedly with the same arguments + * will have no additional effect on its environment. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: false + */ + idempotentHint?: boolean; + /** + * If true, this tool may interact with an "open world" of external + * entities. If false, the tool's domain of interaction is closed. + * For example, the world of a web search tool is open, whereas that + * of a memory tool is not. + * + * Default: true + */ + openWorldHint?: boolean; +} +/** + * Definition for a tool the client can call. + * + * @category `tools/list` + */ +export interface Tool extends BaseMetadata, Icons { + /** + * A human-readable description of the tool. + * + * This can be used by clients to improve the LLM's understanding of available tools. It can be thought of like a "hint" to the model. + */ + description?: string; + /** + * A JSON Schema object defining the expected parameters for the tool. + */ + inputSchema: { + type: "object"; + properties?: { + [key: string]: object; + }; + required?: string[]; + }; + /** + * An optional JSON Schema object defining the structure of the tool's output returned in + * the structuredContent field of a CallToolResult. + */ + outputSchema?: { + type: "object"; + properties?: { + [key: string]: object; + }; + required?: string[]; + }; + /** + * Optional additional tool information. + * + * Display name precedence order is: title, annotations.title, then name. + */ + annotations?: ToolAnnotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Parameters for a `logging/setLevel` request. + * + * @category `logging/setLevel` + */ +export interface SetLevelRequestParams extends RequestParams { + /** + * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message. + */ + level: LoggingLevel; +} +/** + * A request from the client to the server, to enable or adjust logging. + * + * @category `logging/setLevel` + */ +export interface SetLevelRequest extends JSONRPCRequest { + method: "logging/setLevel"; + params: SetLevelRequestParams; +} +/** + * Parameters for a `notifications/message` notification. + * + * @category `notifications/message` + */ +export interface LoggingMessageNotificationParams extends NotificationParams { + /** + * The severity of this log message. + */ + level: LoggingLevel; + /** + * An optional name of the logger issuing this message. + */ + logger?: string; + /** + * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. + */ + data: unknown; +} +/** + * JSONRPCNotification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + * + * @category `notifications/message` + */ +export interface LoggingMessageNotification extends JSONRPCNotification { + method: "notifications/message"; + params: LoggingMessageNotificationParams; +} +/** + * The severity of a log message. + * + * These map to syslog message severities, as specified in RFC-5424: + * https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1 + * + * @category Common Types + */ +export type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"; +/** + * Parameters for a `sampling/createMessage` request. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageRequestParams extends RequestParams { + messages: SamplingMessage[]; + /** + * The server's preferences for which model to select. The client MAY ignore these preferences. + */ + modelPreferences?: ModelPreferences; + /** + * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt. + */ + systemPrompt?: string; + /** + * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. + * The client MAY ignore this request. + * + * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client + * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases. + */ + includeContext?: "none" | "thisServer" | "allServers"; + /** + * @TJS-type number + */ + temperature?: number; + /** + * The requested maximum number of tokens to sample (to prevent runaway completions). + * + * The client MAY choose to sample fewer tokens than the requested maximum. + */ + maxTokens: number; + stopSequences?: string[]; + /** + * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific. + */ + metadata?: object; + /** + * Tools that the model may use during generation. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + */ + tools?: Tool[]; + /** + * Controls how the model uses tools. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + * Default is `{ mode: "auto" }`. + */ + toolChoice?: ToolChoice; +} +/** + * Controls tool selection behavior for sampling requests. + * + * @category `sampling/createMessage` + */ +export interface ToolChoice { + /** + * Controls the tool use ability of the model: + * - "auto": Model decides whether to use tools (default) + * - "required": Model MUST use at least one tool before completing + * - "none": Model MUST NOT use any tools + */ + mode?: "auto" | "required" | "none"; +} +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageRequest extends JSONRPCRequest { + method: "sampling/createMessage"; + params: CreateMessageRequestParams; +} +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + * + * @category `sampling/createMessage` + */ +export interface CreateMessageResult extends Result, SamplingMessage { + /** + * The name of the model that generated the message. + */ + model: string; + /** + * The reason why sampling stopped, if known. + * + * Standard values: + * - "endTurn": Natural end of the assistant's turn + * - "stopSequence": A stop sequence was encountered + * - "maxTokens": Maximum token limit was reached + * - "toolUse": The model wants to use one or more tools + * + * This field is an open string to allow for provider-specific stop reasons. + */ + stopReason?: "endTurn" | "stopSequence" | "maxTokens" | "toolUse" | string; +} +/** + * Describes a message issued to or received from an LLM API. + * + * @category `sampling/createMessage` + */ +export interface SamplingMessage { + role: Role; + content: SamplingMessageContentBlock | SamplingMessageContentBlock[]; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +export type SamplingMessageContentBlock = TextContent | ImageContent | AudioContent | ToolUseContent | ToolResultContent; +/** + * Optional annotations for the client. The client can use annotations to inform how objects are used or displayed + * + * @category Common Types + */ +export interface Annotations { + /** + * Describes who the intended audience of this object or data is. + * + * It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`). + */ + audience?: Role[]; + /** + * Describes how important this data is for operating the server. + * + * A value of 1 means "most important," and indicates that the data is + * effectively required, while 0 means "least important," and indicates that + * the data is entirely optional. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + priority?: number; + /** + * The moment the resource was last modified, as an ISO 8601 formatted string. + * + * Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z"). + * + * Examples: last activity timestamp in an open file, timestamp when the resource + * was attached, etc. + */ + lastModified?: string; +} +/** + * @category Content + */ +export type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource; +/** + * Text provided to or from an LLM. + * + * @category Content + */ +export interface TextContent { + type: "text"; + /** + * The text content of the message. + */ + text: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * An image provided to or from an LLM. + * + * @category Content + */ +export interface ImageContent { + type: "image"; + /** + * The base64-encoded image data. + * + * @format byte + */ + data: string; + /** + * The MIME type of the image. Different providers may support different image types. + */ + mimeType: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * Audio provided to or from an LLM. + * + * @category Content + */ +export interface AudioContent { + type: "audio"; + /** + * The base64-encoded audio data. + * + * @format byte + */ + data: string; + /** + * The MIME type of the audio. Different providers may support different audio types. + */ + mimeType: string; + /** + * Optional annotations for the client. + */ + annotations?: Annotations; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A request from the assistant to call a tool. + * + * @category `sampling/createMessage` + */ +export interface ToolUseContent { + type: "tool_use"; + /** + * A unique identifier for this tool use. + * + * This ID is used to match tool results to their corresponding tool uses. + */ + id: string; + /** + * The name of the tool to call. + */ + name: string; + /** + * The arguments to pass to the tool, conforming to the tool's input schema. + */ + input: { + [key: string]: unknown; + }; + /** + * Optional metadata about the tool use. Clients SHOULD preserve this field when + * including tool uses in subsequent sampling requests to enable caching optimizations. + * + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The result of a tool use, provided by the user back to the assistant. + * + * @category `sampling/createMessage` + */ +export interface ToolResultContent { + type: "tool_result"; + /** + * The ID of the tool use this result corresponds to. + * + * This MUST match the ID from a previous ToolUseContent. + */ + toolUseId: string; + /** + * The unstructured result content of the tool use. + * + * This has the same format as CallToolResult.content and can include text, images, + * audio, resource links, and embedded resources. + */ + content: ContentBlock[]; + /** + * An optional structured result object. + * + * If the tool defined an outputSchema, this SHOULD conform to that schema. + */ + structuredContent?: { + [key: string]: unknown; + }; + /** + * Whether the tool use resulted in an error. + * + * If true, the content typically describes the error that occurred. + * Default: false + */ + isError?: boolean; + /** + * Optional metadata about the tool result. Clients SHOULD preserve this field when + * including tool results in subsequent sampling requests to enable caching optimizations. + * + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * The server's preferences for model selection, requested of the client during sampling. + * + * Because LLMs can vary along multiple dimensions, choosing the "best" model is + * rarely straightforward. Different models excel in different areas—some are + * faster but less capable, others are more capable but more expensive, and so + * on. This interface allows servers to express their priorities across multiple + * dimensions to help clients make an appropriate selection for their use case. + * + * These preferences are always advisory. The client MAY ignore them. It is also + * up to the client to decide how to interpret these preferences and how to + * balance them against other considerations. + * + * @category `sampling/createMessage` + */ +export interface ModelPreferences { + /** + * Optional hints to use for model selection. + * + * If multiple hints are specified, the client MUST evaluate them in order + * (such that the first match is taken). + * + * The client SHOULD prioritize these hints over the numeric priorities, but + * MAY still use the priorities to select from ambiguous matches. + */ + hints?: ModelHint[]; + /** + * How much to prioritize cost when selecting a model. A value of 0 means cost + * is not important, while a value of 1 means cost is the most important + * factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + costPriority?: number; + /** + * How much to prioritize sampling speed (latency) when selecting a model. A + * value of 0 means speed is not important, while a value of 1 means speed is + * the most important factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + speedPriority?: number; + /** + * How much to prioritize intelligence and capabilities when selecting a + * model. A value of 0 means intelligence is not important, while a value of 1 + * means intelligence is the most important factor. + * + * @TJS-type number + * @minimum 0 + * @maximum 1 + */ + intelligencePriority?: number; +} +/** + * Hints to use for model selection. + * + * Keys not declared here are currently left unspecified by the spec and are up + * to the client to interpret. + * + * @category `sampling/createMessage` + */ +export interface ModelHint { + /** + * A hint for a model name. + * + * The client SHOULD treat this as a substring of a model name; for example: + * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` + * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. + * - `claude` should match any Claude model + * + * The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: + * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` + */ + name?: string; +} +/** + * Parameters for a `completion/complete` request. + * + * @category `completion/complete` + */ +export interface CompleteRequestParams extends RequestParams { + ref: PromptReference | ResourceTemplateReference; + /** + * The argument's information + */ + argument: { + /** + * The name of the argument + */ + name: string; + /** + * The value of the argument to use for completion matching. + */ + value: string; + }; + /** + * Additional, optional context for completions + */ + context?: { + /** + * Previously-resolved variables in a URI template or prompt. + */ + arguments?: { + [key: string]: string; + }; + }; +} +/** + * A request from the client to the server, to ask for completion options. + * + * @category `completion/complete` + */ +export interface CompleteRequest extends JSONRPCRequest { + method: "completion/complete"; + params: CompleteRequestParams; +} +/** + * The server's response to a completion/complete request + * + * @category `completion/complete` + */ +export interface CompleteResult extends Result { + completion: { + /** + * An array of completion values. Must not exceed 100 items. + */ + values: string[]; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total?: number; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore?: boolean; + }; +} +/** + * A reference to a resource or resource template definition. + * + * @category `completion/complete` + */ +export interface ResourceTemplateReference { + type: "ref/resource"; + /** + * The URI or URI template of the resource. + * + * @format uri-template + */ + uri: string; +} +/** + * Identifies a prompt. + * + * @category `completion/complete` + */ +export interface PromptReference extends BaseMetadata { + type: "ref/prompt"; +} +/** + * Sent from the server to request a list of root URIs from the client. Roots allow + * servers to ask for specific directories or files to operate on. A common example + * for roots is providing a set of repositories or directories a server should operate + * on. + * + * This request is typically used when the server needs to understand the file system + * structure or access specific locations that the client has permission to read from. + * + * @category `roots/list` + */ +export interface ListRootsRequest extends JSONRPCRequest { + method: "roots/list"; + params?: RequestParams; +} +/** + * The client's response to a roots/list request from the server. + * This result contains an array of Root objects, each representing a root directory + * or file that the server can operate on. + * + * @category `roots/list` + */ +export interface ListRootsResult extends Result { + roots: Root[]; +} +/** + * Represents a root directory or file that the server can operate on. + * + * @category `roots/list` + */ +export interface Root { + /** + * The URI identifying the root. This *must* start with file:// for now. + * This restriction may be relaxed in future versions of the protocol to allow + * other URI schemes. + * + * @format uri + */ + uri: string; + /** + * An optional name for the root. This can be used to provide a human-readable + * identifier for the root, which may be useful for display purposes or for + * referencing the root in other parts of the application. + */ + name?: string; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta?: { + [key: string]: unknown; + }; +} +/** + * A notification from the client to the server, informing it that the list of roots has changed. + * This notification should be sent whenever the client adds, removes, or modifies any root. + * The server should then request an updated list of roots using the ListRootsRequest. + * + * @category `notifications/roots/list_changed` + */ +export interface RootsListChangedNotification extends JSONRPCNotification { + method: "notifications/roots/list_changed"; + params?: NotificationParams; +} +/** + * The parameters for a request to elicit non-sensitive information from the user via a form in the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequestFormParams extends RequestParams { + /** + * The elicitation mode. + */ + mode?: "form"; + /** + * The message to present to the user describing what information is being requested. + */ + message: string; + /** + * A restricted subset of JSON Schema. + * Only top-level properties are allowed, without nesting. + */ + requestedSchema: { + $schema?: string; + type: "object"; + properties: { + [key: string]: PrimitiveSchemaDefinition; + }; + required?: string[]; + }; +} +/** + * The parameters for a request to elicit information from the user via a URL in the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequestURLParams extends RequestParams { + /** + * The elicitation mode. + */ + mode: "url"; + /** + * The message to present to the user explaining why the interaction is needed. + */ + message: string; + /** + * The ID of the elicitation, which must be unique within the context of the server. + * The client MUST treat this ID as an opaque value. + */ + elicitationId: string; + /** + * The URL that the user should navigate to. + * + * @format uri + */ + url: string; +} +/** + * The parameters for a request to elicit additional information from the user via the client. + * + * @category `elicitation/create` + */ +export type ElicitRequestParams = ElicitRequestFormParams | ElicitRequestURLParams; +/** + * A request from the server to elicit additional information from the user via the client. + * + * @category `elicitation/create` + */ +export interface ElicitRequest extends JSONRPCRequest { + method: "elicitation/create"; + params: ElicitRequestParams; +} +/** + * Restricted schema definitions that only allow primitive types + * without nested objects or arrays. + * + * @category `elicitation/create` + */ +export type PrimitiveSchemaDefinition = StringSchema | NumberSchema | BooleanSchema | EnumSchema; +/** + * @category `elicitation/create` + */ +export interface StringSchema { + type: "string"; + title?: string; + description?: string; + minLength?: number; + maxLength?: number; + format?: "email" | "uri" | "date" | "date-time"; + default?: string; +} +/** + * @category `elicitation/create` + */ +export interface NumberSchema { + type: "number" | "integer"; + title?: string; + description?: string; + minimum?: number; + maximum?: number; + default?: number; +} +/** + * @category `elicitation/create` + */ +export interface BooleanSchema { + type: "boolean"; + title?: string; + description?: string; + default?: boolean; +} +/** + * Schema for single-selection enumeration without display titles for options. + * + * @category `elicitation/create` + */ +export interface UntitledSingleSelectEnumSchema { + type: "string"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Array of enum values to choose from. + */ + enum: string[]; + /** + * Optional default value. + */ + default?: string; +} +/** + * Schema for single-selection enumeration with display titles for each option. + * + * @category `elicitation/create` + */ +export interface TitledSingleSelectEnumSchema { + type: "string"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Array of enum options with values and display labels. + */ + oneOf: Array<{ + /** + * The enum value. + */ + const: string; + /** + * Display label for this option. + */ + title: string; + }>; + /** + * Optional default value. + */ + default?: string; +} +/** + * @category `elicitation/create` + */ +export type SingleSelectEnumSchema = UntitledSingleSelectEnumSchema | TitledSingleSelectEnumSchema; +/** + * Schema for multiple-selection enumeration without display titles for options. + * + * @category `elicitation/create` + */ +export interface UntitledMultiSelectEnumSchema { + type: "array"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Minimum number of items to select. + */ + minItems?: number; + /** + * Maximum number of items to select. + */ + maxItems?: number; + /** + * Schema for the array items. + */ + items: { + type: "string"; + /** + * Array of enum values to choose from. + */ + enum: string[]; + }; + /** + * Optional default value. + */ + default?: string[]; +} +/** + * Schema for multiple-selection enumeration with display titles for each option. + * + * @category `elicitation/create` + */ +export interface TitledMultiSelectEnumSchema { + type: "array"; + /** + * Optional title for the enum field. + */ + title?: string; + /** + * Optional description for the enum field. + */ + description?: string; + /** + * Minimum number of items to select. + */ + minItems?: number; + /** + * Maximum number of items to select. + */ + maxItems?: number; + /** + * Schema for array items with enum options and display labels. + */ + items: { + /** + * Array of enum options with values and display labels. + */ + anyOf: Array<{ + /** + * The constant enum value. + */ + const: string; + /** + * Display title for this option. + */ + title: string; + }>; + }; + /** + * Optional default value. + */ + default?: string[]; +} +/** + * @category `elicitation/create` + */ +export type MultiSelectEnumSchema = UntitledMultiSelectEnumSchema | TitledMultiSelectEnumSchema; +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + * + * @category `elicitation/create` + */ +export interface LegacyTitledEnumSchema { + type: "string"; + title?: string; + description?: string; + enum: string[]; + /** + * (Legacy) Display names for enum values. + * Non-standard according to JSON schema 2020-12. + */ + enumNames?: string[]; + default?: string; +} +/** + * @category `elicitation/create` + */ +export type EnumSchema = SingleSelectEnumSchema | MultiSelectEnumSchema | LegacyTitledEnumSchema; +/** + * The client's response to an elicitation request. + * + * @category `elicitation/create` + */ +export interface ElicitResult extends Result { + /** + * The user action in response to the elicitation. + * - "accept": User submitted the form/confirmed the action + * - "decline": User explicitly decline the action + * - "cancel": User dismissed without making an explicit choice + */ + action: "accept" | "decline" | "cancel"; + /** + * The submitted form data, only present when action is "accept" and mode was "form". + * Contains values matching the requested schema. + * Omitted for out-of-band mode responses. + */ + content?: { + [key: string]: string | number | boolean | string[]; + }; +} +/** + * An optional notification from the server to the client, informing it of a completion of a out-of-band elicitation request. + * + * @category `notifications/elicitation/complete` + */ +export interface ElicitationCompleteNotification extends JSONRPCNotification { + method: "notifications/elicitation/complete"; + params: { + /** + * The ID of the elicitation that completed. + */ + elicitationId: string; + }; +} +/** @internal */ +export type ClientRequest = PingRequest | InitializeRequest | CompleteRequest | SetLevelRequest | GetPromptRequest | ListPromptsRequest | ListResourcesRequest | ListResourceTemplatesRequest | ReadResourceRequest | SubscribeRequest | UnsubscribeRequest | CallToolRequest | ListToolsRequest; +/** @internal */ +export type ClientNotification = CancelledNotification | ProgressNotification | InitializedNotification | RootsListChangedNotification; +/** @internal */ +export type ClientResult = EmptyResult | CreateMessageResult | ListRootsResult | ElicitResult; +/** @internal */ +export type ServerRequest = PingRequest | CreateMessageRequest | ListRootsRequest | ElicitRequest; +/** @internal */ +export type ServerNotification = CancelledNotification | ProgressNotification | LoggingMessageNotification | ResourceUpdatedNotification | ResourceListChangedNotification | ToolListChangedNotification | PromptListChangedNotification | ElicitationCompleteNotification; +/** @internal */ +export type ServerResult = EmptyResult | InitializeResult | CompleteResult | GetPromptResult | ListPromptsResult | ListResourceTemplatesResult | ListResourcesResult | ReadResourceResult | CallToolResult | ListToolsResult; +//# sourceMappingURL=spec.types.d.ts.map \ No newline at end of file diff --git a/dist/esm/spec.types.d.ts.map b/dist/esm/spec.types.d.ts.map new file mode 100644 index 000000000..9ba480f8b --- /dev/null +++ b/dist/esm/spec.types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"spec.types.d.ts","sourceRoot":"","sources":["../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,GACf,iBAAiB,GACjB,2BAA2B,GAC3B,mBAAmB,GACnB,kBAAkB,GAClB,cAAc,GACd,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/spec.types.js b/dist/esm/spec.types.js new file mode 100644 index 000000000..5dea46dbf --- /dev/null +++ b/dist/esm/spec.types.js @@ -0,0 +1,24 @@ +/** + * This file is automatically generated from the Model Context Protocol specification. + * + * Source: https://github.com/modelcontextprotocol/modelcontextprotocol + * Pulled from: https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/draft/schema.ts + * Last updated from commit: 7dcdd69262bd488ddec071bf4eefedabf1742023 + * + * DO NOT EDIT THIS FILE MANUALLY. Changes will be overwritten by automated updates. + * To update this file, run: npm run fetch:spec-types + */ /* JSON-RPC types */ +/** @internal */ +export const LATEST_PROTOCOL_VERSION = "DRAFT-2025-v3"; +/** @internal */ +export const JSONRPC_VERSION = "2.0"; +// Standard JSON-RPC error codes +export const PARSE_ERROR = -32700; +export const INVALID_REQUEST = -32600; +export const METHOD_NOT_FOUND = -32601; +export const INVALID_PARAMS = -32602; +export const INTERNAL_ERROR = -32603; +// Implementation-specific JSON-RPC error codes [-32000, -32099] +/** @internal */ +export const URL_ELICITATION_REQUIRED = -32042; +//# sourceMappingURL=spec.types.js.map \ No newline at end of file diff --git a/dist/esm/spec.types.js.map b/dist/esm/spec.types.js.map new file mode 100644 index 000000000..d2c9dd0aa --- /dev/null +++ b/dist/esm/spec.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"spec.types.js","sourceRoot":"","sources":["../../src/spec.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG,CAAA,oBAAoB;AAavB,gBAAgB;AAChB,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,gBAAgB;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AA4HrC,gCAAgC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AAErC,gEAAgE;AAChE,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAK,CAAC"} \ No newline at end of file diff --git a/dist/esm/types.d.ts b/dist/esm/types.d.ts new file mode 100644 index 000000000..d99bfe596 --- /dev/null +++ b/dist/esm/types.d.ts @@ -0,0 +1,6508 @@ +import * as z from 'zod/v4'; +import { AuthInfo } from './server/auth/types.js'; +export declare const LATEST_PROTOCOL_VERSION = "2025-06-18"; +export declare const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26"; +export declare const SUPPORTED_PROTOCOL_VERSIONS: string[]; +export declare const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task"; +export declare const JSONRPC_VERSION = "2.0"; +/** + * Utility types + */ +type ExpandRecursively = T extends object ? (T extends infer O ? { + [K in keyof O]: ExpandRecursively; +} : never) : T; +/** + * A progress token, used to associate progress notifications with the original request. + */ +export declare const ProgressTokenSchema: z.ZodUnion; +/** + * An opaque token used to represent a cursor for pagination. + */ +export declare const CursorSchema: z.ZodString; +/** + * Task creation parameters, used to ask that the server create a task to represent a request. + */ +export declare const TaskCreationParamsSchema: z.ZodObject<{ + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; +}, z.core.$loose>; +/** + * Task association metadata, used to signal which task a message originated from. + */ +export declare const RelatedTaskMetadataSchema: z.ZodObject<{ + taskId: z.ZodString; +}, z.core.$loose>; +declare const RequestMetaSchema: z.ZodObject<{ + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; +}, z.core.$loose>; +/** + * Common params for any request. + */ +declare const BaseRequestParamsSchema: z.ZodObject<{ + /** + * If specified, the caller is requesting that the receiver create a task to represent the request. + * Task creation parameters are now at the top level instead of in _meta. + */ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +export declare const RequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +declare const NotificationsParamsSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +export declare const NotificationSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const ResultSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * A uniquely identifying ID for a request in JSON-RPC. + */ +export declare const RequestIdSchema: z.ZodUnion; +/** + * A request that expects a response. + */ +export declare const JSONRPCRequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; +}, z.core.$strict>; +export declare const isJSONRPCRequest: (value: unknown) => value is JSONRPCRequest; +/** + * A notification which does not expect a response. + */ +export declare const JSONRPCNotificationSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; +}, z.core.$strict>; +export declare const isJSONRPCNotification: (value: unknown) => value is JSONRPCNotification; +/** + * A successful (non-error) response to a request. + */ +export declare const JSONRPCResponseSchema: z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + result: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>; +}, z.core.$strict>; +export declare const isJSONRPCResponse: (value: unknown) => value is JSONRPCResponse; +/** + * Error codes defined by the JSON-RPC specification. + */ +export declare enum ErrorCode { + ConnectionClosed = -32000, + RequestTimeout = -32001, + ParseError = -32700, + InvalidRequest = -32600, + MethodNotFound = -32601, + InvalidParams = -32602, + InternalError = -32603, + UrlElicitationRequired = -32042 +} +/** + * A response to a request that indicates an error occurred. + */ +export declare const JSONRPCErrorSchema: z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + error: z.ZodObject<{ + code: z.ZodNumber; + message: z.ZodString; + data: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strict>; +export declare const isJSONRPCError: (value: unknown) => value is JSONRPCError; +export declare const JSONRPCMessageSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; +}, z.core.$strict>, z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + jsonrpc: z.ZodLiteral<"2.0">; +}, z.core.$strict>, z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + result: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>; +}, z.core.$strict>, z.ZodObject<{ + jsonrpc: z.ZodLiteral<"2.0">; + id: z.ZodUnion; + error: z.ZodObject<{ + code: z.ZodNumber; + message: z.ZodString; + data: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strict>]>; +/** + * A response that indicates success but carries no data. + */ +export declare const EmptyResultSchema: z.ZodObject<{ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$strict>; +export declare const CancelledNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; +}, z.core.$loose>; +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + */ +export declare const CancelledNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/cancelled">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Icon schema for use in tools, prompts, resources, and implementations. + */ +export declare const IconSchema: z.ZodObject<{ + src: z.ZodString; + mimeType: z.ZodOptional; + sizes: z.ZodOptional>; +}, z.core.$strip>; +/** + * Base schema to add `icons` property. + * + */ +export declare const IconsSchema: z.ZodObject<{ + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; +}, z.core.$strip>; +/** + * Base metadata interface for common properties across resources, tools, prompts, and implementations. + */ +export declare const BaseMetadataSchema: z.ZodObject<{ + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Describes the name and version of an MCP implementation. + */ +export declare const ImplementationSchema: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Task capabilities for clients, indicating which request types support task creation. + */ +export declare const ClientTasksCapabilitySchema: z.ZodObject<{ + list: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * Task capabilities for servers, indicating which request types support task creation. + */ +export declare const ServerTasksCapabilitySchema: z.ZodObject<{ + list: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + */ +export declare const ClientCapabilitiesSchema: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const InitializeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + */ +export declare const InitializeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"initialize">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + }, z.core.$loose>; +}, z.core.$strip>; +export declare const isInitializeRequest: (value: unknown) => value is InitializeRequest; +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + */ +export declare const ServerCapabilitiesSchema: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; +}, z.core.$loose>; +/** + * After receiving an initialize request from the client, the server sends this response. + */ +export declare const InitializeResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>; + serverInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + instructions: z.ZodOptional; +}, z.core.$loose>; +/** + * This notification is sent from the client to the server after initialization has finished. + */ +export declare const InitializedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/initialized">; +}, z.core.$strip>; +export declare const isInitializedNotification: (value: unknown) => value is InitializedNotification; +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + */ +export declare const PingRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>; +export declare const ProgressSchema: z.ZodObject<{ + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; +}, z.core.$strip>; +export declare const ProgressNotificationParamsSchema: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; +}, z.core.$strip>; +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category notifications/progress + */ +export declare const ProgressNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>; +export declare const PaginatedRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; +}, z.core.$loose>; +export declare const PaginatedRequestSchema: z.ZodObject<{ + method: z.ZodString; + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; +}, z.core.$strip>; +export declare const PaginatedResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; +}, z.core.$loose>; +/** + * A pollable state object associated with a request. + */ +export declare const TaskSchema: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * Result returned when a task is created, containing the task data wrapped in a task field. + */ +export declare const CreateTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * Parameters for task status notification. + */ +export declare const TaskStatusNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * A notification sent when a task's status changes. + */ +export declare const TaskStatusNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>; +/** + * A request to get the state of a specific task. + */ +export declare const GetTaskRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The response to a tasks/get request. + */ +export declare const GetTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * A request to get the result of a specific task. + */ +export declare const GetTaskPayloadRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * A request to list tasks. + */ +export declare const ListTasksRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>; +/** + * The response to a tasks/list request. + */ +export declare const ListTasksResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request to cancel a specific task. + */ +export declare const CancelTaskRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tasks/cancel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The response to a tasks/cancel request. + */ +export declare const CancelTaskResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>; +/** + * The contents of a specific resource or sub-resource. + */ +export declare const ResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$strip>; +export declare const TextResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + text: z.ZodString; +}, z.core.$strip>; +export declare const BlobResourceContentsSchema: z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; +}, z.core.$strip>; +/** + * A known resource that the server is capable of reading. + */ +export declare const ResourceSchema: z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * A template description for resources available on the server. + */ +export declare const ResourceTemplateSchema: z.ZodObject<{ + uriTemplate: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of resources the server has. + */ +export declare const ListResourcesRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/list">; +}, z.core.$strip>; +/** + * The server's response to a resources/list request from the client. + */ +export declare const ListResourcesResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resources: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * Sent from the client to request a list of resource templates the server has. + */ +export declare const ListResourceTemplatesRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/templates/list">; +}, z.core.$strip>; +/** + * The server's response to a resources/templates/list request from the client. + */ +export declare const ListResourceTemplatesResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resourceTemplates: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +export declare const ResourceRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Parameters for a `resources/read` request. + */ +export declare const ReadResourceRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to the server, to read a specific resource URI. + */ +export declare const ReadResourceRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/read">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The server's response to a resources/read request from the client. + */ +export declare const ReadResourceResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + contents: z.ZodArray; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>>; +}, z.core.$loose>; +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const ResourceListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/resources/list_changed">; +}, z.core.$strip>; +export declare const SubscribeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + */ +export declare const SubscribeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/subscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +export declare const UnsubscribeRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + */ +export declare const UnsubscribeRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"resources/unsubscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/resources/updated` notification. + */ +export declare const ResourceUpdatedNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; +}, z.core.$loose>; +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + */ +export declare const ResourceUpdatedNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/resources/updated">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Describes an argument that a prompt can accept. + */ +export declare const PromptArgumentSchema: z.ZodObject<{ + name: z.ZodString; + description: z.ZodOptional; + required: z.ZodOptional; +}, z.core.$strip>; +/** + * A prompt or prompt template that the server offers. + */ +export declare const PromptSchema: z.ZodObject<{ + description: z.ZodOptional; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + */ +export declare const ListPromptsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"prompts/list">; +}, z.core.$strip>; +/** + * The server's response to a prompts/list request from the client. + */ +export declare const ListPromptsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + prompts: z.ZodArray; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * Parameters for a `prompts/get` request. + */ +export declare const GetPromptRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; +}, z.core.$loose>; +/** + * Used by the client to get a prompt provided by the server. + */ +export declare const GetPromptRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"prompts/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Text provided to or from an LLM. + */ +export declare const TextContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"text">; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * An image provided to or from an LLM. + */ +export declare const ImageContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * An Audio provided to or from an LLM. + */ +export declare const AudioContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * A tool call request from an assistant (LLM). + * Represents the assistant's request to use a tool. + */ +export declare const ToolUseContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * The contents of a resource, embedded into a prompt or tool call result. + */ +export declare const EmbeddedResourceSchema: z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + */ +export declare const ResourceLinkSchema: z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; +}, z.core.$strip>; +/** + * A content block that can be used in prompts and tool results. + */ +export declare const ContentBlockSchema: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; +}, z.core.$strip>]>; +/** + * Describes a message returned as part of a prompt. + */ +export declare const PromptMessageSchema: z.ZodObject<{ + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; +}, z.core.$strip>; +/** + * The server's response to a prompts/get request from the client. + */ +export declare const GetPromptResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + description: z.ZodOptional; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const PromptListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/prompts/list_changed">; +}, z.core.$strip>; +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + */ +export declare const ToolAnnotationsSchema: z.ZodObject<{ + title: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; +}, z.core.$strip>; +/** + * Execution-related properties for a tool. + */ +export declare const ToolExecutionSchema: z.ZodObject<{ + taskSupport: z.ZodOptional>; +}, z.core.$strip>; +/** + * Definition for a tool the client can call. + */ +export declare const ToolSchema: z.ZodObject<{ + description: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; +}, z.core.$strip>; +/** + * Sent from the client to request a list of tools the server has. + */ +export declare const ListToolsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tools/list">; +}, z.core.$strip>; +/** + * The server's response to a tools/list request from the client. + */ +export declare const ListToolsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tools: z.ZodArray; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * The server's response to a tool call. + */ +export declare const CallToolResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>; +/** + * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. + */ +export declare const CompatibilityCallToolResultSchema: z.ZodUnion<[z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + toolResult: z.ZodUnknown; +}, z.core.$loose>]>; +/** + * Parameters for a `tools/call` request. + */ +export declare const CallToolRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; +}, z.core.$loose>; +/** + * Used by the client to invoke a tool provided by the server. + */ +export declare const CallToolRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"tools/call">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export declare const ToolListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/tools/list_changed">; +}, z.core.$strip>; +/** + * The severity of a log message. + */ +export declare const LoggingLevelSchema: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; +}>; +/** + * Parameters for a `logging/setLevel` request. + */ +export declare const SetLevelRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; +}, z.core.$loose>; +/** + * A request from the client to the server, to enable or adjust logging. + */ +export declare const SetLevelRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"logging/setLevel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/message` notification. + */ +export declare const LoggingMessageNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; +}, z.core.$loose>; +/** + * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + */ +export declare const LoggingMessageNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/message">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * Hints to use for model selection. + */ +export declare const ModelHintSchema: z.ZodObject<{ + name: z.ZodOptional; +}, z.core.$strip>; +/** + * The server's preferences for model selection, requested of the client during sampling. + */ +export declare const ModelPreferencesSchema: z.ZodObject<{ + hints: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; +}, z.core.$strip>; +/** + * Controls tool usage behavior in sampling requests. + */ +export declare const ToolChoiceSchema: z.ZodObject<{ + mode: z.ZodOptional>; +}, z.core.$strip>; +/** + * The result of a tool execution, provided by the user (server). + * Represents the outcome of invoking a tool requested via ToolUseContent. + */ +export declare const ToolResultContentSchema: z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * Content block types allowed in sampling messages. + * This includes text, image, audio, tool use requests, and tool results. + */ +export declare const SamplingMessageContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ + type: z.ZodLiteral<"text">; + text: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; +}, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$loose>]>; +/** + * Describes a message issued to or received from an LLM API. + */ +export declare const SamplingMessageSchema: z.ZodObject<{ + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; +}, z.core.$loose>; +/** + * Parameters for a `sampling/createMessage` request. + */ +export declare const CreateMessageRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + */ +export declare const CreateMessageRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"sampling/createMessage">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + */ +export declare const CreateMessageResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + model: z.ZodString; + stopReason: z.ZodOptional, z.ZodString]>>; + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; +}, z.core.$loose>; +/** + * Primitive schema definition for boolean fields. + */ +export declare const BooleanSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Primitive schema definition for string fields. + */ +export declare const StringSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Primitive schema definition for number fields. + */ +export declare const NumberSchemaSchema: z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Schema for single-selection enumeration without display titles for options. + */ +export declare const UntitledSingleSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Schema for single-selection enumeration with display titles for each option. + */ +export declare const TitledSingleSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>; +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + */ +export declare const LegacyTitledEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>; +export declare const SingleSelectEnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>; +/** + * Schema for multiple-selection enumeration without display titles for options. + */ +export declare const UntitledMultiSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>; +/** + * Schema for multiple-selection enumeration with display titles for each option. + */ +export declare const TitledMultiSelectEnumSchemaSchema: z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>; +/** + * Combined schema for multiple-selection enumeration + */ +export declare const MultiSelectEnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>; +/** + * Primitive schema definition for enum fields. + */ +export declare const EnumSchemaSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>]>; +/** + * Union of all primitive schema definitions. + */ +export declare const PrimitiveSchemaDefinitionSchema: z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; +}, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; +}, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; +}, z.core.$strip>]>; +/** + * Parameters for an `elicitation/create` request for form-based elicitation. + */ +export declare const ElicitRequestFormParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; +}, z.core.$loose>; +/** + * Parameters for an `elicitation/create` request for URL-based elicitation. + */ +export declare const ElicitRequestURLParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; +}, z.core.$loose>; +/** + * The parameters for a request to elicit additional information from the user via the client. + */ +export declare const ElicitRequestParamsSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; +}, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; +}, z.core.$loose>]>; +/** + * A request from the server to elicit user input via the client. + * The client should present the message and form fields to the user (form mode) + * or navigate to a URL (URL mode). + */ +export declare const ElicitRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"elicitation/create">; + params: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; + }, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; + }, z.core.$loose>]>; +}, z.core.$strip>; +/** + * Parameters for a `notifications/elicitation/complete` notification. + * + * @category notifications/elicitation/complete + */ +export declare const ElicitationCompleteNotificationParamsSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; +}, z.core.$loose>; +/** + * A notification from the server to the client, informing it of a completion of an out-of-band elicitation request. + * + * @category notifications/elicitation/complete + */ +export declare const ElicitationCompleteNotificationSchema: z.ZodObject<{ + method: z.ZodLiteral<"notifications/elicitation/complete">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>; +/** + * The client's response to an elicitation/create request from the server. + */ +export declare const ElicitResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + action: z.ZodEnum<{ + cancel: "cancel"; + accept: "accept"; + decline: "decline"; + }>; + content: z.ZodOptional]>>>; +}, z.core.$loose>; +/** + * A reference to a resource or resource template definition. + */ +export declare const ResourceTemplateReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; +}, z.core.$strip>; +/** + * @deprecated Use ResourceTemplateReferenceSchema instead + */ +export declare const ResourceReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; +}, z.core.$strip>; +/** + * Identifies a prompt. + */ +export declare const PromptReferenceSchema: z.ZodObject<{ + type: z.ZodLiteral<"ref/prompt">; + name: z.ZodString; +}, z.core.$strip>; +/** + * Parameters for a `completion/complete` request. + */ +export declare const CompleteRequestParamsSchema: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A request from the client to the server, to ask for completion options. + */ +export declare const CompleteRequestSchema: z.ZodObject<{ + method: z.ZodLiteral<"completion/complete">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>; +export declare function assertCompleteRequestPrompt(request: CompleteRequest): asserts request is CompleteRequestPrompt; +export declare function assertCompleteRequestResourceTemplate(request: CompleteRequest): asserts request is CompleteRequestResourceTemplate; +/** + * The server's response to a completion/complete request + */ +export declare const CompleteResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + completion: z.ZodObject<{ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.ZodArray; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.ZodOptional; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$loose>; +/** + * Represents a root directory or file that the server can operate on. + */ +export declare const RootSchema: z.ZodObject<{ + uri: z.ZodString; + name: z.ZodOptional; + _meta: z.ZodOptional>; +}, z.core.$strip>; +/** + * Sent from the server to request a list of root URIs from the client. + */ +export declare const ListRootsRequestSchema: z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"roots/list">; +}, z.core.$strip>; +/** + * The client's response to a roots/list request from the server. + */ +export declare const ListRootsResultSchema: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + roots: z.ZodArray; + _meta: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>; +/** + * A notification from the client to the server, informing it that the list of roots has changed. + */ +export declare const RootsListChangedNotificationSchema: z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/roots/list_changed">; +}, z.core.$strip>; +export declare const ClientRequestSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"initialize">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + sampling: z.ZodOptional>; + tools: z.ZodOptional>; + }, z.core.$strip>>; + elicitation: z.ZodOptional, z.ZodIntersection; + }, z.core.$strip>, z.ZodRecord>>; + url: z.ZodOptional>; + }, z.core.$strip>, z.ZodOptional>>>>; + roots: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + elicitation: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$strip>; + clientInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"completion/complete">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + ref: z.ZodUnion; + name: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"ref/resource">; + uri: z.ZodString; + }, z.core.$strip>]>; + argument: z.ZodObject<{ + name: z.ZodString; + value: z.ZodString; + }, z.core.$strip>; + context: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"logging/setLevel">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"prompts/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"prompts/list">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/list">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"resources/templates/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/read">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/subscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"resources/unsubscribe">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tools/call">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + name: z.ZodString; + arguments: z.ZodOptional>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tools/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>]>; +export declare const ClientNotificationSchema: z.ZodUnion; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/initialized">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/roots/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>]>; +export declare const ClientResultSchema: z.ZodUnion>; + }, z.core.$loose>>; +}, z.core.$strict>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + model: z.ZodString; + stopReason: z.ZodOptional, z.ZodString]>>; + role: z.ZodEnum<{ + user: "user"; + assistant: "assistant"; + }>; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + action: z.ZodEnum<{ + cancel: "cancel"; + accept: "accept"; + decline: "decline"; + }>; + content: z.ZodOptional]>>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + roots: z.ZodArray; + _meta: z.ZodOptional>; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>]>; +export declare const ServerRequestSchema: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"ping">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"sampling/createMessage">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>, z.ZodArray; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"tool_use">; + name: z.ZodString; + id: z.ZodString; + input: z.ZodObject<{}, z.core.$loose>; + _meta: z.ZodOptional>; + }, z.core.$loose>, z.ZodObject<{ + type: z.ZodLiteral<"tool_result">; + toolUseId: z.ZodString; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>]>>]>; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + modelPreferences: z.ZodOptional; + }, z.core.$strip>>>; + costPriority: z.ZodOptional; + speedPriority: z.ZodOptional; + intelligencePriority: z.ZodOptional; + }, z.core.$strip>>; + systemPrompt: z.ZodOptional; + includeContext: z.ZodOptional>; + temperature: z.ZodOptional; + maxTokens: z.ZodNumber; + stopSequences: z.ZodOptional>; + metadata: z.ZodOptional>; + tools: z.ZodOptional; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>>; + toolChoice: z.ZodOptional>; + }, z.core.$strip>>; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"elicitation/create">; + params: z.ZodUnion>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodOptional>; + message: z.ZodString; + requestedSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodRecord; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + enumNames: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + enum: z.ZodArray; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + oneOf: z.ZodArray>; + default: z.ZodOptional; + }, z.core.$strip>]>, z.ZodUnion; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + type: z.ZodLiteral<"string">; + enum: z.ZodArray; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"array">; + title: z.ZodOptional; + description: z.ZodOptional; + minItems: z.ZodOptional; + maxItems: z.ZodOptional; + items: z.ZodObject<{ + anyOf: z.ZodArray>; + }, z.core.$strip>; + default: z.ZodOptional>; + }, z.core.$strip>]>]>, z.ZodObject<{ + type: z.ZodLiteral<"boolean">; + title: z.ZodOptional; + description: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"string">; + title: z.ZodOptional; + description: z.ZodOptional; + minLength: z.ZodOptional; + maxLength: z.ZodOptional; + format: z.ZodOptional>; + default: z.ZodOptional; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodEnum<{ + number: "number"; + integer: "integer"; + }>; + title: z.ZodOptional; + description: z.ZodOptional; + minimum: z.ZodOptional; + maximum: z.ZodOptional; + default: z.ZodOptional; + }, z.core.$strip>]>>; + required: z.ZodOptional>; + }, z.core.$strip>; + }, z.core.$loose>, z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + mode: z.ZodLiteral<"url">; + message: z.ZodString; + elicitationId: z.ZodString; + url: z.ZodString; + }, z.core.$loose>]>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"roots/list">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/get">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"tasks/result">; + params: z.ZodObject<{ + task: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.ZodOptional; + }, z.core.$loose>>; + _meta: z.ZodOptional>; + /** + * If specified, this request is related to the provided task. + */ + "io.modelcontextprotocol/related-task": z.ZodOptional>; + }, z.core.$loose>>; + cursor: z.ZodOptional; + }, z.core.$loose>>; + method: z.ZodLiteral<"tasks/list">; +}, z.core.$strip>]>; +export declare const ServerNotificationSchema: z.ZodUnion; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + requestId: z.ZodUnion; + reason: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/progress">; + params: z.ZodObject<{ + progressToken: z.ZodUnion; + progress: z.ZodNumber; + total: z.ZodOptional; + message: z.ZodOptional; + _meta: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/message">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + level: z.ZodEnum<{ + error: "error"; + debug: "debug"; + info: "info"; + notice: "notice"; + warning: "warning"; + critical: "critical"; + alert: "alert"; + emergency: "emergency"; + }>; + logger: z.ZodOptional; + data: z.ZodUnknown; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/resources/updated">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + uri: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/resources/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/tools/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + params: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + method: z.ZodLiteral<"notifications/prompts/list_changed">; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/tasks/status">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$strip>, z.ZodObject<{ + method: z.ZodLiteral<"notifications/elicitation/complete">; + params: z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + elicitationId: z.ZodString; + }, z.core.$loose>; +}, z.core.$strip>]>; +export declare const ServerResultSchema: z.ZodUnion>; + }, z.core.$loose>>; +}, z.core.$strict>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + protocolVersion: z.ZodString; + capabilities: z.ZodObject<{ + experimental: z.ZodOptional>>; + logging: z.ZodOptional>; + completions: z.ZodOptional>; + prompts: z.ZodOptional; + }, z.core.$strip>>; + resources: z.ZodOptional; + listChanged: z.ZodOptional; + }, z.core.$strip>>; + tools: z.ZodOptional; + }, z.core.$strip>>; + tasks: z.ZodOptional>; + cancel: z.ZodOptional>; + requests: z.ZodOptional>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>>; + }, z.core.$loose>; + serverInfo: z.ZodObject<{ + version: z.ZodString; + websiteUrl: z.ZodOptional; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>; + instructions: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + completion: z.ZodObject<{ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.ZodArray; + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.ZodOptional; + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.ZodOptional; + }, z.core.$loose>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + description: z.ZodOptional; + messages: z.ZodArray; + content: z.ZodUnion; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + prompts: z.ZodArray; + arguments: z.ZodOptional; + required: z.ZodOptional; + }, z.core.$strip>>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resources: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + resourceTemplates: z.ZodArray; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + contents: z.ZodArray; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + content: z.ZodDefault; + text: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"image">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"audio">; + data: z.ZodString; + mimeType: z.ZodString; + _meta: z.ZodOptional>; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + description: z.ZodOptional; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + type: z.ZodLiteral<"resource_link">; + }, z.core.$strip>, z.ZodObject<{ + type: z.ZodLiteral<"resource">; + resource: z.ZodUnion; + _meta: z.ZodOptional>; + text: z.ZodString; + }, z.core.$strip>, z.ZodObject<{ + uri: z.ZodString; + mimeType: z.ZodOptional; + _meta: z.ZodOptional>; + blob: z.ZodString; + }, z.core.$strip>]>; + _meta: z.ZodOptional>; + }, z.core.$strip>]>>>; + structuredContent: z.ZodOptional>; + isError: z.ZodOptional; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tools: z.ZodArray; + inputSchema: z.ZodObject<{ + type: z.ZodLiteral<"object">; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>; + outputSchema: z.ZodOptional; + properties: z.ZodOptional>>; + required: z.ZodOptional>; + }, z.core.$catchall>>; + annotations: z.ZodOptional; + readOnlyHint: z.ZodOptional; + destructiveHint: z.ZodOptional; + idempotentHint: z.ZodOptional; + openWorldHint: z.ZodOptional; + }, z.core.$strip>>; + execution: z.ZodOptional>; + }, z.core.$strip>>; + _meta: z.ZodOptional>; + icons: z.ZodOptional; + sizes: z.ZodOptional>; + }, z.core.$strip>>>; + name: z.ZodString; + title: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; +}, z.core.$strip>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + nextCursor: z.ZodOptional; + tasks: z.ZodArray; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>>; +}, z.core.$loose>, z.ZodObject<{ + _meta: z.ZodOptional>; + }, z.core.$loose>>; + task: z.ZodObject<{ + taskId: z.ZodString; + status: z.ZodEnum<{ + working: "working"; + input_required: "input_required"; + completed: "completed"; + failed: "failed"; + cancelled: "cancelled"; + }>; + ttl: z.ZodUnion; + createdAt: z.ZodString; + lastUpdatedAt: z.ZodString; + pollInterval: z.ZodOptional; + statusMessage: z.ZodOptional; + }, z.core.$strip>; +}, z.core.$loose>]>; +export declare class McpError extends Error { + readonly code: number; + readonly data?: unknown; + constructor(code: number, message: string, data?: unknown); + /** + * Factory method to create the appropriate error type based on the error code and data + */ + static fromError(code: number, message: string, data?: unknown): McpError; +} +/** + * Specialized error type when a tool requires a URL mode elicitation. + * This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against. + */ +export declare class UrlElicitationRequiredError extends McpError { + constructor(elicitations: ElicitRequestURLParams[], message?: string); + get elicitations(): ElicitRequestURLParams[]; +} +type Primitive = string | number | boolean | bigint | null | undefined; +type Flatten = T extends Primitive ? T : T extends Array ? Array> : T extends Set ? Set> : T extends Map ? Map, Flatten> : T extends object ? { + [K in keyof T]: Flatten; +} : T; +type Infer = Flatten>; +/** + * Headers that are compatible with both Node.js and the browser. + */ +export type IsomorphicHeaders = Record; +/** + * Information about the incoming request. + */ +export interface RequestInfo { + /** + * The headers of the request. + */ + headers: IsomorphicHeaders; +} +/** + * Extra information about a message. + */ +export interface MessageExtraInfo { + /** + * The request information. + */ + requestInfo?: RequestInfo; + /** + * The authentication information. + */ + authInfo?: AuthInfo; +} +export type ProgressToken = Infer; +export type Cursor = Infer; +export type Request = Infer; +export type RequestMeta = Infer; +export type Notification = Infer; +export type Result = Infer; +export type RequestId = Infer; +export type JSONRPCRequest = Infer; +export type JSONRPCNotification = Infer; +export type JSONRPCResponse = Infer; +export type JSONRPCError = Infer; +export type JSONRPCMessage = Infer; +export type RequestParams = Infer; +export type NotificationParams = Infer; +export type EmptyResult = Infer; +export type CancelledNotificationParams = Infer; +export type CancelledNotification = Infer; +export type Icon = Infer; +export type Icons = Infer; +export type BaseMetadata = Infer; +export type Implementation = Infer; +export type ClientCapabilities = Infer; +export type InitializeRequestParams = Infer; +export type InitializeRequest = Infer; +export type ServerCapabilities = Infer; +export type InitializeResult = Infer; +export type InitializedNotification = Infer; +export type PingRequest = Infer; +export type Progress = Infer; +export type ProgressNotificationParams = Infer; +export type ProgressNotification = Infer; +export type Task = Infer; +export type TaskCreationParams = Infer; +export type RelatedTaskMetadata = Infer; +export type CreateTaskResult = Infer; +export type TaskStatusNotificationParams = Infer; +export type TaskStatusNotification = Infer; +export type GetTaskRequest = Infer; +export type GetTaskResult = Infer; +export type GetTaskPayloadRequest = Infer; +export type ListTasksRequest = Infer; +export type ListTasksResult = Infer; +export type CancelTaskRequest = Infer; +export type CancelTaskResult = Infer; +export type PaginatedRequestParams = Infer; +export type PaginatedRequest = Infer; +export type PaginatedResult = Infer; +export type ResourceContents = Infer; +export type TextResourceContents = Infer; +export type BlobResourceContents = Infer; +export type Resource = Infer; +export type ResourceTemplate = Infer; +export type ListResourcesRequest = Infer; +export type ListResourcesResult = Infer; +export type ListResourceTemplatesRequest = Infer; +export type ListResourceTemplatesResult = Infer; +export type ResourceRequestParams = Infer; +export type ReadResourceRequestParams = Infer; +export type ReadResourceRequest = Infer; +export type ReadResourceResult = Infer; +export type ResourceListChangedNotification = Infer; +export type SubscribeRequestParams = Infer; +export type SubscribeRequest = Infer; +export type UnsubscribeRequestParams = Infer; +export type UnsubscribeRequest = Infer; +export type ResourceUpdatedNotificationParams = Infer; +export type ResourceUpdatedNotification = Infer; +export type PromptArgument = Infer; +export type Prompt = Infer; +export type ListPromptsRequest = Infer; +export type ListPromptsResult = Infer; +export type GetPromptRequestParams = Infer; +export type GetPromptRequest = Infer; +export type TextContent = Infer; +export type ImageContent = Infer; +export type AudioContent = Infer; +export type ToolUseContent = Infer; +export type ToolResultContent = Infer; +export type EmbeddedResource = Infer; +export type ResourceLink = Infer; +export type ContentBlock = Infer; +export type PromptMessage = Infer; +export type GetPromptResult = Infer; +export type PromptListChangedNotification = Infer; +export type ToolAnnotations = Infer; +export type ToolExecution = Infer; +export type Tool = Infer; +export type ListToolsRequest = Infer; +export type ListToolsResult = Infer; +export type CallToolRequestParams = Infer; +export type CallToolResult = Infer; +export type CompatibilityCallToolResult = Infer; +export type CallToolRequest = Infer; +export type ToolListChangedNotification = Infer; +export type LoggingLevel = Infer; +export type SetLevelRequestParams = Infer; +export type SetLevelRequest = Infer; +export type LoggingMessageNotificationParams = Infer; +export type LoggingMessageNotification = Infer; +export type ToolChoice = Infer; +export type ModelHint = Infer; +export type ModelPreferences = Infer; +export type SamplingMessageContentBlock = Infer; +export type SamplingMessage = Infer; +export type CreateMessageRequestParams = Infer; +export type CreateMessageRequest = Infer; +export type CreateMessageResult = Infer; +export type BooleanSchema = Infer; +export type StringSchema = Infer; +export type NumberSchema = Infer; +export type EnumSchema = Infer; +export type UntitledSingleSelectEnumSchema = Infer; +export type TitledSingleSelectEnumSchema = Infer; +export type LegacyTitledEnumSchema = Infer; +export type UntitledMultiSelectEnumSchema = Infer; +export type TitledMultiSelectEnumSchema = Infer; +export type SingleSelectEnumSchema = Infer; +export type MultiSelectEnumSchema = Infer; +export type PrimitiveSchemaDefinition = Infer; +export type ElicitRequestParams = Infer; +export type ElicitRequestFormParams = Infer; +export type ElicitRequestURLParams = Infer; +export type ElicitRequest = Infer; +export type ElicitationCompleteNotificationParams = Infer; +export type ElicitationCompleteNotification = Infer; +export type ElicitResult = Infer; +export type ResourceTemplateReference = Infer; +/** + * @deprecated Use ResourceTemplateReference instead + */ +export type ResourceReference = ResourceTemplateReference; +export type PromptReference = Infer; +export type CompleteRequestParams = Infer; +export type CompleteRequest = Infer; +export type CompleteRequestResourceTemplate = ExpandRecursively; +export type CompleteRequestPrompt = ExpandRecursively; +export type CompleteResult = Infer; +export type Root = Infer; +export type ListRootsRequest = Infer; +export type ListRootsResult = Infer; +export type RootsListChangedNotification = Infer; +export type ClientRequest = Infer; +export type ClientNotification = Infer; +export type ClientResult = Infer; +export type ServerRequest = Infer; +export type ServerNotification = Infer; +export type ServerResult = Infer; +export {}; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/esm/types.d.ts.map b/dist/esm/types.d.ts.map new file mode 100644 index 000000000..9ddeea1d0 --- /dev/null +++ b/dist/esm/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,eAAO,MAAM,uBAAuB,eAAe,CAAC;AACpD,eAAO,MAAM,mCAAmC,eAAe,CAAC;AAChE,eAAO,MAAM,2BAA2B,UAAsE,CAAC;AAE/G,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAG5E,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC;;GAEG;AACH,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG;KAAG,CA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AG;QAAE,GAAG,EAAE,yBAAyB,CAAA;KAAE,CAAA;CAAE,CAC3F,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,eAAe,GAAG;IAAE,MAAM,EAAE,qBAAqB,GAAG;QAAE,GAAG,EAAE,eAAe,CAAA;KAAE,CAAA;CAAE,CAAC,CAAC;AACtI,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAGhE,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAC5C,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClE,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAG5F,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAG5D,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/esm/types.js b/dist/esm/types.js new file mode 100644 index 000000000..c69cc369c --- /dev/null +++ b/dist/esm/types.js @@ -0,0 +1,1885 @@ +import * as z from 'zod/v4'; +export const LATEST_PROTOCOL_VERSION = '2025-06-18'; +export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26'; +export const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, '2025-03-26', '2024-11-05', '2024-10-07']; +export const RELATED_TASK_META_KEY = 'io.modelcontextprotocol/related-task'; +/* JSON-RPC types */ +export const JSONRPC_VERSION = '2.0'; +/** + * Assert 'object' type schema. + * + * @internal + */ +const AssertObjectSchema = z.custom((v) => v !== null && (typeof v === 'object' || typeof v === 'function')); +/** + * A progress token, used to associate progress notifications with the original request. + */ +export const ProgressTokenSchema = z.union([z.string(), z.number().int()]); +/** + * An opaque token used to represent a cursor for pagination. + */ +export const CursorSchema = z.string(); +/** + * Task creation parameters, used to ask that the server create a task to represent a request. + */ +export const TaskCreationParamsSchema = z.looseObject({ + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.union([z.number(), z.null()]).optional(), + /** + * Time in milliseconds to wait between task status requests. + */ + pollInterval: z.number().optional() +}); +/** + * Task association metadata, used to signal which task a message originated from. + */ +export const RelatedTaskMetadataSchema = z.looseObject({ + taskId: z.string() +}); +const RequestMetaSchema = z.looseObject({ + /** + * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications. + */ + progressToken: ProgressTokenSchema.optional(), + /** + * If specified, this request is related to the provided task. + */ + [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional() +}); +/** + * Common params for any request. + */ +const BaseRequestParamsSchema = z.looseObject({ + /** + * If specified, the caller is requesting that the receiver create a task to represent the request. + * Task creation parameters are now at the top level instead of in _meta. + */ + task: TaskCreationParamsSchema.optional(), + /** + * See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage. + */ + _meta: RequestMetaSchema.optional() +}); +export const RequestSchema = z.object({ + method: z.string(), + params: BaseRequestParamsSchema.optional() +}); +const NotificationsParamsSchema = z.looseObject({ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z + .object({ + /** + * If specified, this notification is related to the provided task. + */ + [RELATED_TASK_META_KEY]: z.optional(RelatedTaskMetadataSchema) + }) + .passthrough() + .optional() +}); +export const NotificationSchema = z.object({ + method: z.string(), + params: NotificationsParamsSchema.optional() +}); +export const ResultSchema = z.looseObject({ + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z + .looseObject({ + /** + * If specified, this result is related to the provided task. + */ + [RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional() + }) + .optional() +}); +/** + * A uniquely identifying ID for a request in JSON-RPC. + */ +export const RequestIdSchema = z.union([z.string(), z.number().int()]); +/** + * A request that expects a response. + */ +export const JSONRPCRequestSchema = z + .object({ + jsonrpc: z.literal(JSONRPC_VERSION), + id: RequestIdSchema, + ...RequestSchema.shape +}) + .strict(); +export const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success; +/** + * A notification which does not expect a response. + */ +export const JSONRPCNotificationSchema = z + .object({ + jsonrpc: z.literal(JSONRPC_VERSION), + ...NotificationSchema.shape +}) + .strict(); +export const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success; +/** + * A successful (non-error) response to a request. + */ +export const JSONRPCResponseSchema = z + .object({ + jsonrpc: z.literal(JSONRPC_VERSION), + id: RequestIdSchema, + result: ResultSchema +}) + .strict(); +export const isJSONRPCResponse = (value) => JSONRPCResponseSchema.safeParse(value).success; +/** + * Error codes defined by the JSON-RPC specification. + */ +export var ErrorCode; +(function (ErrorCode) { + // SDK error codes + ErrorCode[ErrorCode["ConnectionClosed"] = -32000] = "ConnectionClosed"; + ErrorCode[ErrorCode["RequestTimeout"] = -32001] = "RequestTimeout"; + // Standard JSON-RPC error codes + ErrorCode[ErrorCode["ParseError"] = -32700] = "ParseError"; + ErrorCode[ErrorCode["InvalidRequest"] = -32600] = "InvalidRequest"; + ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound"; + ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams"; + ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError"; + // MCP-specific error codes + ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired"; +})(ErrorCode || (ErrorCode = {})); +/** + * A response to a request that indicates an error occurred. + */ +export const JSONRPCErrorSchema = z + .object({ + jsonrpc: z.literal(JSONRPC_VERSION), + id: RequestIdSchema, + error: z.object({ + /** + * The error type that occurred. + */ + code: z.number().int(), + /** + * A short description of the error. The message SHOULD be limited to a concise single sentence. + */ + message: z.string(), + /** + * Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.). + */ + data: z.optional(z.unknown()) + }) +}) + .strict(); +export const isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success; +export const JSONRPCMessageSchema = z.union([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]); +/* Empty result */ +/** + * A response that indicates success but carries no data. + */ +export const EmptyResultSchema = ResultSchema.strict(); +export const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The ID of the request to cancel. + * + * This MUST correspond to the ID of a request previously issued in the same direction. + */ + requestId: RequestIdSchema, + /** + * An optional string describing the reason for the cancellation. This MAY be logged or presented to the user. + */ + reason: z.string().optional() +}); +/* Cancellation */ +/** + * This notification can be sent by either side to indicate that it is cancelling a previously-issued request. + * + * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished. + * + * This notification indicates that the result will be unused, so any associated processing SHOULD cease. + * + * A client MUST NOT attempt to cancel its `initialize` request. + */ +export const CancelledNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/cancelled'), + params: CancelledNotificationParamsSchema +}); +/* Base Metadata */ +/** + * Icon schema for use in tools, prompts, resources, and implementations. + */ +export const IconSchema = z.object({ + /** + * URL or data URI for the icon. + */ + src: z.string(), + /** + * Optional MIME type for the icon. + */ + mimeType: z.string().optional(), + /** + * Optional array of strings that specify sizes at which the icon can be used. + * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG. + * + * If not provided, the client should assume that the icon can be used at any size. + */ + sizes: z.array(z.string()).optional() +}); +/** + * Base schema to add `icons` property. + * + */ +export const IconsSchema = z.object({ + /** + * Optional set of sized icons that the client can display in a user interface. + * + * Clients that support rendering icons MUST support at least the following MIME types: + * - `image/png` - PNG images (safe, universal compatibility) + * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility) + * + * Clients that support rendering icons SHOULD also support: + * - `image/svg+xml` - SVG images (scalable but requires security precautions) + * - `image/webp` - WebP images (modern, efficient format) + */ + icons: z.array(IconSchema).optional() +}); +/** + * Base metadata interface for common properties across resources, tools, prompts, and implementations. + */ +export const BaseMetadataSchema = z.object({ + /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */ + name: z.string(), + /** + * Intended for UI and end-user contexts — optimized to be human-readable and easily understood, + * even by those unfamiliar with domain-specific terminology. + * + * If not provided, the name should be used for display (except for Tool, + * where `annotations.title` should be given precedence over using `name`, + * if present). + */ + title: z.string().optional() +}); +/* Initialization */ +/** + * Describes the name and version of an MCP implementation. + */ +export const ImplementationSchema = BaseMetadataSchema.extend({ + ...BaseMetadataSchema.shape, + ...IconsSchema.shape, + version: z.string(), + /** + * An optional URL of the website for this implementation. + */ + websiteUrl: z.string().optional() +}); +const FormElicitationCapabilitySchema = z.intersection(z.object({ + applyDefaults: z.boolean().optional() +}), z.record(z.string(), z.unknown())); +const ElicitationCapabilitySchema = z.preprocess(value => { + if (value && typeof value === 'object' && !Array.isArray(value)) { + if (Object.keys(value).length === 0) { + return { form: {} }; + } + } + return value; +}, z.intersection(z.object({ + form: FormElicitationCapabilitySchema.optional(), + url: AssertObjectSchema.optional() +}), z.record(z.string(), z.unknown()).optional())); +/** + * Task capabilities for clients, indicating which request types support task creation. + */ +export const ClientTasksCapabilitySchema = z + .object({ + /** + * Present if the client supports listing tasks. + */ + list: z.optional(z.object({}).passthrough()), + /** + * Present if the client supports cancelling tasks. + */ + cancel: z.optional(z.object({}).passthrough()), + /** + * Capabilities for task creation on specific request types. + */ + requests: z.optional(z + .object({ + /** + * Task support for sampling requests. + */ + sampling: z.optional(z + .object({ + createMessage: z.optional(z.object({}).passthrough()) + }) + .passthrough()), + /** + * Task support for elicitation requests. + */ + elicitation: z.optional(z + .object({ + create: z.optional(z.object({}).passthrough()) + }) + .passthrough()) + }) + .passthrough()) +}) + .passthrough(); +/** + * Task capabilities for servers, indicating which request types support task creation. + */ +export const ServerTasksCapabilitySchema = z + .object({ + /** + * Present if the server supports listing tasks. + */ + list: z.optional(z.object({}).passthrough()), + /** + * Present if the server supports cancelling tasks. + */ + cancel: z.optional(z.object({}).passthrough()), + /** + * Capabilities for task creation on specific request types. + */ + requests: z.optional(z + .object({ + /** + * Task support for tool requests. + */ + tools: z.optional(z + .object({ + call: z.optional(z.object({}).passthrough()) + }) + .passthrough()) + }) + .passthrough()) +}) + .passthrough(); +/** + * Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities. + */ +export const ClientCapabilitiesSchema = z.object({ + /** + * Experimental, non-standard capabilities that the client supports. + */ + experimental: z.record(z.string(), AssertObjectSchema).optional(), + /** + * Present if the client supports sampling from an LLM. + */ + sampling: z + .object({ + /** + * Present if the client supports context inclusion via includeContext parameter. + * If not declared, servers SHOULD only use `includeContext: "none"` (or omit it). + */ + context: AssertObjectSchema.optional(), + /** + * Present if the client supports tool use via tools and toolChoice parameters. + */ + tools: AssertObjectSchema.optional() + }) + .optional(), + /** + * Present if the client supports eliciting user input. + */ + elicitation: ElicitationCapabilitySchema.optional(), + /** + * Present if the client supports listing roots. + */ + roots: z + .object({ + /** + * Whether the client supports issuing notifications for changes to the roots list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the client supports task creation. + */ + tasks: z.optional(ClientTasksCapabilitySchema) +}); +export const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. + */ + protocolVersion: z.string(), + capabilities: ClientCapabilitiesSchema, + clientInfo: ImplementationSchema +}); +/** + * This request is sent from the client to the server when it first connects, asking it to begin initialization. + */ +export const InitializeRequestSchema = RequestSchema.extend({ + method: z.literal('initialize'), + params: InitializeRequestParamsSchema +}); +export const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success; +/** + * Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities. + */ +export const ServerCapabilitiesSchema = z + .object({ + /** + * Experimental, non-standard capabilities that the server supports. + */ + experimental: z.record(z.string(), AssertObjectSchema).optional(), + /** + * Present if the server supports sending log messages to the client. + */ + logging: AssertObjectSchema.optional(), + /** + * Present if the server supports sending completions to the client. + */ + completions: AssertObjectSchema.optional(), + /** + * Present if the server offers any prompt templates. + */ + prompts: z.optional(z.object({ + /** + * Whether this server supports issuing notifications for changes to the prompt list. + */ + listChanged: z.optional(z.boolean()) + })), + /** + * Present if the server offers any resources to read. + */ + resources: z + .object({ + /** + * Whether this server supports clients subscribing to resource updates. + */ + subscribe: z.boolean().optional(), + /** + * Whether this server supports issuing notifications for changes to the resource list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the server offers any tools to call. + */ + tools: z + .object({ + /** + * Whether this server supports issuing notifications for changes to the tool list. + */ + listChanged: z.boolean().optional() + }) + .optional(), + /** + * Present if the server supports task creation. + */ + tasks: z.optional(ServerTasksCapabilitySchema) +}) + .passthrough(); +/** + * After receiving an initialize request from the client, the server sends this response. + */ +export const InitializeResultSchema = ResultSchema.extend({ + /** + * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. + */ + protocolVersion: z.string(), + capabilities: ServerCapabilitiesSchema, + serverInfo: ImplementationSchema, + /** + * Instructions describing how to use the server and its features. + * + * This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. + */ + instructions: z.string().optional() +}); +/** + * This notification is sent from the client to the server after initialization has finished. + */ +export const InitializedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/initialized') +}); +export const isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success; +/* Ping */ +/** + * A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected. + */ +export const PingRequestSchema = RequestSchema.extend({ + method: z.literal('ping') +}); +/* Progress notifications */ +export const ProgressSchema = z.object({ + /** + * The progress thus far. This should increase every time progress is made, even if the total is unknown. + */ + progress: z.number(), + /** + * Total number of items to process (or total progress required), if known. + */ + total: z.optional(z.number()), + /** + * An optional message describing the current progress. + */ + message: z.optional(z.string()) +}); +export const ProgressNotificationParamsSchema = z.object({ + ...NotificationsParamsSchema.shape, + ...ProgressSchema.shape, + /** + * The progress token which was given in the initial request, used to associate this notification with the request that is proceeding. + */ + progressToken: ProgressTokenSchema +}); +/** + * An out-of-band notification used to inform the receiver of a progress update for a long-running request. + * + * @category notifications/progress + */ +export const ProgressNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/progress'), + params: ProgressNotificationParamsSchema +}); +export const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * An opaque token representing the current pagination position. + * If provided, the server should return results starting after this cursor. + */ + cursor: CursorSchema.optional() +}); +/* Pagination */ +export const PaginatedRequestSchema = RequestSchema.extend({ + params: PaginatedRequestParamsSchema.optional() +}); +export const PaginatedResultSchema = ResultSchema.extend({ + /** + * An opaque token representing the pagination position after the last returned result. + * If present, there may be more results available. + */ + nextCursor: z.optional(CursorSchema) +}); +/* Tasks */ +/** + * A pollable state object associated with a request. + */ +export const TaskSchema = z.object({ + taskId: z.string(), + status: z.enum(['working', 'input_required', 'completed', 'failed', 'cancelled']), + /** + * Time in milliseconds to keep task results available after completion. + * If null, the task has unlimited lifetime until manually cleaned up. + */ + ttl: z.union([z.number(), z.null()]), + /** + * ISO 8601 timestamp when the task was created. + */ + createdAt: z.string(), + /** + * ISO 8601 timestamp when the task was last updated. + */ + lastUpdatedAt: z.string(), + pollInterval: z.optional(z.number()), + /** + * Optional diagnostic message for failed tasks or other status information. + */ + statusMessage: z.optional(z.string()) +}); +/** + * Result returned when a task is created, containing the task data wrapped in a task field. + */ +export const CreateTaskResultSchema = ResultSchema.extend({ + task: TaskSchema +}); +/** + * Parameters for task status notification. + */ +export const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema); +/** + * A notification sent when a task's status changes. + */ +export const TaskStatusNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/tasks/status'), + params: TaskStatusNotificationParamsSchema +}); +/** + * A request to get the state of a specific task. + */ +export const GetTaskRequestSchema = RequestSchema.extend({ + method: z.literal('tasks/get'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * The response to a tasks/get request. + */ +export const GetTaskResultSchema = ResultSchema.merge(TaskSchema); +/** + * A request to get the result of a specific task. + */ +export const GetTaskPayloadRequestSchema = RequestSchema.extend({ + method: z.literal('tasks/result'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * A request to list tasks. + */ +export const ListTasksRequestSchema = PaginatedRequestSchema.extend({ + method: z.literal('tasks/list') +}); +/** + * The response to a tasks/list request. + */ +export const ListTasksResultSchema = PaginatedResultSchema.extend({ + tasks: z.array(TaskSchema) +}); +/** + * A request to cancel a specific task. + */ +export const CancelTaskRequestSchema = RequestSchema.extend({ + method: z.literal('tasks/cancel'), + params: BaseRequestParamsSchema.extend({ + taskId: z.string() + }) +}); +/** + * The response to a tasks/cancel request. + */ +export const CancelTaskResultSchema = ResultSchema.merge(TaskSchema); +/* Resources */ +/** + * The contents of a specific resource or sub-resource. + */ +export const ResourceContentsSchema = z.object({ + /** + * The URI of this resource. + */ + uri: z.string(), + /** + * The MIME type of this resource, if known. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +export const TextResourceContentsSchema = ResourceContentsSchema.extend({ + /** + * The text of the item. This must only be set if the item can actually be represented as text (not binary data). + */ + text: z.string() +}); +/** + * A Zod schema for validating Base64 strings that is more performant and + * robust for very large inputs than the default regex-based check. It avoids + * stack overflows by using the native `atob` function for validation. + */ +const Base64Schema = z.string().refine(val => { + try { + // atob throws a DOMException if the string contains characters + // that are not part of the Base64 character set. + atob(val); + return true; + } + catch (_a) { + return false; + } +}, { message: 'Invalid Base64 string' }); +export const BlobResourceContentsSchema = ResourceContentsSchema.extend({ + /** + * A base64-encoded string representing the binary data of the item. + */ + blob: Base64Schema +}); +/** + * A known resource that the server is capable of reading. + */ +export const ResourceSchema = z.object({ + ...BaseMetadataSchema.shape, + ...IconsSchema.shape, + /** + * The URI of this resource. + */ + uri: z.string(), + /** + * A description of what this resource represents. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description: z.optional(z.string()), + /** + * The MIME type of this resource, if known. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * A template description for resources available on the server. + */ +export const ResourceTemplateSchema = z.object({ + ...BaseMetadataSchema.shape, + ...IconsSchema.shape, + /** + * A URI template (according to RFC 6570) that can be used to construct resource URIs. + */ + uriTemplate: z.string(), + /** + * A description of what this template is for. + * + * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model. + */ + description: z.optional(z.string()), + /** + * The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type. + */ + mimeType: z.optional(z.string()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * Sent from the client to request a list of resources the server has. + */ +export const ListResourcesRequestSchema = PaginatedRequestSchema.extend({ + method: z.literal('resources/list') +}); +/** + * The server's response to a resources/list request from the client. + */ +export const ListResourcesResultSchema = PaginatedResultSchema.extend({ + resources: z.array(ResourceSchema) +}); +/** + * Sent from the client to request a list of resource templates the server has. + */ +export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({ + method: z.literal('resources/templates/list') +}); +/** + * The server's response to a resources/templates/list request from the client. + */ +export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({ + resourceTemplates: z.array(ResourceTemplateSchema) +}); +export const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it. + * + * @format uri + */ + uri: z.string() +}); +/** + * Parameters for a `resources/read` request. + */ +export const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema; +/** + * Sent from the client to the server, to read a specific resource URI. + */ +export const ReadResourceRequestSchema = RequestSchema.extend({ + method: z.literal('resources/read'), + params: ReadResourceRequestParamsSchema +}); +/** + * The server's response to a resources/read request from the client. + */ +export const ReadResourceResultSchema = ResultSchema.extend({ + contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema])) +}); +/** + * An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client. + */ +export const ResourceListChangedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/resources/list_changed') +}); +export const SubscribeRequestParamsSchema = ResourceRequestParamsSchema; +/** + * Sent from the client to request resources/updated notifications from the server whenever a particular resource changes. + */ +export const SubscribeRequestSchema = RequestSchema.extend({ + method: z.literal('resources/subscribe'), + params: SubscribeRequestParamsSchema +}); +export const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema; +/** + * Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request. + */ +export const UnsubscribeRequestSchema = RequestSchema.extend({ + method: z.literal('resources/unsubscribe'), + params: UnsubscribeRequestParamsSchema +}); +/** + * Parameters for a `notifications/resources/updated` notification. + */ +export const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. + */ + uri: z.string() +}); +/** + * A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request. + */ +export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/resources/updated'), + params: ResourceUpdatedNotificationParamsSchema +}); +/* Prompts */ +/** + * Describes an argument that a prompt can accept. + */ +export const PromptArgumentSchema = z.object({ + /** + * The name of the argument. + */ + name: z.string(), + /** + * A human-readable description of the argument. + */ + description: z.optional(z.string()), + /** + * Whether this argument must be provided. + */ + required: z.optional(z.boolean()) +}); +/** + * A prompt or prompt template that the server offers. + */ +export const PromptSchema = z.object({ + ...BaseMetadataSchema.shape, + ...IconsSchema.shape, + /** + * An optional description of what this prompt provides + */ + description: z.optional(z.string()), + /** + * A list of arguments to use for templating the prompt. + */ + arguments: z.optional(z.array(PromptArgumentSchema)), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.looseObject({})) +}); +/** + * Sent from the client to request a list of prompts and prompt templates the server has. + */ +export const ListPromptsRequestSchema = PaginatedRequestSchema.extend({ + method: z.literal('prompts/list') +}); +/** + * The server's response to a prompts/list request from the client. + */ +export const ListPromptsResultSchema = PaginatedResultSchema.extend({ + prompts: z.array(PromptSchema) +}); +/** + * Parameters for a `prompts/get` request. + */ +export const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The name of the prompt or prompt template. + */ + name: z.string(), + /** + * Arguments to use for templating the prompt. + */ + arguments: z.record(z.string(), z.string()).optional() +}); +/** + * Used by the client to get a prompt provided by the server. + */ +export const GetPromptRequestSchema = RequestSchema.extend({ + method: z.literal('prompts/get'), + params: GetPromptRequestParamsSchema +}); +/** + * Text provided to or from an LLM. + */ +export const TextContentSchema = z.object({ + type: z.literal('text'), + /** + * The text content of the message. + */ + text: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * An image provided to or from an LLM. + */ +export const ImageContentSchema = z.object({ + type: z.literal('image'), + /** + * The base64-encoded image data. + */ + data: Base64Schema, + /** + * The MIME type of the image. Different providers may support different image types. + */ + mimeType: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * An Audio provided to or from an LLM. + */ +export const AudioContentSchema = z.object({ + type: z.literal('audio'), + /** + * The base64-encoded audio data. + */ + data: Base64Schema, + /** + * The MIME type of the audio. Different providers may support different audio types. + */ + mimeType: z.string(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * A tool call request from an assistant (LLM). + * Represents the assistant's request to use a tool. + */ +export const ToolUseContentSchema = z + .object({ + type: z.literal('tool_use'), + /** + * The name of the tool to invoke. + * Must match a tool name from the request's tools array. + */ + name: z.string(), + /** + * Unique identifier for this tool call. + * Used to correlate with ToolResultContent in subsequent messages. + */ + id: z.string(), + /** + * Arguments to pass to the tool. + * Must conform to the tool's inputSchema. + */ + input: z.object({}).passthrough(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * The contents of a resource, embedded into a prompt or tool call result. + */ +export const EmbeddedResourceSchema = z.object({ + type: z.literal('resource'), + resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * A resource that the server is capable of reading, included in a prompt or tool call result. + * + * Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests. + */ +export const ResourceLinkSchema = ResourceSchema.extend({ + type: z.literal('resource_link') +}); +/** + * A content block that can be used in prompts and tool results. + */ +export const ContentBlockSchema = z.union([ + TextContentSchema, + ImageContentSchema, + AudioContentSchema, + ResourceLinkSchema, + EmbeddedResourceSchema +]); +/** + * Describes a message returned as part of a prompt. + */ +export const PromptMessageSchema = z.object({ + role: z.enum(['user', 'assistant']), + content: ContentBlockSchema +}); +/** + * The server's response to a prompts/get request from the client. + */ +export const GetPromptResultSchema = ResultSchema.extend({ + /** + * An optional description for the prompt. + */ + description: z.optional(z.string()), + messages: z.array(PromptMessageSchema) +}); +/** + * An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export const PromptListChangedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/prompts/list_changed') +}); +/* Tools */ +/** + * Additional properties describing a Tool to clients. + * + * NOTE: all properties in ToolAnnotations are **hints**. + * They are not guaranteed to provide a faithful description of + * tool behavior (including descriptive properties like `title`). + * + * Clients should never make tool use decisions based on ToolAnnotations + * received from untrusted servers. + */ +export const ToolAnnotationsSchema = z.object({ + /** + * A human-readable title for the tool. + */ + title: z.string().optional(), + /** + * If true, the tool does not modify its environment. + * + * Default: false + */ + readOnlyHint: z.boolean().optional(), + /** + * If true, the tool may perform destructive updates to its environment. + * If false, the tool performs only additive updates. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: true + */ + destructiveHint: z.boolean().optional(), + /** + * If true, calling the tool repeatedly with the same arguments + * will have no additional effect on the its environment. + * + * (This property is meaningful only when `readOnlyHint == false`) + * + * Default: false + */ + idempotentHint: z.boolean().optional(), + /** + * If true, this tool may interact with an "open world" of external + * entities. If false, the tool's domain of interaction is closed. + * For example, the world of a web search tool is open, whereas that + * of a memory tool is not. + * + * Default: true + */ + openWorldHint: z.boolean().optional() +}); +/** + * Execution-related properties for a tool. + */ +export const ToolExecutionSchema = z.object({ + /** + * Indicates the tool's preference for task-augmented execution. + * - "required": Clients MUST invoke the tool as a task + * - "optional": Clients MAY invoke the tool as a task or normal request + * - "forbidden": Clients MUST NOT attempt to invoke the tool as a task + * + * If not present, defaults to "forbidden". + */ + taskSupport: z.enum(['required', 'optional', 'forbidden']).optional() +}); +/** + * Definition for a tool the client can call. + */ +export const ToolSchema = z.object({ + ...BaseMetadataSchema.shape, + ...IconsSchema.shape, + /** + * A human-readable description of the tool. + */ + description: z.string().optional(), + /** + * A JSON Schema 2020-12 object defining the expected parameters for the tool. + * Must have type: 'object' at the root level per MCP spec. + */ + inputSchema: z + .object({ + type: z.literal('object'), + properties: z.record(z.string(), AssertObjectSchema).optional(), + required: z.array(z.string()).optional() + }) + .catchall(z.unknown()), + /** + * An optional JSON Schema 2020-12 object defining the structure of the tool's output + * returned in the structuredContent field of a CallToolResult. + * Must have type: 'object' at the root level per MCP spec. + */ + outputSchema: z + .object({ + type: z.literal('object'), + properties: z.record(z.string(), AssertObjectSchema).optional(), + required: z.array(z.string()).optional() + }) + .catchall(z.unknown()) + .optional(), + /** + * Optional additional tool information. + */ + annotations: z.optional(ToolAnnotationsSchema), + /** + * Execution-related properties for this tool. + */ + execution: z.optional(ToolExecutionSchema), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * Sent from the client to request a list of tools the server has. + */ +export const ListToolsRequestSchema = PaginatedRequestSchema.extend({ + method: z.literal('tools/list') +}); +/** + * The server's response to a tools/list request from the client. + */ +export const ListToolsResultSchema = PaginatedResultSchema.extend({ + tools: z.array(ToolSchema) +}); +/** + * The server's response to a tool call. + */ +export const CallToolResultSchema = ResultSchema.extend({ + /** + * A list of content objects that represent the result of the tool call. + * + * If the Tool does not define an outputSchema, this field MUST be present in the result. + * For backwards compatibility, this field is always present, but it may be empty. + */ + content: z.array(ContentBlockSchema).default([]), + /** + * An object containing structured tool output. + * + * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema. + */ + structuredContent: z.record(z.string(), z.unknown()).optional(), + /** + * Whether the tool call ended in an error. + * + * If not set, this is assumed to be false (the call was successful). + * + * Any errors that originate from the tool SHOULD be reported inside the result + * object, with `isError` set to true, _not_ as an MCP protocol-level error + * response. Otherwise, the LLM would not be able to see that an error occurred + * and self-correct. + * + * However, any errors in _finding_ the tool, an error indicating that the + * server does not support tool calls, or any other exceptional conditions, + * should be reported as an MCP error response. + */ + isError: z.optional(z.boolean()) +}); +/** + * CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. + */ +export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({ + toolResult: z.unknown() +})); +/** + * Parameters for a `tools/call` request. + */ +export const CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The name of the tool to call. + */ + name: z.string(), + /** + * Arguments to pass to the tool. + */ + arguments: z.optional(z.record(z.string(), z.unknown())) +}); +/** + * Used by the client to invoke a tool provided by the server. + */ +export const CallToolRequestSchema = RequestSchema.extend({ + method: z.literal('tools/call'), + params: CallToolRequestParamsSchema +}); +/** + * An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client. + */ +export const ToolListChangedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/tools/list_changed') +}); +/* Logging */ +/** + * The severity of a log message. + */ +export const LoggingLevelSchema = z.enum(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']); +/** + * Parameters for a `logging/setLevel` request. + */ +export const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message. + */ + level: LoggingLevelSchema +}); +/** + * A request from the client to the server, to enable or adjust logging. + */ +export const SetLevelRequestSchema = RequestSchema.extend({ + method: z.literal('logging/setLevel'), + params: SetLevelRequestParamsSchema +}); +/** + * Parameters for a `notifications/message` notification. + */ +export const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The severity of this log message. + */ + level: LoggingLevelSchema, + /** + * An optional name of the logger issuing this message. + */ + logger: z.string().optional(), + /** + * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here. + */ + data: z.unknown() +}); +/** + * Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically. + */ +export const LoggingMessageNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/message'), + params: LoggingMessageNotificationParamsSchema +}); +/* Sampling */ +/** + * Hints to use for model selection. + */ +export const ModelHintSchema = z.object({ + /** + * A hint for a model name. + */ + name: z.string().optional() +}); +/** + * The server's preferences for model selection, requested of the client during sampling. + */ +export const ModelPreferencesSchema = z.object({ + /** + * Optional hints to use for model selection. + */ + hints: z.optional(z.array(ModelHintSchema)), + /** + * How much to prioritize cost when selecting a model. + */ + costPriority: z.optional(z.number().min(0).max(1)), + /** + * How much to prioritize sampling speed (latency) when selecting a model. + */ + speedPriority: z.optional(z.number().min(0).max(1)), + /** + * How much to prioritize intelligence and capabilities when selecting a model. + */ + intelligencePriority: z.optional(z.number().min(0).max(1)) +}); +/** + * Controls tool usage behavior in sampling requests. + */ +export const ToolChoiceSchema = z.object({ + /** + * Controls when tools are used: + * - "auto": Model decides whether to use tools (default) + * - "required": Model MUST use at least one tool before completing + * - "none": Model MUST NOT use any tools + */ + mode: z.optional(z.enum(['auto', 'required', 'none'])) +}); +/** + * The result of a tool execution, provided by the user (server). + * Represents the outcome of invoking a tool requested via ToolUseContent. + */ +export const ToolResultContentSchema = z + .object({ + type: z.literal('tool_result'), + toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'), + content: z.array(ContentBlockSchema).default([]), + structuredContent: z.object({}).passthrough().optional(), + isError: z.optional(z.boolean()), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * Content block types allowed in sampling messages. + * This includes text, image, audio, tool use requests, and tool results. + */ +export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [ + TextContentSchema, + ImageContentSchema, + AudioContentSchema, + ToolUseContentSchema, + ToolResultContentSchema +]); +/** + * Describes a message issued to or received from an LLM API. + */ +export const SamplingMessageSchema = z + .object({ + role: z.enum(['user', 'assistant']), + content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.optional(z.object({}).passthrough()) +}) + .passthrough(); +/** + * Parameters for a `sampling/createMessage` request. + */ +export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({ + messages: z.array(SamplingMessageSchema), + /** + * The server's preferences for which model to select. The client MAY modify or omit this request. + */ + modelPreferences: ModelPreferencesSchema.optional(), + /** + * An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt. + */ + systemPrompt: z.string().optional(), + /** + * A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. + * The client MAY ignore this request. + * + * Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client + * declares ClientCapabilities.sampling.context. These values may be removed in future spec releases. + */ + includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(), + temperature: z.number().optional(), + /** + * The requested maximum number of tokens to sample (to prevent runaway completions). + * + * The client MAY choose to sample fewer tokens than the requested maximum. + */ + maxTokens: z.number().int(), + stopSequences: z.array(z.string()).optional(), + /** + * Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific. + */ + metadata: AssertObjectSchema.optional(), + /** + * Tools that the model may use during generation. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + */ + tools: z.optional(z.array(ToolSchema)), + /** + * Controls how the model uses tools. + * The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared. + * Default is `{ mode: "auto" }`. + */ + toolChoice: z.optional(ToolChoiceSchema) +}); +/** + * A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. + */ +export const CreateMessageRequestSchema = RequestSchema.extend({ + method: z.literal('sampling/createMessage'), + params: CreateMessageRequestParamsSchema +}); +/** + * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it. + */ +export const CreateMessageResultSchema = ResultSchema.extend({ + /** + * The name of the model that generated the message. + */ + model: z.string(), + /** + * The reason why sampling stopped, if known. + * + * Standard values: + * - "endTurn": Natural end of the assistant's turn + * - "stopSequence": A stop sequence was encountered + * - "maxTokens": Maximum token limit was reached + * - "toolUse": The model wants to use one or more tools + * + * This field is an open string to allow for provider-specific stop reasons. + */ + stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())), + role: z.enum(['user', 'assistant']), + /** + * Response content. May be ToolUseContent if stopReason is "toolUse". + */ + content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]) +}); +/* Elicitation */ +/** + * Primitive schema definition for boolean fields. + */ +export const BooleanSchemaSchema = z.object({ + type: z.literal('boolean'), + title: z.string().optional(), + description: z.string().optional(), + default: z.boolean().optional() +}); +/** + * Primitive schema definition for string fields. + */ +export const StringSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + minLength: z.number().optional(), + maxLength: z.number().optional(), + format: z.enum(['email', 'uri', 'date', 'date-time']).optional(), + default: z.string().optional() +}); +/** + * Primitive schema definition for number fields. + */ +export const NumberSchemaSchema = z.object({ + type: z.enum(['number', 'integer']), + title: z.string().optional(), + description: z.string().optional(), + minimum: z.number().optional(), + maximum: z.number().optional(), + default: z.number().optional() +}); +/** + * Schema for single-selection enumeration without display titles for options. + */ +export const UntitledSingleSelectEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + enum: z.array(z.string()), + default: z.string().optional() +}); +/** + * Schema for single-selection enumeration with display titles for each option. + */ +export const TitledSingleSelectEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + oneOf: z.array(z.object({ + const: z.string(), + title: z.string() + })), + default: z.string().optional() +}); +/** + * Use TitledSingleSelectEnumSchema instead. + * This interface will be removed in a future version. + */ +export const LegacyTitledEnumSchemaSchema = z.object({ + type: z.literal('string'), + title: z.string().optional(), + description: z.string().optional(), + enum: z.array(z.string()), + enumNames: z.array(z.string()).optional(), + default: z.string().optional() +}); +// Combined single selection enumeration +export const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]); +/** + * Schema for multiple-selection enumeration without display titles for options. + */ +export const UntitledMultiSelectEnumSchemaSchema = z.object({ + type: z.literal('array'), + title: z.string().optional(), + description: z.string().optional(), + minItems: z.number().optional(), + maxItems: z.number().optional(), + items: z.object({ + type: z.literal('string'), + enum: z.array(z.string()) + }), + default: z.array(z.string()).optional() +}); +/** + * Schema for multiple-selection enumeration with display titles for each option. + */ +export const TitledMultiSelectEnumSchemaSchema = z.object({ + type: z.literal('array'), + title: z.string().optional(), + description: z.string().optional(), + minItems: z.number().optional(), + maxItems: z.number().optional(), + items: z.object({ + anyOf: z.array(z.object({ + const: z.string(), + title: z.string() + })) + }), + default: z.array(z.string()).optional() +}); +/** + * Combined schema for multiple-selection enumeration + */ +export const MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]); +/** + * Primitive schema definition for enum fields. + */ +export const EnumSchemaSchema = z.union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]); +/** + * Union of all primitive schema definitions. + */ +export const PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]); +/** + * Parameters for an `elicitation/create` request for form-based elicitation. + */ +export const ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The elicitation mode. + * + * Optional for backward compatibility. Clients MUST treat missing mode as "form". + */ + mode: z.literal('form').optional(), + /** + * The message to present to the user describing what information is being requested. + */ + message: z.string(), + /** + * A restricted subset of JSON Schema. + * Only top-level properties are allowed, without nesting. + */ + requestedSchema: z.object({ + type: z.literal('object'), + properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), + required: z.array(z.string()).optional() + }) +}); +/** + * Parameters for an `elicitation/create` request for URL-based elicitation. + */ +export const ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({ + /** + * The elicitation mode. + */ + mode: z.literal('url'), + /** + * The message to present to the user explaining why the interaction is needed. + */ + message: z.string(), + /** + * The ID of the elicitation, which must be unique within the context of the server. + * The client MUST treat this ID as an opaque value. + */ + elicitationId: z.string(), + /** + * The URL that the user should navigate to. + */ + url: z.string().url() +}); +/** + * The parameters for a request to elicit additional information from the user via the client. + */ +export const ElicitRequestParamsSchema = z.union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]); +/** + * A request from the server to elicit user input via the client. + * The client should present the message and form fields to the user (form mode) + * or navigate to a URL (URL mode). + */ +export const ElicitRequestSchema = RequestSchema.extend({ + method: z.literal('elicitation/create'), + params: ElicitRequestParamsSchema +}); +/** + * Parameters for a `notifications/elicitation/complete` notification. + * + * @category notifications/elicitation/complete + */ +export const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({ + /** + * The ID of the elicitation that completed. + */ + elicitationId: z.string() +}); +/** + * A notification from the server to the client, informing it of a completion of an out-of-band elicitation request. + * + * @category notifications/elicitation/complete + */ +export const ElicitationCompleteNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/elicitation/complete'), + params: ElicitationCompleteNotificationParamsSchema +}); +/** + * The client's response to an elicitation/create request from the server. + */ +export const ElicitResultSchema = ResultSchema.extend({ + /** + * The user action in response to the elicitation. + * - "accept": User submitted the form/confirmed the action + * - "decline": User explicitly decline the action + * - "cancel": User dismissed without making an explicit choice + */ + action: z.enum(['accept', 'decline', 'cancel']), + /** + * The submitted form data, only present when action is "accept". + * Contains values matching the requested schema. + */ + content: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional() +}); +/* Autocomplete */ +/** + * A reference to a resource or resource template definition. + */ +export const ResourceTemplateReferenceSchema = z.object({ + type: z.literal('ref/resource'), + /** + * The URI or URI template of the resource. + */ + uri: z.string() +}); +/** + * @deprecated Use ResourceTemplateReferenceSchema instead + */ +export const ResourceReferenceSchema = ResourceTemplateReferenceSchema; +/** + * Identifies a prompt. + */ +export const PromptReferenceSchema = z.object({ + type: z.literal('ref/prompt'), + /** + * The name of the prompt or prompt template + */ + name: z.string() +}); +/** + * Parameters for a `completion/complete` request. + */ +export const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({ + ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]), + /** + * The argument's information + */ + argument: z.object({ + /** + * The name of the argument + */ + name: z.string(), + /** + * The value of the argument to use for completion matching. + */ + value: z.string() + }), + context: z + .object({ + /** + * Previously-resolved variables in a URI template or prompt. + */ + arguments: z.record(z.string(), z.string()).optional() + }) + .optional() +}); +/** + * A request from the client to the server, to ask for completion options. + */ +export const CompleteRequestSchema = RequestSchema.extend({ + method: z.literal('completion/complete'), + params: CompleteRequestParamsSchema +}); +export function assertCompleteRequestPrompt(request) { + if (request.params.ref.type !== 'ref/prompt') { + throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`); + } + void request; +} +export function assertCompleteRequestResourceTemplate(request) { + if (request.params.ref.type !== 'ref/resource') { + throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`); + } + void request; +} +/** + * The server's response to a completion/complete request + */ +export const CompleteResultSchema = ResultSchema.extend({ + completion: z.looseObject({ + /** + * An array of completion values. Must not exceed 100 items. + */ + values: z.array(z.string()).max(100), + /** + * The total number of completion options available. This can exceed the number of values actually sent in the response. + */ + total: z.optional(z.number().int()), + /** + * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown. + */ + hasMore: z.optional(z.boolean()) + }) +}); +/* Roots */ +/** + * Represents a root directory or file that the server can operate on. + */ +export const RootSchema = z.object({ + /** + * The URI identifying the root. This *must* start with file:// for now. + */ + uri: z.string().startsWith('file://'), + /** + * An optional name for the root. + */ + name: z.string().optional(), + /** + * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + * for notes on _meta usage. + */ + _meta: z.record(z.string(), z.unknown()).optional() +}); +/** + * Sent from the server to request a list of root URIs from the client. + */ +export const ListRootsRequestSchema = RequestSchema.extend({ + method: z.literal('roots/list') +}); +/** + * The client's response to a roots/list request from the server. + */ +export const ListRootsResultSchema = ResultSchema.extend({ + roots: z.array(RootSchema) +}); +/** + * A notification from the client to the server, informing it that the list of roots has changed. + */ +export const RootsListChangedNotificationSchema = NotificationSchema.extend({ + method: z.literal('notifications/roots/list_changed') +}); +/* Client messages */ +export const ClientRequestSchema = z.union([ + PingRequestSchema, + InitializeRequestSchema, + CompleteRequestSchema, + SetLevelRequestSchema, + GetPromptRequestSchema, + ListPromptsRequestSchema, + ListResourcesRequestSchema, + ListResourceTemplatesRequestSchema, + ReadResourceRequestSchema, + SubscribeRequestSchema, + UnsubscribeRequestSchema, + CallToolRequestSchema, + ListToolsRequestSchema, + GetTaskRequestSchema, + GetTaskPayloadRequestSchema, + ListTasksRequestSchema +]); +export const ClientNotificationSchema = z.union([ + CancelledNotificationSchema, + ProgressNotificationSchema, + InitializedNotificationSchema, + RootsListChangedNotificationSchema, + TaskStatusNotificationSchema +]); +export const ClientResultSchema = z.union([ + EmptyResultSchema, + CreateMessageResultSchema, + ElicitResultSchema, + ListRootsResultSchema, + GetTaskResultSchema, + ListTasksResultSchema, + CreateTaskResultSchema +]); +/* Server messages */ +export const ServerRequestSchema = z.union([ + PingRequestSchema, + CreateMessageRequestSchema, + ElicitRequestSchema, + ListRootsRequestSchema, + GetTaskRequestSchema, + GetTaskPayloadRequestSchema, + ListTasksRequestSchema +]); +export const ServerNotificationSchema = z.union([ + CancelledNotificationSchema, + ProgressNotificationSchema, + LoggingMessageNotificationSchema, + ResourceUpdatedNotificationSchema, + ResourceListChangedNotificationSchema, + ToolListChangedNotificationSchema, + PromptListChangedNotificationSchema, + TaskStatusNotificationSchema, + ElicitationCompleteNotificationSchema +]); +export const ServerResultSchema = z.union([ + EmptyResultSchema, + InitializeResultSchema, + CompleteResultSchema, + GetPromptResultSchema, + ListPromptsResultSchema, + ListResourcesResultSchema, + ListResourceTemplatesResultSchema, + ReadResourceResultSchema, + CallToolResultSchema, + ListToolsResultSchema, + GetTaskResultSchema, + ListTasksResultSchema, + CreateTaskResultSchema +]); +export class McpError extends Error { + constructor(code, message, data) { + super(`MCP error ${code}: ${message}`); + this.code = code; + this.data = data; + this.name = 'McpError'; + } + /** + * Factory method to create the appropriate error type based on the error code and data + */ + static fromError(code, message, data) { + // Check for specific error types + if (code === ErrorCode.UrlElicitationRequired && data) { + const errorData = data; + if (errorData.elicitations) { + return new UrlElicitationRequiredError(errorData.elicitations, message); + } + } + // Default to generic McpError + return new McpError(code, message, data); + } +} +/** + * Specialized error type when a tool requires a URL mode elicitation. + * This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against. + */ +export class UrlElicitationRequiredError extends McpError { + constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? 's' : ''} required`) { + super(ErrorCode.UrlElicitationRequired, message, { + elicitations: elicitations + }); + } + get elicitations() { + var _a, _b; + return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : []; + } +} +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/esm/types.js.map b/dist/esm/types.js.map new file mode 100644 index 000000000..1cedf1c2f --- /dev/null +++ b/dist/esm/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACpD,MAAM,CAAC,MAAM,mCAAmC,GAAG,YAAY,CAAC;AAChE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE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YAAY,EAAE,CAAC;gBACzB,OAAO,IAAI,2BAA2B,CAAC,SAAS,CAAC,YAAwC,EAAE,OAAO,CAAC,CAAC;YACxG,CAAC;QACL,CAAC;QAED,8BAA8B;QAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,QAAQ;IACrD,YAAY,YAAsC,EAAE,UAAkB,kBAAkB,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW;QACjI,KAAK,CAAC,SAAS,CAAC,sBAAsB,EAAE,OAAO,EAAE;YAC7C,YAAY,EAAE,YAAY;SAC7B,CAAC,CAAC;IACP,CAAC;IAED,IAAI,YAAY;;QACZ,OAAO,MAAA,MAAC,IAAI,CAAC,IAAmD,0CAAE,YAAY,mCAAI,EAAE,CAAC;IACzF,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/validation/ajv-provider.d.ts b/dist/esm/validation/ajv-provider.d.ts new file mode 100644 index 000000000..43e24ffc9 --- /dev/null +++ b/dist/esm/validation/ajv-provider.d.ts @@ -0,0 +1,53 @@ +/** + * AJV-based JSON Schema validator provider + */ +import { Ajv } from 'ajv'; +import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js'; +/** + * @example + * ```typescript + * // Use with default AJV instance (recommended) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Use with custom AJV instance + * import { Ajv } from 'ajv'; + * const ajv = new Ajv({ strict: true, allErrors: true }); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ +export declare class AjvJsonSchemaValidator implements jsonSchemaValidator { + private _ajv; + /** + * Create an AJV validator + * + * @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created. + * + * @example + * ```typescript + * // Use default configuration (recommended for most cases) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Or provide custom AJV instance for advanced configuration + * import { Ajv } from 'ajv'; + * import addFormats from 'ajv-formats'; + * + * const ajv = new Ajv({ validateFormats: true }); + * addFormats(ajv); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ + constructor(ajv?: Ajv); + /** + * Create a validator for the given JSON Schema + * + * The validator is compiled once and can be reused multiple times. + * If the schema has an $id, it will be cached by AJV automatically. + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +//# sourceMappingURL=ajv-provider.d.ts.map \ No newline at end of file diff --git a/dist/esm/validation/ajv-provider.d.ts.map b/dist/esm/validation/ajv-provider.d.ts.map new file mode 100644 index 000000000..4e955a3b3 --- /dev/null +++ b/dist/esm/validation/ajv-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ajv-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/ajv-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAgBtH;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,mBAAmB;IAC9D,OAAO,CAAC,IAAI,CAAM;IAElB;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,GAAG,CAAC,EAAE,GAAG;IAIrB;;;;;;;;OAQG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAyBlE"} \ No newline at end of file diff --git a/dist/esm/validation/ajv-provider.js b/dist/esm/validation/ajv-provider.js new file mode 100644 index 000000000..02762f0c1 --- /dev/null +++ b/dist/esm/validation/ajv-provider.js @@ -0,0 +1,88 @@ +/** + * AJV-based JSON Schema validator provider + */ +import { Ajv } from 'ajv'; +import _addFormats from 'ajv-formats'; +function createDefaultAjvInstance() { + const ajv = new Ajv({ + strict: false, + validateFormats: true, + validateSchema: false, + allErrors: true + }); + const addFormats = _addFormats; + addFormats(ajv); + return ajv; +} +/** + * @example + * ```typescript + * // Use with default AJV instance (recommended) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Use with custom AJV instance + * import { Ajv } from 'ajv'; + * const ajv = new Ajv({ strict: true, allErrors: true }); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ +export class AjvJsonSchemaValidator { + /** + * Create an AJV validator + * + * @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created. + * + * @example + * ```typescript + * // Use default configuration (recommended for most cases) + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // Or provide custom AJV instance for advanced configuration + * import { Ajv } from 'ajv'; + * import addFormats from 'ajv-formats'; + * + * const ajv = new Ajv({ validateFormats: true }); + * addFormats(ajv); + * const validator = new AjvJsonSchemaValidator(ajv); + * ``` + */ + constructor(ajv) { + this._ajv = ajv !== null && ajv !== void 0 ? ajv : createDefaultAjvInstance(); + } + /** + * Create a validator for the given JSON Schema + * + * The validator is compiled once and can be reused multiple times. + * If the schema has an $id, it will be cached by AJV automatically. + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema) { + var _a; + // Check if schema has $id and is already compiled/cached + const ajvValidator = '$id' in schema && typeof schema.$id === 'string' + ? ((_a = this._ajv.getSchema(schema.$id)) !== null && _a !== void 0 ? _a : this._ajv.compile(schema)) + : this._ajv.compile(schema); + return (input) => { + const valid = ajvValidator(input); + if (valid) { + return { + valid: true, + data: input, + errorMessage: undefined + }; + } + else { + return { + valid: false, + data: undefined, + errorMessage: this._ajv.errorsText(ajvValidator.errors) + }; + } + }; + } +} +//# sourceMappingURL=ajv-provider.js.map \ No newline at end of file diff --git a/dist/esm/validation/ajv-provider.js.map b/dist/esm/validation/ajv-provider.js.map new file mode 100644 index 000000000..ce7e5d0c9 --- /dev/null +++ b/dist/esm/validation/ajv-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ajv-provider.js","sourceRoot":"","sources":["../../../src/validation/ajv-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,WAAW,MAAM,aAAa,CAAC;AAGtC,SAAS,wBAAwB;IAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC;QAChB,MAAM,EAAE,KAAK;QACb,eAAe,EAAE,IAAI;QACrB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,WAAoD,CAAC;IACxE,UAAU,CAAC,GAAG,CAAC,CAAC;IAEhB,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,sBAAsB;IAG/B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,GAAS;QACjB,IAAI,CAAC,IAAI,GAAG,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,wBAAwB,EAAE,CAAC;IAClD,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAI,MAAsB;;QAClC,yDAAyD;QACzD,MAAM,YAAY,GACd,KAAK,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;YAC7C,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpC,OAAO,CAAC,KAAc,EAAgC,EAAE;YACpD,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAElC,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAU;oBAChB,YAAY,EAAE,SAAS;iBAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO;oBACH,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,SAAS;oBACf,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;iBAC1D,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/validation/cfworker-provider.d.ts b/dist/esm/validation/cfworker-provider.d.ts new file mode 100644 index 000000000..89c244a60 --- /dev/null +++ b/dist/esm/validation/cfworker-provider.d.ts @@ -0,0 +1,51 @@ +/** + * Cloudflare Worker-compatible JSON Schema validator provider + * + * This provider uses @cfworker/json-schema for validation without code generation, + * making it compatible with edge runtimes like Cloudflare Workers that restrict + * eval and new Function. + */ +import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js'; +/** + * JSON Schema draft version supported by @cfworker/json-schema + */ +export type CfWorkerSchemaDraft = '4' | '7' | '2019-09' | '2020-12'; +/** + * + * @example + * ```typescript + * // Use with default configuration (2020-12, shortcircuit) + * const validator = new CfWorkerJsonSchemaValidator(); + * + * // Use with custom configuration + * const validator = new CfWorkerJsonSchemaValidator({ + * draft: '2020-12', + * shortcircuit: false // Report all errors + * }); + * ``` + */ +export declare class CfWorkerJsonSchemaValidator implements jsonSchemaValidator { + private shortcircuit; + private draft; + /** + * Create a validator + * + * @param options - Configuration options + * @param options.shortcircuit - If true, stop validation after first error (default: true) + * @param options.draft - JSON Schema draft version to use (default: '2020-12') + */ + constructor(options?: { + shortcircuit?: boolean; + draft?: CfWorkerSchemaDraft; + }); + /** + * Create a validator for the given JSON Schema + * + * Unlike AJV, this validator is not cached internally + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +//# sourceMappingURL=cfworker-provider.d.ts.map \ No newline at end of file diff --git a/dist/esm/validation/cfworker-provider.d.ts.map b/dist/esm/validation/cfworker-provider.d.ts.map new file mode 100644 index 000000000..ce404d92f --- /dev/null +++ b/dist/esm/validation/cfworker-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"cfworker-provider.d.ts","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAA6B,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACnE,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAsB;IAEnC;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,mBAAmB,CAAA;KAAE;IAK7E;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAsBlE"} \ No newline at end of file diff --git a/dist/esm/validation/cfworker-provider.js b/dist/esm/validation/cfworker-provider.js new file mode 100644 index 000000000..d55ef011e --- /dev/null +++ b/dist/esm/validation/cfworker-provider.js @@ -0,0 +1,66 @@ +/** + * Cloudflare Worker-compatible JSON Schema validator provider + * + * This provider uses @cfworker/json-schema for validation without code generation, + * making it compatible with edge runtimes like Cloudflare Workers that restrict + * eval and new Function. + */ +import { Validator } from '@cfworker/json-schema'; +/** + * + * @example + * ```typescript + * // Use with default configuration (2020-12, shortcircuit) + * const validator = new CfWorkerJsonSchemaValidator(); + * + * // Use with custom configuration + * const validator = new CfWorkerJsonSchemaValidator({ + * draft: '2020-12', + * shortcircuit: false // Report all errors + * }); + * ``` + */ +export class CfWorkerJsonSchemaValidator { + /** + * Create a validator + * + * @param options - Configuration options + * @param options.shortcircuit - If true, stop validation after first error (default: true) + * @param options.draft - JSON Schema draft version to use (default: '2020-12') + */ + constructor(options) { + var _a, _b; + this.shortcircuit = (_a = options === null || options === void 0 ? void 0 : options.shortcircuit) !== null && _a !== void 0 ? _a : true; + this.draft = (_b = options === null || options === void 0 ? void 0 : options.draft) !== null && _b !== void 0 ? _b : '2020-12'; + } + /** + * Create a validator for the given JSON Schema + * + * Unlike AJV, this validator is not cached internally + * + * @param schema - Standard JSON Schema object + * @returns A validator function that validates input data + */ + getValidator(schema) { + const cfSchema = schema; + const validator = new Validator(cfSchema, this.draft, this.shortcircuit); + return (input) => { + const result = validator.validate(input); + if (result.valid) { + return { + valid: true, + data: input, + errorMessage: undefined + }; + } + else { + return { + valid: false, + data: undefined, + errorMessage: result.errors.map(err => `${err.instanceLocation}: ${err.error}`).join('; ') + }; + } + }; + } +} +//# sourceMappingURL=cfworker-provider.js.map \ No newline at end of file diff --git a/dist/esm/validation/cfworker-provider.js.map b/dist/esm/validation/cfworker-provider.js.map new file mode 100644 index 000000000..0f0e1799f --- /dev/null +++ b/dist/esm/validation/cfworker-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cfworker-provider.js","sourceRoot":"","sources":["../../../src/validation/cfworker-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQ/D;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,2BAA2B;IAIpC;;;;;;OAMG;IACH,YAAY,OAAiE;;QACzE,IAAI,CAAC,YAAY,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,IAAI,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,SAAS,CAAC;IAC7C,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CAAI,MAAsB;QAClC,MAAM,QAAQ,GAAG,MAA2B,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAEzE,OAAO,CAAC,KAAc,EAAgC,EAAE;YACpD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEzC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAU;oBAChB,YAAY,EAAE,SAAS;iBAC1B,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO;oBACH,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,SAAS;oBACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,gBAAgB,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC7F,CAAC;YACN,CAAC;QACL,CAAC,CAAC;IACN,CAAC;CACJ"} \ No newline at end of file diff --git a/dist/esm/validation/index.d.ts b/dist/esm/validation/index.d.ts new file mode 100644 index 000000000..99e993967 --- /dev/null +++ b/dist/esm/validation/index.d.ts @@ -0,0 +1,29 @@ +/** + * JSON Schema validation + * + * This module provides configurable JSON Schema validation for the MCP SDK. + * Choose a validator based on your runtime environment: + * + * - AjvJsonSchemaValidator: Best for Node.js (default, fastest) + * Import from: @modelcontextprotocol/sdk/validation/ajv + * Requires peer dependencies: ajv, ajv-formats + * + * - CfWorkerJsonSchemaValidator: Best for edge runtimes + * Import from: @modelcontextprotocol/sdk/validation/cfworker + * Requires peer dependency: @cfworker/json-schema + * + * @example + * ```typescript + * // For Node.js with AJV + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // For Cloudflare Workers + * import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker'; + * const validator = new CfWorkerJsonSchemaValidator(); + * ``` + * + * @module validation + */ +export type { JsonSchemaType, JsonSchemaValidator, JsonSchemaValidatorResult, jsonSchemaValidator } from './types.js'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/validation/index.d.ts.map b/dist/esm/validation/index.d.ts.map new file mode 100644 index 000000000..a8845b96e --- /dev/null +++ b/dist/esm/validation/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/esm/validation/index.js b/dist/esm/validation/index.js new file mode 100644 index 000000000..685b1fd45 --- /dev/null +++ b/dist/esm/validation/index.js @@ -0,0 +1,29 @@ +/** + * JSON Schema validation + * + * This module provides configurable JSON Schema validation for the MCP SDK. + * Choose a validator based on your runtime environment: + * + * - AjvJsonSchemaValidator: Best for Node.js (default, fastest) + * Import from: @modelcontextprotocol/sdk/validation/ajv + * Requires peer dependencies: ajv, ajv-formats + * + * - CfWorkerJsonSchemaValidator: Best for edge runtimes + * Import from: @modelcontextprotocol/sdk/validation/cfworker + * Requires peer dependency: @cfworker/json-schema + * + * @example + * ```typescript + * // For Node.js with AJV + * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv'; + * const validator = new AjvJsonSchemaValidator(); + * + * // For Cloudflare Workers + * import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker'; + * const validator = new CfWorkerJsonSchemaValidator(); + * ``` + * + * @module validation + */ +export {}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/validation/index.js.map b/dist/esm/validation/index.js.map new file mode 100644 index 000000000..ed2b9fc23 --- /dev/null +++ b/dist/esm/validation/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"} \ No newline at end of file diff --git a/dist/esm/validation/types.d.ts b/dist/esm/validation/types.d.ts new file mode 100644 index 000000000..5872215c7 --- /dev/null +++ b/dist/esm/validation/types.d.ts @@ -0,0 +1,55 @@ +import type { Schema } from '@cfworker/json-schema'; +/** + * Result of a JSON Schema validation operation + */ +export type JsonSchemaValidatorResult = { + valid: true; + data: T; + errorMessage: undefined; +} | { + valid: false; + data: undefined; + errorMessage: string; +}; +/** + * A validator function that validates data against a JSON Schema + */ +export type JsonSchemaValidator = (input: unknown) => JsonSchemaValidatorResult; +/** + * Provider interface for creating validators from JSON Schemas + * + * This is the main extension point for custom validator implementations. + * Implementations should: + * - Support JSON Schema Draft 2020-12 (or be compatible with it) + * - Return validator functions that can be called multiple times + * - Handle schema compilation/caching internally + * - Provide clear error messages on validation failure + * + * @example + * ```typescript + * class MyValidatorProvider implements jsonSchemaValidator { + * getValidator(schema: JsonSchemaType): JsonSchemaValidator { + * // Compile/cache validator from schema + * return (input: unknown) => { + * // Validate input against schema + * if (valid) { + * return { valid: true, data: input as T, errorMessage: undefined }; + * } else { + * return { valid: false, data: undefined, errorMessage: 'Error details' }; + * } + * }; + * } + * } + * ``` + */ +export interface jsonSchemaValidator { + /** + * Create a validator for the given JSON Schema + * + * @param schema - Standard JSON Schema object + * @returns A validator function that can be called multiple times + */ + getValidator(schema: JsonSchemaType): JsonSchemaValidator; +} +export type JsonSchemaType = Schema; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/esm/validation/types.d.ts.map b/dist/esm/validation/types.d.ts.map new file mode 100644 index 000000000..3bdf64e58 --- /dev/null +++ b/dist/esm/validation/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACjC;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,GACjD;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/esm/validation/types.js b/dist/esm/validation/types.js new file mode 100644 index 000000000..718fd38ae --- /dev/null +++ b/dist/esm/validation/types.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/esm/validation/types.js.map b/dist/esm/validation/types.js.map new file mode 100644 index 000000000..51361cf6a --- /dev/null +++ b/dist/esm/validation/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/package.json b/package.json index 545994806..df5aeae3c 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,18 @@ { - "name": "@modelcontextprotocol/sdk", - "version": "1.23.0", - "description": "Model Context Protocol implementation for TypeScript", + "name": "@anthropic-advisori/mcp-sdk", + "version": "1.23.0-sessionstore.1", + "description": "Model Context Protocol implementation for TypeScript - Fork with SessionStore support for distributed deployments", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", + "contributors": [ + "Advisori GmbH - SessionStore extension for multi-pod support" + ], "homepage": "https://modelcontextprotocol.io", "bugs": "https://github.com/modelcontextprotocol/typescript-sdk/issues", "type": "module", "repository": { "type": "git", - "url": "git+https://github.com/modelcontextprotocol/typescript-sdk.git" + "url": "git+https://github.com/anthropic-advisori/mcp-typescript-sdk.git" }, "engines": { "node": ">=18" @@ -51,6 +54,14 @@ "import": "./dist/esm/experimental/tasks/index.js", "require": "./dist/cjs/experimental/tasks/index.js" }, + "./server/session-stores": { + "import": "./dist/esm/server/session-stores/index.js", + "require": "./dist/cjs/server/session-stores/index.js" + }, + "./server/session-stores/redis": { + "import": "./dist/esm/server/session-stores/redis.js", + "require": "./dist/cjs/server/session-stores/redis.js" + }, "./*": { "import": "./dist/esm/*", "require": "./dist/cjs/*" diff --git a/src/server/index.ts b/src/server/index.ts index dfbb2a2a3..3cf2f246c 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -633,3 +633,8 @@ export class Server< return this.notification({ method: 'notifications/prompts/list_changed' }); } } + +// Re-export session store types and implementations +export type { SessionStore, SessionData, SessionStorageMode } from './streamableHttp.js'; +export { RedisSessionStore, InMemorySessionStore } from './session-stores/redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './session-stores/redis.js'; diff --git a/src/server/session-stores/index.ts b/src/server/session-stores/index.ts new file mode 100644 index 000000000..506044767 --- /dev/null +++ b/src/server/session-stores/index.ts @@ -0,0 +1,6 @@ +/** + * Session Store implementations for distributed MCP deployments + */ + +export { RedisSessionStore, InMemorySessionStore } from './redis.js'; +export type { RedisClient, RedisSessionStoreOptions } from './redis.js'; diff --git a/src/server/session-stores/redis.test.ts b/src/server/session-stores/redis.test.ts new file mode 100644 index 000000000..c5388723e --- /dev/null +++ b/src/server/session-stores/redis.test.ts @@ -0,0 +1,376 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { RedisSessionStore, InMemorySessionStore, RedisClient } from './redis.js'; +import { SessionData } from '../streamableHttp.js'; + +/** + * Mock Redis Client for testing + */ +function createMockRedisClient(): RedisClient & { + _store: Map; + _getKey: (key: string) => { value: string; expiry: number } | undefined; +} { + const store = new Map(); + + return { + _store: store, + _getKey: (key: string) => store.get(key), + + async get(key: string): Promise { + const entry = store.get(key); + if (!entry) return null; + // Check expiry + if (entry.expiry > 0 && Date.now() > entry.expiry) { + store.delete(key); + return null; + } + return entry.value; + }, + + async setex(key: string, seconds: number, value: string): Promise<'OK'> { + store.set(key, { + value, + expiry: Date.now() + seconds * 1000 + }); + return 'OK'; + }, + + async del(key: string | string[]): Promise { + const keys = Array.isArray(key) ? key : [key]; + let deleted = 0; + for (const k of keys) { + if (store.delete(k)) deleted++; + } + return deleted; + }, + + async exists(key: string | string[]): Promise { + const keys = Array.isArray(key) ? key : [key]; + let count = 0; + for (const k of keys) { + const entry = store.get(k); + if (entry && (entry.expiry === 0 || Date.now() <= entry.expiry)) { + count++; + } + } + return count; + }, + + async expire(key: string, seconds: number): Promise { + const entry = store.get(key); + if (!entry) return 0; + entry.expiry = Date.now() + seconds * 1000; + return 1; + } + }; +} + +describe('RedisSessionStore', () => { + let mockRedis: ReturnType; + let sessionStore: RedisSessionStore; + const testSessionId = 'test-session-123'; + + beforeEach(() => { + mockRedis = createMockRedisClient(); + sessionStore = new RedisSessionStore({ + redis: mockRedis, + keyPrefix: 'mcp:test:session:', + ttlSeconds: 3600 + }); + }); + + describe('storeSession', () => { + it('should store session data in Redis', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + + const stored = mockRedis._getKey(`mcp:test:session:${testSessionId}`); + expect(stored).toBeDefined(); + expect(JSON.parse(stored!.value)).toEqual(sessionData); + }); + + it('should set TTL when storing session', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + + const stored = mockRedis._getKey(`mcp:test:session:${testSessionId}`); + expect(stored).toBeDefined(); + // TTL should be approximately 3600 seconds from now + const expectedExpiry = Date.now() + 3600 * 1000; + expect(stored!.expiry).toBeGreaterThan(expectedExpiry - 1000); + expect(stored!.expiry).toBeLessThan(expectedExpiry + 1000); + }); + + it('should store session with metadata', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now(), + metadata: { serverId: 'server-1', userId: 'user-123' } + }; + + await sessionStore.storeSession(testSessionId, sessionData); + + const retrieved = await sessionStore.getSession(testSessionId); + expect(retrieved?.metadata).toEqual({ serverId: 'server-1', userId: 'user-123' }); + }); + }); + + describe('getSession', () => { + it('should retrieve stored session', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: 1000, + lastActivity: 2000 + }; + + await sessionStore.storeSession(testSessionId, sessionData); + const retrieved = await sessionStore.getSession(testSessionId); + + expect(retrieved).toEqual(sessionData); + }); + + it('should return null for non-existent session', async () => { + const retrieved = await sessionStore.getSession('non-existent'); + expect(retrieved).toBeNull(); + }); + + it('should return null for expired session', async () => { + // Create a store with 1 second TTL + const shortTtlStore = new RedisSessionStore({ + redis: mockRedis, + ttlSeconds: 0 // Immediate expiry for test + }); + + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + // Manually set expired data + mockRedis._store.set(`mcp:session:${testSessionId}`, { + value: JSON.stringify(sessionData), + expiry: Date.now() - 1000 // Already expired + }); + + const retrieved = await shortTtlStore.getSession(testSessionId); + expect(retrieved).toBeNull(); + }); + }); + + describe('updateSessionActivity', () => { + it('should update lastActivity timestamp', async () => { + const originalTime = Date.now() - 10000; + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: originalTime, + lastActivity: originalTime + }; + + await sessionStore.storeSession(testSessionId, sessionData); + + // Wait a bit to ensure time difference + await new Promise(resolve => setTimeout(resolve, 10)); + + await sessionStore.updateSessionActivity(testSessionId); + + const retrieved = await sessionStore.getSession(testSessionId); + expect(retrieved?.lastActivity).toBeGreaterThan(originalTime); + expect(retrieved?.createdAt).toBe(originalTime); // Should not change + }); + + it('should not throw for non-existent session', async () => { + // Should not throw + await expect(sessionStore.updateSessionActivity('non-existent')).resolves.not.toThrow(); + }); + }); + + describe('deleteSession', () => { + it('should delete session from Redis', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + expect(await sessionStore.sessionExists(testSessionId)).toBe(true); + + await sessionStore.deleteSession(testSessionId); + + expect(await sessionStore.sessionExists(testSessionId)).toBe(false); + expect(await sessionStore.getSession(testSessionId)).toBeNull(); + }); + + it('should not throw when deleting non-existent session', async () => { + await expect(sessionStore.deleteSession('non-existent')).resolves.not.toThrow(); + }); + }); + + describe('sessionExists', () => { + it('should return true for existing session', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + expect(await sessionStore.sessionExists(testSessionId)).toBe(true); + }); + + it('should return false for non-existent session', async () => { + expect(await sessionStore.sessionExists('non-existent')).toBe(false); + }); + }); + + describe('custom key prefix', () => { + it('should use custom key prefix', async () => { + const customStore = new RedisSessionStore({ + redis: mockRedis, + keyPrefix: 'custom:prefix:', + ttlSeconds: 3600 + }); + + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await customStore.storeSession(testSessionId, sessionData); + + expect(mockRedis._getKey(`custom:prefix:${testSessionId}`)).toBeDefined(); + expect(mockRedis._getKey(`mcp:session:${testSessionId}`)).toBeUndefined(); + }); + }); + + describe('logging callback', () => { + it('should call onLog callback', async () => { + const logSpy = vi.fn(); + const loggingStore = new RedisSessionStore({ + redis: mockRedis, + onLog: logSpy + }); + + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await loggingStore.storeSession(testSessionId, sessionData); + + expect(logSpy).toHaveBeenCalledWith('debug', expect.stringContaining('Session stored')); + }); + }); +}); + +describe('InMemorySessionStore', () => { + let sessionStore: InMemorySessionStore; + const testSessionId = 'test-session-456'; + + beforeEach(() => { + sessionStore = new InMemorySessionStore(3600); + }); + + describe('basic operations', () => { + it('should store and retrieve session', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + const retrieved = await sessionStore.getSession(testSessionId); + + expect(retrieved).toEqual(sessionData); + }); + + it('should delete session', async () => { + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + await sessionStore.deleteSession(testSessionId); + + expect(await sessionStore.getSession(testSessionId)).toBeNull(); + }); + + it('should check session existence', async () => { + expect(await sessionStore.sessionExists(testSessionId)).toBe(false); + + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() + }; + + await sessionStore.storeSession(testSessionId, sessionData); + expect(await sessionStore.sessionExists(testSessionId)).toBe(true); + }); + + it('should update session activity', async () => { + const originalTime = Date.now() - 10000; + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: originalTime, + lastActivity: originalTime + }; + + await sessionStore.storeSession(testSessionId, sessionData); + await sessionStore.updateSessionActivity(testSessionId); + + const retrieved = await sessionStore.getSession(testSessionId); + expect(retrieved?.lastActivity).toBeGreaterThan(originalTime); + }); + }); + + describe('TTL behavior', () => { + it('should expire sessions after TTL', async () => { + // Create store with very short TTL (100ms) + const shortTtlStore = new InMemorySessionStore(0.1); // 0.1 seconds = 100ms + + const sessionData: SessionData = { + sessionId: testSessionId, + initialized: true, + createdAt: Date.now(), + lastActivity: Date.now() - 200 // Already past TTL + }; + + await shortTtlStore.storeSession(testSessionId, sessionData); + + // Session should be considered expired + const retrieved = await shortTtlStore.getSession(testSessionId); + expect(retrieved).toBeNull(); + }); + }); +}); diff --git a/src/server/session-stores/redis.ts b/src/server/session-stores/redis.ts new file mode 100644 index 000000000..61a2deaac --- /dev/null +++ b/src/server/session-stores/redis.ts @@ -0,0 +1,249 @@ +/** + * Redis Session Store Implementation + * + * This module provides a Redis-based implementation of the SessionStore interface + * for distributed MCP server deployments. + * + * Usage: + * ```typescript + * import Redis from 'ioredis'; + * import { RedisSessionStore } from '@modelcontextprotocol/sdk/server/session-stores/redis.js'; + * import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; + * + * const redis = new Redis({ + * host: 'redis.example.com', + * port: 6379, + * password: 'your-password' + * }); + * + * const sessionStore = new RedisSessionStore({ + * redis, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 // 1 hour + * }); + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore + * }); + * ``` + */ + +import { SessionStore, SessionData } from '../streamableHttp.js'; + +/** + * Generic Redis client interface + * Compatible with ioredis, node-redis, and other Redis clients + */ +export interface RedisClient { + get(key: string): Promise; + setex(key: string, seconds: number, value: string): Promise; + del(key: string | string[]): Promise; + exists(key: string | string[]): Promise; + expire(key: string, seconds: number): Promise; +} + +/** + * Configuration options for RedisSessionStore + */ +export interface RedisSessionStoreOptions { + /** + * Redis client instance (ioredis, node-redis, or compatible) + */ + redis: RedisClient; + + /** + * Key prefix for session data in Redis + * @default 'mcp:session:' + */ + keyPrefix?: string; + + /** + * Session TTL in seconds + * @default 3600 (1 hour) + */ + ttlSeconds?: number; + + /** + * Optional callback for logging + */ + onLog?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: unknown[]) => void; +} + +/** + * Redis-based session store for distributed MCP deployments + * + * Features: + * - Automatic TTL management with activity-based refresh + * - Cross-pod session sharing + * - Graceful handling of Redis connection issues + */ +export class RedisSessionStore implements SessionStore { + private readonly redis: RedisClient; + private readonly keyPrefix: string; + private readonly ttlSeconds: number; + private readonly log: (level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: unknown[]) => void; + + constructor(options: RedisSessionStoreOptions) { + this.redis = options.redis; + this.keyPrefix = options.keyPrefix ?? 'mcp:session:'; + this.ttlSeconds = options.ttlSeconds ?? 3600; + this.log = options.onLog ?? (() => {}); + } + + /** + * Get the Redis key for a session + */ + private getKey(sessionId: string): string { + return `${this.keyPrefix}${sessionId}`; + } + + /** + * Store session data in Redis + */ + async storeSession(sessionId: string, data: SessionData): Promise { + try { + const key = this.getKey(sessionId); + const serialized = JSON.stringify(data); + await this.redis.setex(key, this.ttlSeconds, serialized); + this.log('debug', `Session stored: ${sessionId}`); + } catch (error) { + this.log('error', `Failed to store session ${sessionId}:`, error); + throw error; + } + } + + /** + * Retrieve session data from Redis + */ + async getSession(sessionId: string): Promise { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + + if (!data) { + this.log('debug', `Session not found: ${sessionId}`); + return null; + } + + const parsed = JSON.parse(data) as SessionData; + this.log('debug', `Session retrieved: ${sessionId}`); + return parsed; + } catch (error) { + this.log('error', `Failed to get session ${sessionId}:`, error); + throw error; + } + } + + /** + * Update session activity timestamp and refresh TTL + */ + async updateSessionActivity(sessionId: string): Promise { + try { + const key = this.getKey(sessionId); + const data = await this.redis.get(key); + + if (!data) { + this.log('warn', `Cannot update activity for non-existent session: ${sessionId}`); + return; + } + + const parsed = JSON.parse(data) as SessionData; + parsed.lastActivity = Date.now(); + + await this.redis.setex(key, this.ttlSeconds, JSON.stringify(parsed)); + this.log('debug', `Session activity updated: ${sessionId}`); + } catch (error) { + this.log('error', `Failed to update session activity ${sessionId}:`, error); + // Don't throw - activity update failures shouldn't break the request + } + } + + /** + * Delete a session from Redis + */ + async deleteSession(sessionId: string): Promise { + try { + const key = this.getKey(sessionId); + await this.redis.del(key); + this.log('debug', `Session deleted: ${sessionId}`); + } catch (error) { + this.log('error', `Failed to delete session ${sessionId}:`, error); + throw error; + } + } + + /** + * Check if a session exists in Redis + */ + async sessionExists(sessionId: string): Promise { + try { + const key = this.getKey(sessionId); + const exists = await this.redis.exists(key); + return exists === 1; + } catch (error) { + this.log('error', `Failed to check session existence ${sessionId}:`, error); + throw error; + } + } +} + +/** + * In-Memory Session Store (for development/testing) + * + * NOT suitable for production multi-pod deployments! + * Use RedisSessionStore or implement your own SessionStore for production. + */ +export class InMemorySessionStore implements SessionStore { + private sessions: Map = new Map(); + private readonly ttlMs: number; + + constructor(ttlSeconds: number = 3600) { + this.ttlMs = ttlSeconds * 1000; + + // Cleanup expired sessions every minute + setInterval(() => this.cleanup(), 60000); + } + + async storeSession(sessionId: string, data: SessionData): Promise { + this.sessions.set(sessionId, data); + } + + async getSession(sessionId: string): Promise { + const data = this.sessions.get(sessionId); + if (!data) return null; + + // Check if expired + if (Date.now() - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + return null; + } + + return data; + } + + async updateSessionActivity(sessionId: string): Promise { + const data = this.sessions.get(sessionId); + if (data) { + data.lastActivity = Date.now(); + } + } + + async deleteSession(sessionId: string): Promise { + this.sessions.delete(sessionId); + } + + async sessionExists(sessionId: string): Promise { + const data = await this.getSession(sessionId); + return data !== null; + } + + private cleanup(): void { + const now = Date.now(); + for (const [sessionId, data] of this.sessions) { + if (now - data.lastActivity > this.ttlMs) { + this.sessions.delete(sessionId); + } + } + } +} diff --git a/src/server/streamableHttp.test.ts b/src/server/streamableHttp.test.ts index 80ee04d67..7da93d3e1 100644 --- a/src/server/streamableHttp.test.ts +++ b/src/server/streamableHttp.test.ts @@ -2438,3 +2438,506 @@ async function createTestServerWithDnsProtection(config: { baseUrl: serverUrl }; } + +/** + * Tests for SessionStore support in StreamableHTTPServerTransport + * These tests validate the external session storage functionality for multi-pod deployments + */ +import { SessionStore, SessionData, SessionStorageMode } from './streamableHttp.js'; +import { InMemorySessionStore } from './session-stores/redis.js'; + +describe('StreamableHTTPServerTransport with SessionStore', () => { + /** + * Mock SessionStore for testing + */ + class MockSessionStore implements SessionStore { + private sessions = new Map(); + public storeSessionCalls: Array<{ sessionId: string; data: SessionData }> = []; + public getSessionCalls: string[] = []; + public updateActivityCalls: string[] = []; + public deleteSessionCalls: string[] = []; + public sessionExistsCalls: string[] = []; + + async storeSession(sessionId: string, data: SessionData): Promise { + this.storeSessionCalls.push({ sessionId, data }); + this.sessions.set(sessionId, { ...data }); + } + + async getSession(sessionId: string): Promise { + this.getSessionCalls.push(sessionId); + const data = this.sessions.get(sessionId); + return data ? { ...data } : null; + } + + async updateSessionActivity(sessionId: string): Promise { + this.updateActivityCalls.push(sessionId); + const data = this.sessions.get(sessionId); + if (data) { + data.lastActivity = Date.now(); + this.sessions.set(sessionId, data); + } + } + + async deleteSession(sessionId: string): Promise { + this.deleteSessionCalls.push(sessionId); + this.sessions.delete(sessionId); + } + + async sessionExists(sessionId: string): Promise { + this.sessionExistsCalls.push(sessionId); + return this.sessions.has(sessionId); + } + + // Helper for tests + clear(): void { + this.sessions.clear(); + this.storeSessionCalls = []; + this.getSessionCalls = []; + this.updateActivityCalls = []; + this.deleteSessionCalls = []; + this.sessionExistsCalls = []; + } + } + + describe('SessionStorageMode configuration', () => { + it('should default to memory mode when no sessionStore provided', () => { + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID() + }); + + expect(transport.sessionStorageMode).toBe('memory'); + expect(transport.isUsingExternalSessionStore).toBe(false); + }); + + it('should use external mode when sessionStore is provided without explicit mode', () => { + const mockStore = new MockSessionStore(); + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStore: mockStore + }); + + // When sessionStore is provided, mode should still default to 'memory' + // unless explicitly set to 'external' + expect(transport.sessionStorageMode).toBe('memory'); + }); + + it('should use external mode when explicitly set with sessionStore', () => { + const mockStore = new MockSessionStore(); + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', + sessionStore: mockStore + }); + + expect(transport.sessionStorageMode).toBe('external'); + expect(transport.isUsingExternalSessionStore).toBe(true); + }); + + it('should throw error when external mode is set without sessionStore', () => { + expect(() => { + new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external' + // No sessionStore provided + }); + }).toThrow('SessionStore is required when sessionStorageMode is "external"'); + }); + + it('should allow memory mode explicitly', () => { + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'memory' + }); + + expect(transport.sessionStorageMode).toBe('memory'); + expect(transport.isUsingExternalSessionStore).toBe(false); + }); + + it('should allow memory mode with sessionStore (for flexibility)', () => { + const mockStore = new MockSessionStore(); + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'memory', + sessionStore: mockStore // Provided but not used in memory mode + }); + + expect(transport.sessionStorageMode).toBe('memory'); + expect(transport.isUsingExternalSessionStore).toBe(false); + }); + }); + + describe('External session storage integration', () => { + let server: Server; + let transport: StreamableHTTPServerTransport; + let baseUrl: URL; + let mockStore: MockSessionStore; + let mcpServer: McpServer; + + async function createTestServerWithSessionStore(): Promise { + mockStore = new MockSessionStore(); + mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); + + transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', + sessionStore: mockStore + }); + + await mcpServer.connect(transport); + + server = createServer(async (req, res) => { + try { + await transport.handleRequest(req, res); + } catch (error) { + console.error('Error handling request:', error); + if (!res.headersSent) res.writeHead(500).end(); + } + }); + + baseUrl = await new Promise(resolve => { + server.listen(0, '127.0.0.1', () => { + const addr = server.address() as AddressInfo; + resolve(new URL(`http://127.0.0.1:${addr.port}`)); + }); + }); + } + + beforeEach(async () => { + await createTestServerWithSessionStore(); + }); + + afterEach(async () => { + await transport.close(); + server.close(); + }); + + const TEST_INIT_MESSAGE: JSONRPCMessage = { + jsonrpc: '2.0', + method: 'initialize', + params: { + clientInfo: { name: 'test-client', version: '1.0' }, + protocolVersion: '2025-03-26', + capabilities: {} + }, + id: 'init-1' + }; + + it('should store session in external store on initialization', async () => { + const response = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify(TEST_INIT_MESSAGE) + }); + + expect(response.status).toBe(200); + const sessionId = response.headers.get('mcp-session-id'); + expect(sessionId).toBeDefined(); + + // Verify session was stored in external store + expect(mockStore.storeSessionCalls.length).toBeGreaterThan(0); + const lastStoreCall = mockStore.storeSessionCalls[mockStore.storeSessionCalls.length - 1]; + expect(lastStoreCall.sessionId).toBe(sessionId); + expect(lastStoreCall.data.initialized).toBe(true); + expect(lastStoreCall.data.sessionId).toBe(sessionId); + }); + + it('should validate session against external store', async () => { + // Initialize first + const initResponse = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify(TEST_INIT_MESSAGE) + }); + + const sessionId = initResponse.headers.get('mcp-session-id')!; + + // Make a subsequent request + const toolsRequest: JSONRPCMessage = { + jsonrpc: '2.0', + method: 'tools/list', + params: {}, + id: 'tools-1' + }; + + const response = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + 'mcp-session-id': sessionId, + 'mcp-protocol-version': '2025-03-26' + }, + body: JSON.stringify(toolsRequest) + }); + + expect(response.status).toBe(200); + + // Verify getSession was called to validate + expect(mockStore.getSessionCalls).toContain(sessionId); + }); + + it('should update session activity on requests', async () => { + // Initialize first + const initResponse = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify(TEST_INIT_MESSAGE) + }); + + const sessionId = initResponse.headers.get('mcp-session-id')!; + + // Make a subsequent request + const toolsRequest: JSONRPCMessage = { + jsonrpc: '2.0', + method: 'tools/list', + params: {}, + id: 'tools-1' + }; + + await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + 'mcp-session-id': sessionId, + 'mcp-protocol-version': '2025-03-26' + }, + body: JSON.stringify(toolsRequest) + }); + + // Verify updateSessionActivity was called + expect(mockStore.updateActivityCalls).toContain(sessionId); + }); + + it('should delete session from external store on DELETE', async () => { + // Initialize first + const initResponse = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify(TEST_INIT_MESSAGE) + }); + + const sessionId = initResponse.headers.get('mcp-session-id')!; + + // DELETE the session + const deleteResponse = await fetch(baseUrl, { + method: 'DELETE', + headers: { + 'mcp-session-id': sessionId, + 'mcp-protocol-version': '2025-03-26' + } + }); + + expect(deleteResponse.status).toBe(200); + + // Verify deleteSession was called + expect(mockStore.deleteSessionCalls).toContain(sessionId); + }); + + it('should reject requests with invalid session ID in external mode', async () => { + // Initialize to activate the server + await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify(TEST_INIT_MESSAGE) + }); + + // Try with an invalid session ID + const toolsRequest: JSONRPCMessage = { + jsonrpc: '2.0', + method: 'tools/list', + params: {}, + id: 'tools-1' + }; + + const response = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + 'mcp-session-id': 'invalid-session-id', + 'mcp-protocol-version': '2025-03-26' + }, + body: JSON.stringify(toolsRequest) + }); + + expect(response.status).toBe(404); + const errorData = await response.json(); + expect(errorData.error.message).toMatch(/Session not found/); + }); + }); + + describe('Cross-pod session recovery simulation', () => { + it('should recover session from external store (simulating different pod)', async () => { + // This test simulates what happens when a request comes to a different pod + // that doesn't have the session in memory but it exists in the external store + + const mockStore = new MockSessionStore(); + const sessionId = 'pre-existing-session-123'; + + // Pre-populate the external store (simulating session created on Pod A) + await mockStore.storeSession(sessionId, { + sessionId, + initialized: true, + createdAt: Date.now() - 60000, // Created 1 minute ago + lastActivity: Date.now() - 30000 // Last activity 30 seconds ago + }); + + // Create a new transport (simulating Pod B that never saw this session) + const mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); + + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', + sessionStore: mockStore + }); + + await mcpServer.connect(transport); + + const server = createServer(async (req, res) => { + try { + await transport.handleRequest(req, res); + } catch (error) { + console.error('Error handling request:', error); + if (!res.headersSent) res.writeHead(500).end(); + } + }); + + const baseUrl = await new Promise(resolve => { + server.listen(0, '127.0.0.1', () => { + const addr = server.address() as AddressInfo; + resolve(new URL(`http://127.0.0.1:${addr.port}`)); + }); + }); + + try { + // First initialize (required by protocol) + await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'initialize', + params: { + clientInfo: { name: 'test-client', version: '1.0' }, + protocolVersion: '2025-03-26', + capabilities: {} + }, + id: 'init-1' + }) + }); + + // Now try to use the pre-existing session + const toolsRequest: JSONRPCMessage = { + jsonrpc: '2.0', + method: 'tools/list', + params: {}, + id: 'tools-1' + }; + + const response = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream', + 'mcp-session-id': sessionId, + 'mcp-protocol-version': '2025-03-26' + }, + body: JSON.stringify(toolsRequest) + }); + + // Session should be recovered from external store + expect(response.status).toBe(200); + + // Verify the store was queried + expect(mockStore.getSessionCalls).toContain(sessionId); + } finally { + await transport.close(); + server.close(); + } + }); + }); + + describe('InMemorySessionStore integration', () => { + it('should work with InMemorySessionStore for development/testing', async () => { + const inMemoryStore = new InMemorySessionStore(3600); + + const mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); + + const transport = new StreamableHTTPServerTransport({ + sessionIdGenerator: () => randomUUID(), + sessionStorageMode: 'external', + sessionStore: inMemoryStore + }); + + await mcpServer.connect(transport); + + const server = createServer(async (req, res) => { + try { + await transport.handleRequest(req, res); + } catch (error) { + console.error('Error handling request:', error); + if (!res.headersSent) res.writeHead(500).end(); + } + }); + + const baseUrl = await new Promise(resolve => { + server.listen(0, '127.0.0.1', () => { + const addr = server.address() as AddressInfo; + resolve(new URL(`http://127.0.0.1:${addr.port}`)); + }); + }); + + try { + // Initialize + const initResponse = await fetch(baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json, text/event-stream' + }, + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'initialize', + params: { + clientInfo: { name: 'test-client', version: '1.0' }, + protocolVersion: '2025-03-26', + capabilities: {} + }, + id: 'init-1' + }) + }); + + expect(initResponse.status).toBe(200); + const sessionId = initResponse.headers.get('mcp-session-id'); + expect(sessionId).toBeDefined(); + + // Verify session exists in store + expect(await inMemoryStore.sessionExists(sessionId!)).toBe(true); + const sessionData = await inMemoryStore.getSession(sessionId!); + expect(sessionData?.initialized).toBe(true); + } finally { + await transport.close(); + server.close(); + } + }); + }); +}); diff --git a/src/server/streamableHttp.ts b/src/server/streamableHttp.ts index 4514e619c..5447ead0f 100644 --- a/src/server/streamableHttp.ts +++ b/src/server/streamableHttp.ts @@ -55,6 +55,114 @@ export interface EventStore { ): Promise; } +/** + * Session data structure for distributed session storage + */ +export interface SessionData { + /** + * The unique session identifier + */ + sessionId: string; + + /** + * Whether the session has been initialized (received initialize request) + */ + initialized: boolean; + + /** + * Timestamp when the session was created (Unix ms) + */ + createdAt: number; + + /** + * Timestamp of last activity (Unix ms) + */ + lastActivity: number; + + /** + * Optional metadata for custom use cases (e.g., serverId, userId) + */ + metadata?: Record; +} + +/** + * Interface for distributed session storage (e.g., Redis, PostgreSQL, etc.) + * + * This interface enables multi-node/multi-pod deployments where session state + * must be shared across multiple server instances. Without this, sessions are + * stored in-memory and requests routed to different pods will fail. + * + * Usage example with Redis: + * ```typescript + * const sessionStore: SessionStore = { + * async storeSession(sessionId, data) { + * await redis.setex(`mcp:session:${sessionId}`, 3600, JSON.stringify(data)); + * }, + * async getSession(sessionId) { + * const data = await redis.get(`mcp:session:${sessionId}`); + * return data ? JSON.parse(data) : null; + * }, + * async updateSessionActivity(sessionId) { + * const data = await this.getSession(sessionId); + * if (data) { + * data.lastActivity = Date.now(); + * await this.storeSession(sessionId, data); + * } + * }, + * async deleteSession(sessionId) { + * await redis.del(`mcp:session:${sessionId}`); + * }, + * async sessionExists(sessionId) { + * return await redis.exists(`mcp:session:${sessionId}`) === 1; + * } + * }; + * + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: sessionStore + * }); + * ``` + */ +export interface SessionStore { + /** + * Store session data + * @param sessionId The session identifier + * @param data The session data to store + */ + storeSession(sessionId: string, data: SessionData): Promise; + + /** + * Retrieve session data + * @param sessionId The session identifier + * @returns The session data, or null if not found + */ + getSession(sessionId: string): Promise; + + /** + * Update session activity timestamp (e.g., refresh TTL) + * @param sessionId The session identifier + */ + updateSessionActivity(sessionId: string): Promise; + + /** + * Delete a session + * @param sessionId The session identifier + */ + deleteSession(sessionId: string): Promise; + + /** + * Check if a session exists + * @param sessionId The session identifier + * @returns true if the session exists + */ + sessionExists(sessionId: string): Promise; +} + +/** + * Session storage mode for the transport + */ +export type SessionStorageMode = 'memory' | 'external'; + /** * Configuration options for StreamableHTTPServerTransport */ @@ -101,6 +209,47 @@ export interface StreamableHTTPServerTransportOptions { */ eventStore?: EventStore; + /** + * Session storage mode - explicitly choose between in-memory and external storage. + * + * - 'memory': Sessions stored in process memory (single-node only, default) + * - 'external': Sessions stored in external store (requires sessionStore option) + * + * When 'external' is selected but sessionStore is not provided, an error will be thrown. + * + * @default 'memory' + */ + sessionStorageMode?: SessionStorageMode; + + /** + * Session store for distributed session management. + * Required when sessionStorageMode is 'external'. + * + * This enables multi-node/multi-pod deployments where requests may be routed + * to different server instances. + * + * When sessionStore is provided with mode 'external': + * - Session validation checks the external store instead of local memory + * - Session data is persisted across server restarts + * - Multiple server instances can share session state + * - Cross-pod session recovery is handled automatically + * + * @example + * ```typescript + * // Redis session store for multi-pod deployment + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStorageMode: 'external', + * sessionStore: new RedisSessionStore({ + * redis: redisClient, + * keyPrefix: 'mcp:session:', + * ttlSeconds: 3600 + * }) + * }); + * ``` + */ + sessionStore?: SessionStore; + /** * List of allowed host header values for DNS rebinding protection. * If not specified, host validation is disabled. @@ -148,6 +297,12 @@ export interface StreamableHTTPServerTransportOptions { * app.post('/mcp', (req, res) => { * transport.handleRequest(req, res, req.body); * }); + * + * // With distributed session store (Redis) for multi-pod deployments + * const transport = new StreamableHTTPServerTransport({ + * sessionIdGenerator: () => randomUUID(), + * sessionStore: myRedisSessionStore + * }); * ``` * * In stateful mode: @@ -155,7 +310,7 @@ export interface StreamableHTTPServerTransportOptions { * - Session ID is always included in initialization responses * - Requests with invalid session IDs are rejected with 404 Not Found * - Non-initialization requests without a session ID are rejected with 400 Bad Request - * - State is maintained in-memory (connections, message history) + * - State is maintained in-memory (connections, message history) or externally via sessionStore * * In stateless mode: * - No Session ID is included in any responses @@ -172,6 +327,8 @@ export class StreamableHTTPServerTransport implements Transport { private _enableJsonResponse: boolean = false; private _standaloneSseStreamId: string = '_GET_stream'; private _eventStore?: EventStore; + private _sessionStorageMode: SessionStorageMode; + private _sessionStore?: SessionStore; private _onsessioninitialized?: (sessionId: string) => void | Promise; private _onsessionclosed?: (sessionId: string) => void | Promise; private _allowedHosts?: string[]; @@ -188,12 +345,36 @@ export class StreamableHTTPServerTransport implements Transport { this.sessionIdGenerator = options.sessionIdGenerator; this._enableJsonResponse = options.enableJsonResponse ?? false; this._eventStore = options.eventStore; + this._sessionStorageMode = options.sessionStorageMode ?? 'memory'; + this._sessionStore = options.sessionStore; this._onsessioninitialized = options.onsessioninitialized; this._onsessionclosed = options.onsessionclosed; this._allowedHosts = options.allowedHosts; this._allowedOrigins = options.allowedOrigins; this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false; this._retryInterval = options.retryInterval; + + // Validate configuration + if (this._sessionStorageMode === 'external' && !this._sessionStore) { + throw new Error( + 'SessionStore is required when sessionStorageMode is "external". ' + + 'Please provide a sessionStore implementation (e.g., RedisSessionStore) or use sessionStorageMode: "memory".' + ); + } + } + + /** + * Returns the current session storage mode + */ + get sessionStorageMode(): SessionStorageMode { + return this._sessionStorageMode; + } + + /** + * Returns true if using external session storage + */ + get isUsingExternalSessionStore(): boolean { + return this._sessionStorageMode === 'external' && this._sessionStore !== undefined; } /** @@ -309,7 +490,7 @@ export class StreamableHTTPServerTransport implements Transport { // If an Mcp-Session-Id is returned by the server during initialization, // clients using the Streamable HTTP transport MUST include it // in the Mcp-Session-Id header on all of their subsequent HTTP requests. - if (!this.validateSession(req, res)) { + if (!await this.validateSession(req, res)) { return; } if (!this.validateProtocolVersion(req, res)) { @@ -548,9 +729,17 @@ export class StreamableHTTPServerTransport implements Transport { // https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/ const isInitializationRequest = messages.some(isInitializeRequest); if (isInitializationRequest) { + // Check if session already exists (either in-memory or in session store) + let sessionAlreadyExists = this._initialized && this.sessionId !== undefined; + + // If using external session storage, also check there + if (!sessionAlreadyExists && this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + sessionAlreadyExists = await this._sessionStore.sessionExists(this.sessionId); + } + // If it's a server with session management and the session ID is already set we should reject the request // to avoid re-initialization. - if (this._initialized && this.sessionId !== undefined) { + if (sessionAlreadyExists) { res.writeHead(400).end( JSON.stringify({ jsonrpc: '2.0', @@ -579,23 +768,47 @@ export class StreamableHTTPServerTransport implements Transport { this.sessionId = this.sessionIdGenerator?.(); this._initialized = true; - // If we have a session ID and an onsessioninitialized handler, call it immediately - // This is needed in cases where the server needs to keep track of multiple sessions + // If we have a session ID and an onsessioninitialized handler, call it FIRST + // This allows the handler to store metadata (e.g., serverId) before we update the session if (this.sessionId && this._onsessioninitialized) { await Promise.resolve(this._onsessioninitialized(this.sessionId)); } + + // Store/update session in external store if using external storage mode + // This runs AFTER onsessioninitialized so we can merge with any existing metadata + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + // Try to get existing session data (may have been stored by onsessioninitialized) + const existingData = await this._sessionStore.getSession(this.sessionId); + const now = Date.now(); + + const sessionData: SessionData = { + sessionId: this.sessionId, + initialized: true, + createdAt: existingData?.createdAt ?? now, + lastActivity: now, + // Preserve any existing metadata (e.g., serverId set by onsessioninitialized) + metadata: existingData?.metadata + }; + await this._sessionStore.storeSession(this.sessionId, sessionData); + } + } if (!isInitializationRequest) { // If an Mcp-Session-Id is returned by the server during initialization, // clients using the Streamable HTTP transport MUST include it // in the Mcp-Session-Id header on all of their subsequent HTTP requests. - if (!this.validateSession(req, res)) { + if (!await this.validateSession(req, res)) { return; } // Mcp-Protocol-Version header is required for all requests after initialization. if (!this.validateProtocolVersion(req, res)) { return; } + + // Update session activity if using external session storage + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.updateSessionActivity(this.sessionId); + } } // check if it contains requests @@ -675,27 +888,111 @@ export class StreamableHTTPServerTransport implements Transport { * Handles DELETE requests to terminate sessions */ private async handleDeleteRequest(req: IncomingMessage, res: ServerResponse): Promise { - if (!this.validateSession(req, res)) { + if (!await this.validateSession(req, res)) { return; } if (!this.validateProtocolVersion(req, res)) { return; } + + // Delete session from external store if using external storage mode + if (this._sessionStorageMode === 'external' && this._sessionStore && this.sessionId) { + await this._sessionStore.deleteSession(this.sessionId); + } + await Promise.resolve(this._onsessionclosed?.(this.sessionId!)); await this.close(); res.writeHead(200).end(); } /** - * Validates session ID for non-initialization requests - * Returns true if the session is valid, false otherwise + * Validates session ID for non-initialization requests. + * + * When sessionStore is provided, validation checks the external store, + * enabling multi-node deployments where different pods may handle requests + * for the same session. + * + * Returns true if the session is valid, false otherwise. */ - private validateSession(req: IncomingMessage, res: ServerResponse): boolean { + private async validateSession(req: IncomingMessage, res: ServerResponse): Promise { if (this.sessionIdGenerator === undefined) { // If the sessionIdGenerator ID is not set, the session management is disabled // and we don't need to validate the session ID return true; } + + const requestSessionId = req.headers['mcp-session-id'] as string | string[] | undefined; + + // If using external session storage mode, check external store + if (this._sessionStorageMode === 'external' && this._sessionStore) { + if (!requestSessionId) { + // Non-initialization requests without a session ID should return 400 Bad Request + res.writeHead(400).end( + JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header is required' + }, + id: null + }) + ); + return false; + } else if (Array.isArray(requestSessionId)) { + res.writeHead(400).end( + JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Mcp-Session-Id header must be a single value' + }, + id: null + }) + ); + return false; + } + + // Check if session exists in external store + const sessionData = await this._sessionStore.getSession(requestSessionId); + if (!sessionData) { + res.writeHead(404).end( + JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32001, + message: 'Session not found' + }, + id: null + }) + ); + return false; + } + + if (!sessionData.initialized) { + res.writeHead(400).end( + JSON.stringify({ + jsonrpc: '2.0', + error: { + code: -32000, + message: 'Bad Request: Server not initialized' + }, + id: null + }) + ); + return false; + } + + // Session is valid - update local state if needed + // This enables cross-pod session recovery + if (this.sessionId !== requestSessionId) { + this.sessionId = requestSessionId; + this._initialized = true; + } + + return true; + } + + // Original in-memory validation logic (no session store) if (!this._initialized) { // If the server has not been initialized yet, reject all requests res.writeHead(400).end( @@ -711,9 +1008,7 @@ export class StreamableHTTPServerTransport implements Transport { return false; } - const sessionId = req.headers['mcp-session-id']; - - if (!sessionId) { + if (!requestSessionId) { // Non-initialization requests without a session ID should return 400 Bad Request res.writeHead(400).end( JSON.stringify({ @@ -726,7 +1021,7 @@ export class StreamableHTTPServerTransport implements Transport { }) ); return false; - } else if (Array.isArray(sessionId)) { + } else if (Array.isArray(requestSessionId)) { res.writeHead(400).end( JSON.stringify({ jsonrpc: '2.0', @@ -738,7 +1033,7 @@ export class StreamableHTTPServerTransport implements Transport { }) ); return false; - } else if (sessionId !== this.sessionId) { + } else if (requestSessionId !== this.sessionId) { // Reject requests with invalid session ID with 404 Not Found res.writeHead(404).end( JSON.stringify({