server.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * QMD MCP Server - Model Context Protocol server for QMD
  3. *
  4. * Exposes QMD search and document retrieval as MCP tools and resources.
  5. * Documents are accessible via qmd:// URIs.
  6. *
  7. * Follows MCP spec 2025-06-18 for proper response types.
  8. */
  9. /**
  10. * Periodically check this MCP process's RSS and exit cleanly when it
  11. * crosses a configurable ceiling, so the parent (Claude Code stdio
  12. * client, pm2, systemd, etc.) can respawn a fresh process. Contains
  13. * the blast radius of memory leaks in the search/expansion path
  14. * without requiring a full re-architecture.
  15. *
  16. * Configuration:
  17. * QMD_MCP_RSS_LIMIT_BYTES — ceiling in bytes. Default 0 (disabled).
  18. * Set to e.g. `2147483648` (2 GiB) to opt in.
  19. * QMD_MCP_RSS_CHECK_INTERVAL_MS — poll interval. Default 60000 (60s).
  20. *
  21. * Default-off so we can ship the diagnostic + pragma fix safely and
  22. * graduate the supervisor on once we have soak data showing no
  23. * false positives. Operators can opt in immediately by exporting
  24. * `QMD_MCP_RSS_LIMIT_BYTES=2147483648` in their MCP launcher env.
  25. */
  26. export type RssSupervisorHandle = {
  27. stop: () => void;
  28. /** Snapshot the most recent RSS reading (test hook). */
  29. lastRss: () => number;
  30. };
  31. export interface RssSupervisorOptions {
  32. /** RSS ceiling in bytes. 0 disables. */
  33. limitBytes?: number;
  34. /** Polling cadence in ms. Default 60000. */
  35. intervalMs?: number;
  36. /** Override RSS reader for tests. */
  37. readRss?: () => number;
  38. /** Override exit hook for tests. */
  39. onExceeded?: (rss: number, limit: number) => void;
  40. /** Override stderr writer for tests. */
  41. log?: (line: string) => void;
  42. }
  43. export declare function startRssSupervisor(opts?: RssSupervisorOptions): RssSupervisorHandle | null;
  44. export declare function startMcpServer(): Promise<void>;
  45. export type HttpServerHandle = {
  46. httpServer: import("http").Server;
  47. port: number;
  48. stop: () => Promise<void>;
  49. };
  50. /**
  51. * Start MCP server over Streamable HTTP (JSON responses, no SSE).
  52. * Binds to localhost only. Returns a handle for shutdown and port discovery.
  53. */
  54. export declare function startMcpHttpServer(port: number, options?: {
  55. quiet?: boolean;
  56. }): Promise<HttpServerHandle>;