@lostgradient/mcp 0.2.6 → 0.3.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.
Files changed (123) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -173
  3. package/dist/http.d.ts +35 -0
  4. package/dist/http.js +251 -0
  5. package/dist/internal/cryptography/encryption.d.ts +108 -0
  6. package/dist/internal/cryptography/encryption.js +241 -0
  7. package/dist/internal/cryptography/hash.d.ts +72 -0
  8. package/dist/internal/cryptography/hash.js +233 -0
  9. package/dist/internal/cryptography/index.d.ts +4 -0
  10. package/dist/internal/cryptography/index.js +2 -0
  11. package/dist/oauth/canonicalize-ip-address.d.ts +0 -6
  12. package/dist/oauth/canonicalize-ip-address.js +113 -0
  13. package/dist/oauth/client-metadata-documents.d.ts +2 -22
  14. package/dist/oauth/client-metadata-documents.js +205 -19
  15. package/dist/oauth/index.d.ts +9 -213
  16. package/dist/oauth/index.js +6 -69
  17. package/dist/oauth/issuer.d.ts +103 -0
  18. package/dist/oauth/issuer.js +564 -0
  19. package/dist/oauth/postgres.d.ts +12 -0
  20. package/dist/oauth/postgres.js +76 -0
  21. package/dist/oauth/safe-public-https-fetch.d.ts +3 -5
  22. package/dist/oauth/safe-public-https-fetch.js +114 -0
  23. package/dist/oauth/security-utilities.d.ts +0 -3
  24. package/dist/oauth/security-utilities.js +93 -0
  25. package/dist/oauth-store.d.ts +108 -0
  26. package/dist/oauth-store.js +321 -0
  27. package/package.json +50 -124
  28. package/dist/chunk-3ek3knfm.js +0 -73
  29. package/dist/chunk-3rr24vhh.js +0 -28
  30. package/dist/chunk-5444sx3n.js +0 -916
  31. package/dist/chunk-6ekjtvcq.js +0 -273
  32. package/dist/chunk-k6fm3cmk.js +0 -132
  33. package/dist/chunk-r9atew6b.js +0 -449
  34. package/dist/chunk-rxnyn7tf.js +0 -19
  35. package/dist/chunk-taxyscge.js +0 -67
  36. package/dist/chunk-tkn6m6az.js +0 -1107
  37. package/dist/chunk-xcf742mf.js +0 -14
  38. package/dist/chunk-zrrf78wj.js +0 -4
  39. package/dist/conformance-fixture-registration.d.ts +0 -30
  40. package/dist/conformance-server.d.ts +0 -1
  41. package/dist/conformance.d.ts +0 -43
  42. package/dist/env.d.ts +0 -59
  43. package/dist/env.js +0 -9
  44. package/dist/environment-schema.d.ts +0 -29
  45. package/dist/environment-schema.js +0 -6
  46. package/dist/golden-prompts.d.ts +0 -42
  47. package/dist/handler-context.d.ts +0 -16
  48. package/dist/http/authenticate.d.ts +0 -35
  49. package/dist/http/authorization-header.d.ts +0 -5
  50. package/dist/http/grant-revocation-channel.d.ts +0 -24
  51. package/dist/http/handler.d.ts +0 -32
  52. package/dist/http/index.d.ts +0 -27
  53. package/dist/http/index.js +0 -870
  54. package/dist/http/listen-inspection.d.ts +0 -11
  55. package/dist/http/request-context.d.ts +0 -17
  56. package/dist/http/responses.d.ts +0 -13
  57. package/dist/http/serving-layer.d.ts +0 -25
  58. package/dist/http/user-handler-cache.d.ts +0 -37
  59. package/dist/http/user-server-event-bus.d.ts +0 -35
  60. package/dist/index.d.ts +0 -29
  61. package/dist/index.js +0 -616
  62. package/dist/localhost-request-validation.d.ts +0 -2
  63. package/dist/logger.d.ts +0 -59
  64. package/dist/logger.js +0 -18
  65. package/dist/long-running-operation-support.d.ts +0 -34
  66. package/dist/metrics.d.ts +0 -64
  67. package/dist/metrics.js +0 -6
  68. package/dist/oauth/authorize-endpoint.d.ts +0 -5
  69. package/dist/oauth/client-authentication.d.ts +0 -10
  70. package/dist/oauth/discovery-metadata.d.ts +0 -19
  71. package/dist/oauth/endpoint-rate-limits.d.ts +0 -10
  72. package/dist/oauth/endpoint-responses.d.ts +0 -10
  73. package/dist/oauth/network-identity.d.ts +0 -32
  74. package/dist/oauth/pkce-validation.d.ts +0 -2
  75. package/dist/oauth/postgres/client-store.d.ts +0 -12
  76. package/dist/oauth/postgres/code-store.d.ts +0 -14
  77. package/dist/oauth/postgres/database.d.ts +0 -59
  78. package/dist/oauth/postgres/index.d.ts +0 -11
  79. package/dist/oauth/postgres/index.js +0 -616
  80. package/dist/oauth/postgres/schema.d.ts +0 -1476
  81. package/dist/oauth/postgres/token-store.d.ts +0 -16
  82. package/dist/oauth/postgres/transaction-store.d.ts +0 -14
  83. package/dist/oauth/redirect-uri-matching.d.ts +0 -2
  84. package/dist/oauth/registration-endpoint.d.ts +0 -2
  85. package/dist/oauth/request-body.d.ts +0 -14
  86. package/dist/oauth/revocation-endpoint.d.ts +0 -2
  87. package/dist/oauth/scope-utilities.d.ts +0 -15
  88. package/dist/oauth/stores.d.ts +0 -225
  89. package/dist/oauth/stores.js +0 -0
  90. package/dist/oauth/testing/contract-fixtures.d.ts +0 -134
  91. package/dist/oauth/testing/index.d.ts +0 -56
  92. package/dist/oauth/testing/index.js +0 -330
  93. package/dist/oauth/token-endpoint.d.ts +0 -2
  94. package/dist/oauth-scope-configuration.d.ts +0 -3
  95. package/dist/prompts/index.d.ts +0 -5
  96. package/dist/prompts/summarize.d.ts +0 -4
  97. package/dist/rate-limit/in-memory-sliding-window-store.d.ts +0 -3
  98. package/dist/rate-limit/index.d.ts +0 -23
  99. package/dist/rate-limit/index.js +0 -29
  100. package/dist/rate-limit/mcp-concurrency-limiter.d.ts +0 -26
  101. package/dist/rate-limit/rate-limit-response.d.ts +0 -1
  102. package/dist/rate-limit/redis-sliding-window-store.d.ts +0 -2
  103. package/dist/rate-limit/request-rate-limiter.d.ts +0 -10
  104. package/dist/rate-limit/sliding-window-rate-limiter.d.ts +0 -16
  105. package/dist/resources/index.d.ts +0 -4
  106. package/dist/resources/user-profile.d.ts +0 -1
  107. package/dist/scope-vocabulary.d.ts +0 -127
  108. package/dist/scopes.d.ts +0 -49
  109. package/dist/server.d.ts +0 -113
  110. package/dist/supported-scopes.d.ts +0 -25
  111. package/dist/sveltekit-mount-state.d.ts +0 -4
  112. package/dist/sveltekit-mount.d.ts +0 -43
  113. package/dist/sveltekit-mount.js +0 -344
  114. package/dist/template-registry.d.ts +0 -16
  115. package/dist/tool-response.d.ts +0 -100
  116. package/dist/tools/get-user-profile.d.ts +0 -8
  117. package/dist/tools/index.d.ts +0 -16
  118. package/dist/tools/list-audit-events.d.ts +0 -11
  119. package/dist/type-assertions.d.ts +0 -1
  120. package/dist/types/primitives.d.ts +0 -130
  121. package/dist/ui-extension-support.d.ts +0 -20
  122. package/dist/version.d.ts +0 -23
  123. package/dist/version.js +0 -6
@@ -1,11 +0,0 @@
1
- /**
2
- * Detects the `subscriptions/listen` request whose response the transport must
3
- * not force-close on graceful shutdown. Shared by the serving handler (for
4
- * subscription-scope authorization) and the serving layer (to tag the final
5
- * response), so neither needs a runtime dependency on the other (TRI-128).
6
- */
7
- export type ListenInspection = {
8
- isListenRequest: boolean;
9
- requestedResourceUris: string[];
10
- };
11
- export declare function inspectListenRequest(request: Request): Promise<ListenInspection>;
@@ -1,17 +0,0 @@
1
- import type { AuthInfo } from '@modelcontextprotocol/server';
2
- import type { McpUserProfile } from '../types/primitives.js';
3
- export type McpRequestAuthExtra = {
4
- userId: string;
5
- userProfile: McpUserProfile;
6
- oauthClientId: string;
7
- scopes: string[];
8
- resource: string;
9
- networkIdentity?: string;
10
- requestId?: string;
11
- };
12
- export declare function buildMcpAuthInfo(input: {
13
- accessToken: string;
14
- expiresAt: Date;
15
- extra: McpRequestAuthExtra;
16
- }): AuthInfo;
17
- export declare function readMcpRequestAuthExtra(authInfo: AuthInfo | undefined): McpRequestAuthExtra | undefined;
@@ -1,13 +0,0 @@
1
- export declare class McpPayloadTooLargeError extends Error {
2
- }
3
- export type McpProtocolErrorCode = 'bad_request' | 'unauthorized' | 'forbidden' | 'not_found' | 'session_affinity_required' | 'unsupported_media_type' | 'not_acceptable' | 'rate_limited' | 'payload_too_large' | 'internal_error';
4
- export declare function createMcpProtocolErrorResponse(input: {
5
- status: number;
6
- error: McpProtocolErrorCode;
7
- errorDescription: string;
8
- headers?: Record<string, string>;
9
- data?: Record<string, unknown>;
10
- }): Response;
11
- export declare function createMcpCorsHeaders(request: Request, allowedOrigins: ReadonlySet<string>): Record<string, string>;
12
- export declare function isMcpOriginAllowed(request: Request, allowedOrigins: ReadonlySet<string>): boolean;
13
- export declare function createRateLimitedResponse(retryAfterSeconds: number, headers: Record<string, string>): Response;
@@ -1,25 +0,0 @@
1
- import { type OAuthRequestContext } from '../oauth/index.js';
2
- import type { McpConcurrencyLimiter, RequestRateLimiter } from '../rate-limit/index.js';
3
- import { type McpAuthenticationConfiguration, type McpAuthenticationSeams } from './authenticate.js';
4
- import type { McpServingHandler } from './handler.js';
5
- export type McpHttpServingLayer = {
6
- handle(context: OAuthRequestContext): Promise<Response>;
7
- };
8
- /**
9
- * Owns the full `/mcp` order: network admission, authentication, auth-extra
10
- * validation, per-user admission, concurrency acquisition, then dispatch.
11
- */
12
- export declare function createMcpHttpServingLayer(input: {
13
- authenticationConfiguration: McpAuthenticationConfiguration;
14
- authenticationSeams: McpAuthenticationSeams;
15
- rateLimiter: Pick<RequestRateLimiter, 'consume'>;
16
- concurrencyLimiter: Pick<McpConcurrencyLimiter, 'acquire'>;
17
- handler: Pick<McpServingHandler, 'handle'>;
18
- /**
19
- * Applied to the FINAL response for a `subscriptions/listen` request so a
20
- * graceful-shutdown drain can exclude it. Provided here (not read off the
21
- * handler) because this layer owns the response after its CORS and
22
- * concurrency re-wraps, which replace the object the handler could tag.
23
- */
24
- markServerOnlyCloseableStream?: (response: Response) => Response;
25
- }): McpHttpServingLayer;
@@ -1,37 +0,0 @@
1
- import type { McpHttpHandler } from '@modelcontextprotocol/server';
2
- import type { UserServerEventBus } from './user-server-event-bus.js';
3
- export type McpUserHandlerEntry = {
4
- handler: McpHttpHandler;
5
- bus: UserServerEventBus;
6
- lastAccessedAt: number;
7
- activeRequestCount: number;
8
- };
9
- export type McpHandlerLifecycleError = (input: {
10
- error: unknown;
11
- userId?: string;
12
- operation: 'evict' | 'revoke' | 'shutdown';
13
- }) => void;
14
- /**
15
- * Maintains one handler and event bus per durable subject. This topology is
16
- * the authorization boundary that prevents one user's subscription events
17
- * from reaching another user who subscribes to the same resource URI.
18
- *
19
- * Entries are bounded by idleness: an entry with no open listener and no
20
- * request inside `idleMilliseconds` is evicted by `evictIdle` or `startSweep`.
21
- */
22
- export declare class McpUserHandlerCache {
23
- private readonly createEntry;
24
- private readonly now;
25
- private readonly onError;
26
- private readonly entries;
27
- private sweepTimer;
28
- constructor(createEntry: (userId: string) => Omit<McpUserHandlerEntry, 'lastAccessedAt' | 'activeRequestCount'>, now?: () => number, onError?: McpHandlerLifecycleError);
29
- get size(): number;
30
- peek(userId: string): McpUserHandlerEntry | undefined;
31
- get(userId: string): McpUserHandlerEntry;
32
- dispatch<T>(userId: string, operation: (handler: McpHttpHandler) => Promise<T>): Promise<T>;
33
- evictIdle(idleMilliseconds: number): string[];
34
- closeUser(userId: string): Promise<boolean>;
35
- startSweep(intervalMilliseconds: number, idleMilliseconds: number): void;
36
- closeAll(): Promise<void>;
37
- }
@@ -1,35 +0,0 @@
1
- import type { ServerEvent, ServerEventBus } from '@modelcontextprotocol/server';
2
- import type { CrossInstanceMessaging } from '../oauth/index.js';
3
- export type UserServerEventBus = ServerEventBus & {
4
- readonly listenerCount: number;
5
- };
6
- export type McpMessagingError = (input: {
7
- error: unknown;
8
- userId: string;
9
- operation: 'publish' | 'subscribe' | 'unsubscribe' | 'deserialize';
10
- }) => void;
11
- /** A per-user event bus backed by the host's cross-instance messaging seam. */
12
- export declare class CrossInstanceUserServerEventBus implements UserServerEventBus {
13
- private readonly userId;
14
- private readonly messaging;
15
- private readonly onError;
16
- private readonly listeners;
17
- private unsubscribeFromMessaging;
18
- private transitionQueue;
19
- private retryTimer;
20
- private retryDelayMilliseconds;
21
- private readonly sourceId;
22
- constructor(userId: string, messaging: CrossInstanceMessaging, onError?: McpMessagingError);
23
- get listenerCount(): number;
24
- publish(event: ServerEvent): void;
25
- subscribe(listener: (event: ServerEvent) => void): () => void;
26
- whenSubscribed(): Promise<void>;
27
- private enqueueTransition;
28
- private scheduleRetry;
29
- private reconcileSubscription;
30
- }
31
- export declare function createUserServerEventBus(input: {
32
- userId: string;
33
- messaging?: CrossInstanceMessaging;
34
- onError?: McpMessagingError;
35
- }): UserServerEventBus;
package/dist/index.d.ts DELETED
@@ -1,29 +0,0 @@
1
- export { createMcpServer, areResourceSubscriptionsAuthorized } from './server.js';
2
- export { cancellableOperationTestHooks } from './conformance-fixture-registration.js';
3
- export { getUserProfileTool, listAuditEventsTool, allTools } from './tools/index.js';
4
- export { userProfileResource, allResources } from './resources/index.js';
5
- export { summarizePrompt, allPrompts } from './prompts/index.js';
6
- export { logger, getLogger, setLogger } from './logger.js';
7
- export type { McpLogger } from './logger.js';
8
- export { createToolTextResponse, createToolJsonResponse, createToolStructuredResponse, createToolErrorResponse, } from './tool-response.js';
9
- export { getEnvironment, parseMcpServerEnvironment } from './env.js';
10
- export type { McpServerEnvironment } from './env.js';
11
- export { PACKAGE_VERSION } from './version.js';
12
- export { hasValidLocalhostRebindingHeaders, isLoopbackHostname, } from './localhost-request-validation.js';
13
- export declare const EXTENSION_ID = "io.modelcontextprotocol/ui";
14
- export declare const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
15
- export { readProgressToken, readSessionIdentifier, readNotificationSender, readRequestSender, stringifyUnknown, parseSampledText, assertSamplingSupport, } from './handler-context.js';
16
- export { metricsCollector } from './metrics.js';
17
- export type { ToolMetricEntry, MetricsSnapshot } from './metrics.js';
18
- export { defineTool, defineResource, definePrompt } from './types/primitives.js';
19
- export type { McpToolDefinition, McpToolAnnotations, McpResourceDefinition, McpPromptDefinition, McpUserProfile, McpContext, } from './types/primitives.js';
20
- export { mcpScopes, mcpScopeDescriptions, isMcpScope, templateScopeVocabulary } from './scopes.js';
21
- export { defineScopes } from './scope-vocabulary.js';
22
- export type { McpScopeVocabulary, McpRegistry } from './scope-vocabulary.js';
23
- export { templateRegistry } from './template-registry.js';
24
- export type { McpScope } from './scopes.js';
25
- export { getSupportedScopes } from './supported-scopes.js';
26
- export { defineOAuthScopeConfiguration } from './oauth-scope-configuration.js';
27
- export { createConsumerConformanceHandler, runMcpConformance } from './conformance.js';
28
- export type { ConsumerConformanceOptions, McpConformanceEra, McpConformanceIdentity, McpConformanceResult, RunMcpConformanceOptions, } from './conformance.js';
29
- export { hasRegisteredUiExtensionResource } from './ui-extension-support.js';