@lostgradient/mcp 0.1.0 → 0.2.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/README.md +68 -8
- package/dist/chunk-11p5d5a1.js +909 -0
- 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-88nhf6xt.js +449 -0
- package/dist/{chunk-psnez3q2.js → chunk-k6fm3cmk.js} +23 -2
- package/dist/{chunk-mf3t0afg.js → chunk-nfvwew92.js} +1 -1
- package/dist/chunk-rxnyn7tf.js +19 -0
- 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
package/README.md
CHANGED
|
@@ -91,6 +91,28 @@ If you would rather rely on the environment, set `NODE_ENV` (and any other varia
|
|
|
91
91
|
|
|
92
92
|
`getSupportedScopes(registry)` returns the sorted union of every scope your registry actually requires. Use it for the `scopes_supported` field of your OAuth metadata documents and for the `scope` attribute on a `401` challenge, rather than maintaining that list by hand.
|
|
93
93
|
|
|
94
|
+
## Running protocol conformance
|
|
95
|
+
|
|
96
|
+
`runMcpConformance` runs either protocol era against your registry. Discovery is checked automatically. Supply valid arguments only for the tools or prompts you want invoked, and resource URIs only for the resources you want read—the harness cannot safely invent valid consumer input.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { runMcpConformance } from '@lostgradient/mcp';
|
|
100
|
+
|
|
101
|
+
const results = await runMcpConformance({
|
|
102
|
+
era: 'modern', // or 'legacy'
|
|
103
|
+
registry,
|
|
104
|
+
scopeVocabulary: scopes,
|
|
105
|
+
identity: { userId: user.id, user },
|
|
106
|
+
toolProbes: { list_repositories: {} },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
for (const result of results) {
|
|
110
|
+
console.log(result.name, result.status, result.error ?? '');
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Each result has a stable behavior name and its own `passed` or `failed` status. One failed tool, resource, or prompt probe does not hide the results of the remaining behaviors. Supply the same application identity every probe should use; otherwise the harness creates one stable synthetic identity for the run. The runner disables package-owned conformance fixtures so discovery reflects only the supplied registry. `createConsumerConformanceHandler` exposes the lower-level request handler when a consumer needs to drive its own client or explicitly enable those fixtures, including watched-resource notifications. Its localhost DNS-rebinding check runs independently of `enableConformanceMode`.
|
|
115
|
+
|
|
94
116
|
## Environment
|
|
95
117
|
|
|
96
118
|
Importing this package reads nothing from `process.env` and cannot throw, whatever the ambient environment. That is deliberate: a library which validates its host's environment during module evaluation cannot be embedded, because the host can neither catch the failure nor supply a different environment nor decide whether it wants a server at all.
|
|
@@ -109,16 +131,54 @@ const environment = parseMcpServerEnvironment(process.env);
|
|
|
109
131
|
|
|
110
132
|
`areResourceSubscriptionsAuthorized(uris, scopes, registry)` is exported because `subscriptions/listen` is decided at the HTTP boundary, before a request reaches the server instance — so a host that mounts this engine must call it there. Omitting it means a client with any valid token can observe updates for a resource whose scope it was never granted.
|
|
111
133
|
|
|
134
|
+
## Rate limiting and concurrency
|
|
135
|
+
|
|
136
|
+
`@lostgradient/mcp/rate-limit` provides the protocol-level sliding-window policy, in-memory and Redis stores, MCP concurrency slots, and the standard `429` response. The Redis factories accept the `MinimalRedisClient` seam from `@lostgradient/mcp/oauth`; they do not require a particular Redis package or a full client object.
|
|
137
|
+
|
|
138
|
+
The shared `RateLimitConfiguration` owns exactly eight protocol categories: OAuth authorize, registration, token network, token client, and revocation; MCP network and user; and failed authentication. Host-only routes such as sign-in, session creation, health, and metrics should use `SlidingWindowRateLimiter` directly with host-owned categories rather than extending the protocol category union.
|
|
139
|
+
|
|
140
|
+
Concurrency is a resource-lifetime concern, not a handler-promise concern. For a streaming response, pass the acquired slot to `attachConcurrencySlotToResponseLifetime` so it renews while the body remains open and releases only when the body closes, is canceled, or errors. A host that separately tracks requests must follow the same rule; Tribunal's other implementation is `applications/web/src/lib/in-flight-request-tracker.ts`.
|
|
141
|
+
|
|
142
|
+
## Host logging
|
|
143
|
+
|
|
144
|
+
Call `setLogger(hostLogger)` before serving requests to route every engine log record through the host's existing sink and redaction policy. The logger is structural and deliberately small: `info`, `warn`, `error`, and `child`. A host does not need to import pino or implement any other pino API. The exported `logger` and `getLogger()` remain the package's full pino-backed logger for compatibility; injection changes the engine's internal sink. If `setLogger` is not called, engine records use that same lazy pino logger and existing behavior.
|
|
145
|
+
|
|
146
|
+
## Required server identity in 0.2.0
|
|
147
|
+
|
|
148
|
+
`MCP_SERVER_NAME` is required starting in 0.2.0. The package no longer defaults to the template-branded `template-mcp-server` identity because that fallback was silently advertised to every connected MCP client. Set the explicit server name before constructing a server.
|
|
149
|
+
|
|
150
|
+
## Mounting in SvelteKit
|
|
151
|
+
|
|
152
|
+
`@lostgradient/mcp/sveltekit` provides a dependency-free adapter for a SvelteKit `handle` chain. Call `createSvelteKitMcpMount` once in a long-lived server process, pass the OAuth seams and MCP runtime, and delegate each request to the returned `handle`. The adapter claims its process lifecycle synchronously: a second mount fails, disposal is permanent, and failed startup cannot be retried in the same process.
|
|
153
|
+
|
|
154
|
+
The host's identity handle must run first and call `primeSvelteKitMcpIdentity(event, identity)` for every request, including anonymous requests with `null`. The mount rejects a request when that handle was skipped or sequenced after it. It reads `event.getClientAddress()` for each request so the OAuth and MCP serving layers receive the immediate socket peer rather than a construction-time value.
|
|
155
|
+
|
|
156
|
+
The host still owns the network listener, signal handling, request draining, and process termination. It must dispose the mount only after response bodies, including long-lived MCP streams, have closed or been canceled. Request-scoped edge and serverless runtimes cannot preserve the mount's subscriptions and must not set `longLivedProcess` to true. Adapter-node deployment behavior is intentionally left to the first host integration rather than claimed by this package contract.
|
|
157
|
+
|
|
158
|
+
## Client ID Metadata Documents
|
|
159
|
+
|
|
160
|
+
`@lostgradient/mcp/oauth` exports Client ID Metadata Document fetching and the shared OAuth security utilities. Use `safeFetchPublicHttpsUrl` for any client-supplied metadata URL. It applies the complete SSRF boundary as one operation: the URL must use HTTPS, literal private addresses are rejected, every DNS result must be public, and redirects are disabled. Do not recreate those checks at a host call site.
|
|
161
|
+
|
|
162
|
+
The dedicated `@lostgradient/mcp/oauth/client-metadata-documents` subpath exposes the same safe fetch together with `fetchClientIdMetadataDocument` and `isClientIdMetadataDocumentUrl`. The general `/oauth` entry point also owns `isAddressInCidr`, `isValidCidr`, `isValidRedirectUri`, `isValidClientName`, `isExactContentType`, `withDeadline`, and IP canonicalization so an embedding host does not maintain a second security implementation.
|
|
163
|
+
|
|
112
164
|
## Subpaths
|
|
113
165
|
|
|
114
|
-
| Subpath
|
|
115
|
-
|
|
|
116
|
-
| `@lostgradient/mcp`
|
|
117
|
-
| `@lostgradient/mcp/logger`
|
|
118
|
-
| `@lostgradient/mcp/env`
|
|
119
|
-
| `@lostgradient/mcp/environment-schema`
|
|
120
|
-
| `@lostgradient/mcp/metrics`
|
|
121
|
-
| `@lostgradient/mcp/
|
|
166
|
+
| Subpath | Contents |
|
|
167
|
+
| --------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
168
|
+
| `@lostgradient/mcp` | The engine: server factory, registries, scope vocabularies, primitives |
|
|
169
|
+
| `@lostgradient/mcp/logger` | Host logger injection and the lazy default pino logger |
|
|
170
|
+
| `@lostgradient/mcp/env` | `parseMcpServerEnvironment` and `getEnvironment` |
|
|
171
|
+
| `@lostgradient/mcp/environment-schema` | The raw Zod shape, side-effect free |
|
|
172
|
+
| `@lostgradient/mcp/metrics` | The in-process metrics collector |
|
|
173
|
+
| `@lostgradient/mcp/oauth` | OAuth contracts, metadata fetching, and shared security utilities |
|
|
174
|
+
| `@lostgradient/mcp/oauth/stores` | Type-only contracts for durable OAuth storage |
|
|
175
|
+
| `@lostgradient/mcp/oauth/testing` | In-memory OAuth stores for tests |
|
|
176
|
+
| `@lostgradient/mcp/oauth/postgres` | PostgreSQL OAuth store implementations |
|
|
177
|
+
| `@lostgradient/mcp/oauth/client-metadata-documents` | Client ID Metadata Document validation and SSRF-safe fetching |
|
|
178
|
+
| `@lostgradient/mcp/rate-limit` | Sliding-window policy, stores, concurrency slots, and `429` responses |
|
|
179
|
+
| `@lostgradient/mcp/http` | Ordered MCP HTTP serving and per-user handler lifecycle |
|
|
180
|
+
| `@lostgradient/mcp/sveltekit` | Host-agnostic SvelteKit handle-chain mount |
|
|
181
|
+
| `@lostgradient/mcp/version` | The advertised package version |
|
|
122
182
|
|
|
123
183
|
## License
|
|
124
184
|
|