sse.d.ts 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { IncomingMessage, ServerResponse } from 'node:http';
  2. import { Transport } from '../shared/transport.js';
  3. import { JSONRPCMessage, MessageExtraInfo } from '../types.js';
  4. import { AuthInfo } from './auth/types.js';
  5. /**
  6. * Configuration options for SSEServerTransport.
  7. */
  8. export interface SSEServerTransportOptions {
  9. /**
  10. * List of allowed host header values for DNS rebinding protection.
  11. * If not specified, host validation is disabled.
  12. * @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
  13. * or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
  14. */
  15. allowedHosts?: string[];
  16. /**
  17. * List of allowed origin header values for DNS rebinding protection.
  18. * If not specified, origin validation is disabled.
  19. * @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
  20. * or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
  21. */
  22. allowedOrigins?: string[];
  23. /**
  24. * Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured).
  25. * Default is false for backwards compatibility.
  26. * @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
  27. * or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
  28. */
  29. enableDnsRebindingProtection?: boolean;
  30. }
  31. /**
  32. * Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.
  33. *
  34. * This transport is only available in Node.js environments.
  35. * @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead.
  36. */
  37. export declare class SSEServerTransport implements Transport {
  38. private _endpoint;
  39. private res;
  40. private _sseResponse?;
  41. private _sessionId;
  42. private _options;
  43. onclose?: () => void;
  44. onerror?: (error: Error) => void;
  45. onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
  46. /**
  47. * Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`.
  48. */
  49. constructor(_endpoint: string, res: ServerResponse, options?: SSEServerTransportOptions);
  50. /**
  51. * Validates request headers for DNS rebinding protection.
  52. * @returns Error message if validation fails, undefined if validation passes.
  53. */
  54. private validateRequestHeaders;
  55. /**
  56. * Handles the initial SSE connection request.
  57. *
  58. * This should be called when a GET request is made to establish the SSE stream.
  59. */
  60. start(): Promise<void>;
  61. /**
  62. * Handles incoming POST messages.
  63. *
  64. * This should be called when a POST request is made to send a message to the server.
  65. */
  66. handlePostMessage(req: IncomingMessage & {
  67. auth?: AuthInfo;
  68. }, res: ServerResponse, parsedBody?: unknown): Promise<void>;
  69. /**
  70. * 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.
  71. */
  72. handleMessage(message: unknown, extra?: MessageExtraInfo): Promise<void>;
  73. close(): Promise<void>;
  74. send(message: JSONRPCMessage): Promise<void>;
  75. /**
  76. * Returns the session ID for this transport.
  77. *
  78. * This can be used to route incoming POST requests.
  79. */
  80. get sessionId(): string;
  81. }
  82. //# sourceMappingURL=sse.d.ts.map