@lostgradient/mcp 0.1.0 → 0.2.1
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/README.md +68 -8
- package/dist/chunk-3ek3knfm.js +73 -0
- package/dist/{chunk-v14p4gng.js → chunk-3rr24vhh.js} +4 -1
- package/dist/chunk-6ekjtvcq.js +273 -0
- package/dist/chunk-7dpts3r9.js +909 -0
- package/dist/chunk-88nhf6xt.js +449 -0
- package/dist/{chunk-psnez3q2.js → chunk-k6fm3cmk.js} +23 -2
- package/dist/chunk-rxnyn7tf.js +19 -0
- package/dist/{chunk-mf3t0afg.js → chunk-wfty87ws.js} +1 -1
- package/dist/{chunk-wmkqd45r.js → chunk-xcf742mf.js} +1 -1
- package/dist/chunk-yf4nw40e.js +1102 -0
- package/dist/conformance.d.ts +43 -0
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/environment-schema.d.ts +1 -1
- package/dist/environment-schema.js +1 -1
- package/dist/http/authenticate.d.ts +35 -0
- package/dist/http/authorization-header.d.ts +5 -0
- package/dist/http/grant-revocation-channel.d.ts +24 -0
- package/dist/http/handler.d.ts +32 -0
- package/dist/http/index.d.ts +27 -0
- package/dist/http/index.js +813 -0
- package/dist/http/request-context.d.ts +17 -0
- package/dist/http/responses.d.ts +11 -0
- package/dist/http/serving-layer.d.ts +18 -0
- package/dist/http/user-handler-cache.d.ts +37 -0
- package/dist/http/user-server-event-bus.d.ts +35 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +230 -940
- package/dist/logger.d.ts +20 -0
- package/dist/logger.js +9 -5
- package/dist/oauth/authorize-endpoint.d.ts +5 -0
- package/dist/oauth/canonicalize-ip-address.d.ts +20 -0
- package/dist/oauth/client-authentication.d.ts +10 -0
- package/dist/oauth/client-metadata-documents.d.ts +52 -0
- package/dist/oauth/client-metadata-documents.js +19 -0
- package/dist/oauth/discovery-metadata.d.ts +19 -0
- package/dist/oauth/endpoint-rate-limits.d.ts +10 -0
- package/dist/oauth/endpoint-responses.d.ts +10 -0
- package/dist/oauth/index.d.ts +214 -0
- package/dist/oauth/index.js +69 -0
- package/dist/oauth/network-identity.d.ts +32 -0
- package/dist/oauth/pkce-validation.d.ts +2 -0
- package/dist/oauth/postgres/client-store.d.ts +12 -0
- package/dist/oauth/postgres/code-store.d.ts +14 -0
- package/dist/oauth/postgres/database.d.ts +18 -0
- package/dist/oauth/postgres/index.d.ts +11 -0
- package/dist/oauth/postgres/index.js +584 -0
- package/dist/oauth/postgres/schema.d.ts +1455 -0
- package/dist/oauth/postgres/token-store.d.ts +16 -0
- package/dist/oauth/postgres/transaction-store.d.ts +14 -0
- package/dist/oauth/redirect-uri-matching.d.ts +2 -0
- package/dist/oauth/registration-endpoint.d.ts +2 -0
- package/dist/oauth/request-body.d.ts +14 -0
- package/dist/oauth/revocation-endpoint.d.ts +2 -0
- package/dist/oauth/safe-public-https-fetch.d.ts +28 -0
- package/dist/oauth/scope-utilities.d.ts +15 -0
- package/dist/oauth/security-utilities.d.ts +8 -0
- package/dist/oauth/stores.d.ts +225 -0
- package/dist/oauth/stores.js +0 -0
- package/dist/oauth/testing/contract-fixtures.d.ts +134 -0
- package/dist/oauth/testing/index.d.ts +56 -0
- package/dist/oauth/testing/index.js +330 -0
- package/dist/oauth/token-endpoint.d.ts +2 -0
- package/dist/oauth-scope-configuration.d.ts +3 -0
- package/dist/rate-limit/in-memory-sliding-window-store.d.ts +3 -0
- package/dist/rate-limit/index.d.ts +23 -0
- package/dist/rate-limit/index.js +29 -0
- package/dist/rate-limit/mcp-concurrency-limiter.d.ts +26 -0
- package/dist/rate-limit/rate-limit-response.d.ts +1 -0
- package/dist/rate-limit/redis-sliding-window-store.d.ts +2 -0
- package/dist/rate-limit/request-rate-limiter.d.ts +10 -0
- package/dist/rate-limit/sliding-window-rate-limiter.d.ts +16 -0
- package/dist/scopes.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/sveltekit-mount-state.d.ts +4 -0
- package/dist/sveltekit-mount.d.ts +43 -0
- package/dist/sveltekit-mount.js +332 -0
- package/dist/tool-response.d.ts +6 -0
- package/dist/types/primitives.d.ts +1 -1
- package/dist/ui-extension-support.d.ts +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +56 -4
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type McpProtocolErrorCode = 'bad_request' | 'unauthorized' | 'forbidden' | 'not_found' | 'session_affinity_required' | 'unsupported_media_type' | 'not_acceptable' | 'rate_limited' | 'payload_too_large' | 'internal_error';
|
|
2
|
+
export declare function createMcpProtocolErrorResponse(input: {
|
|
3
|
+
status: number;
|
|
4
|
+
error: McpProtocolErrorCode;
|
|
5
|
+
errorDescription: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
data?: Record<string, unknown>;
|
|
8
|
+
}): Response;
|
|
9
|
+
export declare function createMcpCorsHeaders(request: Request, allowedOrigins: ReadonlySet<string>): Record<string, string>;
|
|
10
|
+
export declare function isMcpOriginAllowed(request: Request, allowedOrigins: ReadonlySet<string>): boolean;
|
|
11
|
+
export declare function createRateLimitedResponse(retryAfterSeconds: number, headers: Record<string, string>): Response;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}): McpHttpServingLayer;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
CHANGED
|
@@ -3,7 +3,8 @@ export { cancellableOperationTestHooks } from './conformance-fixture-registratio
|
|
|
3
3
|
export { getUserProfileTool, listAuditEventsTool, allTools } from './tools/index.js';
|
|
4
4
|
export { userProfileResource, allResources } from './resources/index.js';
|
|
5
5
|
export { summarizePrompt, allPrompts } from './prompts/index.js';
|
|
6
|
-
export { logger, getLogger } from './logger.js';
|
|
6
|
+
export { logger, getLogger, setLogger } from './logger.js';
|
|
7
|
+
export type { McpLogger } from './logger.js';
|
|
7
8
|
export { createToolTextResponse, createToolJsonResponse, createToolStructuredResponse, createToolErrorResponse, } from './tool-response.js';
|
|
8
9
|
export { getEnvironment, parseMcpServerEnvironment } from './env.js';
|
|
9
10
|
export type { McpServerEnvironment } from './env.js';
|
|
@@ -22,4 +23,7 @@ export type { McpScopeVocabulary, McpRegistry } from './scope-vocabulary.js';
|
|
|
22
23
|
export { templateRegistry } from './template-registry.js';
|
|
23
24
|
export type { McpScope } from './scopes.js';
|
|
24
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';
|
|
25
29
|
export { hasRegisteredUiExtensionResource } from './ui-extension-support.js';
|