@prefecthq/fastmcp-ts 1.5.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.d.ts CHANGED
@@ -6,6 +6,43 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import { Readable, Writable } from 'node:stream';
7
7
  import { Response as Response$1 } from 'express';
8
8
 
9
+ /** Sink contract for FastMCPOptions.logger. `console` and Winston loggers
10
+ * satisfy it structurally; Pino needs a small adapter (see docs/servers/logging.mdx). */
11
+ interface Logger {
12
+ debug(message: string, meta?: Record<string, unknown>): void;
13
+ info(message: string, meta?: Record<string, unknown>): void;
14
+ warn(message: string, meta?: Record<string, unknown>): void;
15
+ error(message: string, meta?: Record<string, unknown>): void;
16
+ }
17
+ declare const FRAMEWORK_LOG_LEVELS: readonly ["debug", "info", "warn", "error", "silent"];
18
+ /** Framework-diagnostics level axis. Distinct from the MCP `LogLevel` union
19
+ * (client-facing `ctx.log` levels), which is a separate axis entirely. */
20
+ type FrameworkLogLevel = (typeof FRAMEWORK_LOG_LEVELS)[number];
21
+ interface BannerFields {
22
+ name: string;
23
+ version: string;
24
+ transport: 'stdio' | 'http';
25
+ url?: string;
26
+ }
27
+ /** Level-gated wrapper around the sink. This is what the framework holds and
28
+ * calls; the gate applies identically to injected and default sinks. */
29
+ declare class ResolvedLogger {
30
+ private readonly sink;
31
+ readonly level: FrameworkLogLevel;
32
+ constructor(sink: Logger, level: FrameworkLogLevel);
33
+ private enabled;
34
+ debug(message: string, meta?: Record<string, unknown>): void;
35
+ info(message: string, meta?: Record<string, unknown>): void;
36
+ warn(message: string, meta?: Record<string, unknown>): void;
37
+ error(message: string, meta?: Record<string, unknown>): void;
38
+ /** Server-start card. Pretty DefaultSink renders a banner block;
39
+ * every other sink gets one plain info line. Gated as info. */
40
+ startupBanner(fields: BannerFields): void;
41
+ /** Listening confirmation. The word "listening" is load-bearing: the CLI's
42
+ * run command detects a successful start by sniffing stderr for it. */
43
+ listening(url: string): void;
44
+ }
45
+
9
46
  /**
10
47
  * Read-only, per-request snapshot of the HTTP request that carried the current
11
48
  * MCP message. Present wherever the server is reached over an HTTP transport;
@@ -419,8 +456,9 @@ interface CustomRouteConfig {
419
456
  path: string;
420
457
  /**
421
458
  * HTTP methods served, compared case-insensitively. Default: `['GET']`.
422
- * `OPTIONS` is rejected at registration: the global CORS preflight answers
423
- * `OPTIONS` before route dispatch, so a route on it would be unreachable.
459
+ * `OPTIONS` is rejected at registration: it is reserved for the global
460
+ * CORS preflight, and never dispatches to a route even when CORS is
461
+ * disabled (`http.cors: false`).
424
462
  */
425
463
  methods?: string[];
426
464
  }
@@ -461,10 +499,21 @@ interface Middleware {
461
499
  onGetPrompt?(ctx: MiddlewareContext, next: Next): Promise<unknown>;
462
500
  onListPrompts?(ctx: MiddlewareContext, next: Next): Promise<unknown>;
463
501
  }
464
- /** Logs every request with method, outcome, and elapsed time. */
502
+ /** Logs every request with method, outcome, and elapsed time.
503
+ *
504
+ * Output resolution, in order: an explicit `emit` (unchanged legacy behavior,
505
+ * `[fastmcp]`-prefixed strings); the server's framework logger when attached
506
+ * via FastMCPOptions.middleware or `use()`; a plain stderr write. The default
507
+ * was `console.log` before v-next, which corrupted the stdio protocol stream. */
465
508
  declare class LoggingMiddleware implements Middleware {
466
- private readonly emit;
467
- constructor(emit?: (msg: string) => void);
509
+ private readonly emit?;
510
+ private logger;
511
+ constructor(emit?: ((msg: string) => void) | undefined);
512
+ /** @internal Called by FastMCP when this middleware is attached. */
513
+ _bindLogger(logger: ResolvedLogger): void;
514
+ private emitRequest;
515
+ private emitResponse;
516
+ private emitFailure;
468
517
  onRequest(ctx: MiddlewareContext, next: Next): Promise<unknown>;
469
518
  }
470
519
  /**
@@ -791,6 +840,49 @@ declare class ResourceResult {
791
840
  }>);
792
841
  }
793
842
 
843
+ /**
844
+ * Configurable CORS for the HTTP listener `run()` starts (both the plain and
845
+ * the OAuth serve paths). Resolution and header computation are pure
846
+ * functions: `resolveCors` runs once, in the FastMCP constructor, and fails
847
+ * loudly on malformed config (the `resolveHealth` precedent); the two header
848
+ * builders run per request.
849
+ *
850
+ * `fetch()` is deliberately untouched: the embedding framework owns CORS at
851
+ * its HTTP boundary, exactly as it owns Host/Origin validation.
852
+ */
853
+
854
+ /** `FastMCPOptions.http.cors` object form. `true` and omitted mean the
855
+ * permissive defaults; `false` disables CORS handling entirely (no global
856
+ * preflight, no headers). */
857
+ interface CorsOptions {
858
+ /**
859
+ * Origins allowed to call the MCP endpoint from a browser, compared
860
+ * against the request's `Origin` header. `'*'` (the default) allows every
861
+ * origin. A string or array allows exactly those `scheme://host[:port]`
862
+ * origins. A function receives the `Origin` value and returns whether it
863
+ * is allowed. A function that throws denies the origin.
864
+ */
865
+ origin?: string | string[] | ((origin: string) => boolean);
866
+ /** `Access-Control-Allow-Methods` value; replaces the default
867
+ * `GET, POST, DELETE, OPTIONS` list verbatim. */
868
+ methods?: string[];
869
+ /** Extra request headers for `Access-Control-Allow-Headers`, added to the
870
+ * defaults. The MCP protocol headers are never removed: silently dropping
871
+ * one would break browser clients in ways that only surface in
872
+ * production. */
873
+ allowedHeaders?: string[];
874
+ /** Extra response headers for `Access-Control-Expose-Headers`, added to
875
+ * the default `Mcp-Session-Id` (legacy sessionful browser clients must
876
+ * read it from the initialize response). */
877
+ exposedHeaders?: string[];
878
+ /** Send `Access-Control-Allow-Credentials: true`. Requires an explicit
879
+ * non-`'*'` `origin`: browsers reject `*` on credentialed requests, so
880
+ * that combination is a construction-time error. */
881
+ credentials?: boolean;
882
+ /** `Access-Control-Max-Age` for preflight caching, in seconds. */
883
+ maxAge?: number;
884
+ }
885
+
794
886
  type CacheableResultMethod = 'tools/list' | 'prompts/list' | 'resources/list' | 'resources/templates/list' | 'resources/read' | 'server/discover';
795
887
 
796
888
  interface OAuthConfig {
@@ -826,11 +918,37 @@ interface FastMCPOptions {
826
918
  * opt-out. Withheld names are listed in `ctx.http.redactedHeaderNames`.
827
919
  * Redaction applies to `ctx.http` only; a RequestVerifier always sees the
828
920
  * full wire headers.
921
+ *
922
+ * `cors` configures the CORS posture of the HTTP listener `run()` starts
923
+ * (both serve paths): omitted or `true` serves the permissive defaults
924
+ * (`Access-Control-Allow-Origin: *`), `false` disables CORS handling
925
+ * entirely, and an object narrows it — see `CorsOptions`. Malformed
926
+ * values throw here, at construction, for every transport. `fetch()` is
927
+ * unaffected: the embedding framework owns CORS at its HTTP boundary.
829
928
  */
830
929
  http?: {
831
930
  redactHeaders?: string[];
832
931
  exposeHeaders?: string[];
932
+ cors?: boolean | CorsOptions;
833
933
  };
934
+ /**
935
+ * Sink for the framework's own diagnostic logs (lifecycle, warnings,
936
+ * errors). `console` and Winston loggers satisfy the shape directly; see
937
+ * the logging docs for a Pino adapter. Default: a built-in stderr logger
938
+ * (styled on a TTY, plain single-line format otherwise). Client-facing MCP
939
+ * logging (`ctx.log`) is a separate channel and is not affected. Do not use
940
+ * `logger: console` with the stdio transport: `console.info` and
941
+ * `console.debug` write to stdout, which carries the JSON-RPC stream on
942
+ * that transport.
943
+ */
944
+ logger?: Logger;
945
+ /**
946
+ * Minimum level for framework logs, applied before any logger (injected or
947
+ * default) is called. Precedence: this option, then the FASTMCP_LOG_LEVEL
948
+ * environment variable, then 'info'. 'silent' disables framework logging.
949
+ * Malformed values throw here, at construction, for every transport.
950
+ */
951
+ logLevel?: FrameworkLogLevel;
834
952
  /** Maximum number of tools returned per listTools page. Default: 50. */
835
953
  toolsPageSize?: number;
836
954
  /** Maximum number of resources (or templates) returned per page. Default: 50. */
@@ -1026,6 +1144,9 @@ declare class FastMCP {
1026
1144
  readonly name: string;
1027
1145
  readonly version: string;
1028
1146
  private _auth;
1147
+ /** @internal Framework logger; used by same-package modules (proxy, openapi). Not public API. */
1148
+ readonly _logger: ResolvedLogger;
1149
+ private _cors;
1029
1150
  private _oauth;
1030
1151
  private _sensitiveHeaders;
1031
1152
  private _toolsPageSize;
@@ -1487,6 +1608,10 @@ type StdioTransport = {
1487
1608
  cwd?: string;
1488
1609
  /** How long (ms) before the proxy re-fetches component lists. Default 30 000. Set 0 for notifications-only. */
1489
1610
  cacheTtl?: number;
1611
+ /** Framework logger for the proxy's own FastMCP instance. Defaults to the stderr sink. */
1612
+ logger?: Logger;
1613
+ /** Framework log level for the proxy's own FastMCP instance. */
1614
+ logLevel?: FrameworkLogLevel;
1490
1615
  };
1491
1616
  type HttpTransport = {
1492
1617
  type: 'http';
@@ -1494,6 +1619,10 @@ type HttpTransport = {
1494
1619
  requestInit?: RequestInit;
1495
1620
  /** How long (ms) before the proxy re-fetches component lists. Default 30 000. Set 0 for notifications-only. */
1496
1621
  cacheTtl?: number;
1622
+ /** Framework logger for the proxy's own FastMCP instance. Defaults to the stderr sink. */
1623
+ logger?: Logger;
1624
+ /** Framework log level for the proxy's own FastMCP instance. */
1625
+ logLevel?: FrameworkLogLevel;
1497
1626
  };
1498
1627
  type ProxyTransport = StdioTransport | HttpTransport;
1499
1628
  /**
@@ -1841,4 +1970,4 @@ declare class FormInput {
1841
1970
  constructor(options: FormInputOptions);
1842
1971
  }
1843
1972
 
1844
- export { type AccessToken, Approval, Area, type AuthCheck, AuthorizationError, type BackendToolConfig, Badge, Bar, type BrowserPermissions, Button, type CacheKeyFn, CachingMiddleware, CancellationMiddleware, type CatalogEntry, Choice, Column, type CompleteCallback, type CompletionContext, type CompletionResult, type Component, type ComponentFn, type CspPolicy, type CustomRouteConfig, type CustomRouteHandler, type ElicitationResult, type ElicitationSchema, type EntrypointConfig, ErrorNormalizationMiddleware, FastMCP, FastMCPApp, type FastMCPAppOptions, type FastMCPOptions, File, type FileHandle, type FileStorageAdapter, FileUpload, type FileUploadOptions, FilterTransform, ForEach, FormInput, type FormInputOptions, GenerativeUI, Grid, type HTTPRoute, type HealthOptions, type HttpMethod, type HttpRequestContext, If, type IfNode, Image, Input, Line, type LogLevel, LoggingMiddleware, type MCPType, type McpContext, type Middleware, type MiddlewareContext, NamespaceTransform, type Next, type OAuthConfig, type OAuthProviderOptions, type OAuthProxyOptions, type OpenAPIClientOptions, type OpenAPIComponent, type OpenAPIResourceComponent, type OpenAPIResourceTemplateComponent, type OpenAPIServerOptions, type OpenAPIToolComponent, type ParameterInfo, Pie, type PromptArgument, type PromptConfig, type PromptContent, type PromptMessage, PromptResult, type PromptView, PromptsAsTools, type ProxyTransport, RateLimitingMiddleware, type RequestBodyInfo, type RequestVerifier, type ResourceAnnotations, type ResourceConfig, ResourceResult, type ResourceUiMeta, type ResourceView, ResourcesAsTools, type ResponseInfo, type Root, type RouteMap, type RouteMapFn, Row, type RunOptions, Rx, type SamplingMessage, type SamplingParams, type SamplingResult, Select, type ServerAddress, SizeLimitingMiddleware, type SynthesizedTool, Table, Text, type TokenVerifier, type ToolAnnotations, type ToolConfig, ToolResult, type ToolView, type Transform, type UiToolMeta, VersionFilter, type Visibility, actionRef, createOpenAPIServer, createProxy, debugTokenVerifier, forwardableHeaders, introspectionVerifier, jwtVerifier, multiAuth, oauthProvider, oauthProxy, redescribeTool, renameTool, requireScopes, staticTokenVerifier };
1973
+ export { type AccessToken, Approval, Area, type AuthCheck, AuthorizationError, type BackendToolConfig, Badge, Bar, type BrowserPermissions, Button, type CacheKeyFn, CachingMiddleware, CancellationMiddleware, type CatalogEntry, Choice, Column, type CompleteCallback, type CompletionContext, type CompletionResult, type Component, type ComponentFn, type CorsOptions, type CspPolicy, type CustomRouteConfig, type CustomRouteHandler, type ElicitationResult, type ElicitationSchema, type EntrypointConfig, ErrorNormalizationMiddleware, FastMCP, FastMCPApp, type FastMCPAppOptions, type FastMCPOptions, File, type FileHandle, type FileStorageAdapter, FileUpload, type FileUploadOptions, FilterTransform, ForEach, FormInput, type FormInputOptions, type FrameworkLogLevel, GenerativeUI, Grid, type HTTPRoute, type HealthOptions, type HttpMethod, type HttpRequestContext, If, type IfNode, Image, Input, Line, type LogLevel, type Logger, LoggingMiddleware, type MCPType, type McpContext, type Middleware, type MiddlewareContext, NamespaceTransform, type Next, type OAuthConfig, type OAuthProviderOptions, type OAuthProxyOptions, type OpenAPIClientOptions, type OpenAPIComponent, type OpenAPIResourceComponent, type OpenAPIResourceTemplateComponent, type OpenAPIServerOptions, type OpenAPIToolComponent, type ParameterInfo, Pie, type PromptArgument, type PromptConfig, type PromptContent, type PromptMessage, PromptResult, type PromptView, PromptsAsTools, type ProxyTransport, RateLimitingMiddleware, type RequestBodyInfo, type RequestVerifier, type ResourceAnnotations, type ResourceConfig, ResourceResult, type ResourceUiMeta, type ResourceView, ResourcesAsTools, type ResponseInfo, type Root, type RouteMap, type RouteMapFn, Row, type RunOptions, Rx, type SamplingMessage, type SamplingParams, type SamplingResult, Select, type ServerAddress, SizeLimitingMiddleware, type SynthesizedTool, Table, Text, type TokenVerifier, type ToolAnnotations, type ToolConfig, ToolResult, type ToolView, type Transform, type UiToolMeta, VersionFilter, type Visibility, actionRef, createOpenAPIServer, createProxy, debugTokenVerifier, forwardableHeaders, introspectionVerifier, jwtVerifier, multiAuth, oauthProvider, oauthProxy, redescribeTool, renameTool, requireScopes, staticTokenVerifier };