@lostgradient/mcp 0.1.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 (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/dist/chunk-mf3t0afg.js +4 -0
  4. package/dist/chunk-psnez3q2.js +111 -0
  5. package/dist/chunk-taxyscge.js +67 -0
  6. package/dist/chunk-v14p4gng.js +25 -0
  7. package/dist/chunk-wmkqd45r.js +14 -0
  8. package/dist/conformance-fixture-registration.d.ts +30 -0
  9. package/dist/conformance-server.d.ts +1 -0
  10. package/dist/env.d.ts +59 -0
  11. package/dist/env.js +9 -0
  12. package/dist/environment-schema.d.ts +29 -0
  13. package/dist/environment-schema.js +6 -0
  14. package/dist/golden-prompts.d.ts +42 -0
  15. package/dist/handler-context.d.ts +16 -0
  16. package/dist/index.d.ts +25 -0
  17. package/dist/index.js +1326 -0
  18. package/dist/localhost-request-validation.d.ts +2 -0
  19. package/dist/logger.d.ts +39 -0
  20. package/dist/logger.js +14 -0
  21. package/dist/long-running-operation-support.d.ts +34 -0
  22. package/dist/metrics.d.ts +64 -0
  23. package/dist/metrics.js +6 -0
  24. package/dist/prompts/index.d.ts +5 -0
  25. package/dist/prompts/summarize.d.ts +4 -0
  26. package/dist/resources/index.d.ts +4 -0
  27. package/dist/resources/user-profile.d.ts +1 -0
  28. package/dist/scope-vocabulary.d.ts +127 -0
  29. package/dist/scopes.d.ts +49 -0
  30. package/dist/server.d.ts +113 -0
  31. package/dist/supported-scopes.d.ts +25 -0
  32. package/dist/template-registry.d.ts +16 -0
  33. package/dist/tool-response.d.ts +94 -0
  34. package/dist/tools/get-user-profile.d.ts +8 -0
  35. package/dist/tools/index.d.ts +16 -0
  36. package/dist/tools/list-audit-events.d.ts +11 -0
  37. package/dist/type-assertions.d.ts +1 -0
  38. package/dist/types/primitives.d.ts +130 -0
  39. package/dist/ui-extension-support.d.ts +20 -0
  40. package/dist/version.d.ts +23 -0
  41. package/dist/version.js +6 -0
  42. package/package.json +73 -0
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ export declare const listAuditEventsTool: import("../index.js").McpToolDefinition<z.ZodObject<{
3
+ cursor: z.ZodOptional<z.ZodString>;
4
+ page_size: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
5
+ }, z.core.$strip>, z.ZodObject<{
6
+ items: z.ZodArray<z.ZodObject<{
7
+ identifier: z.ZodString;
8
+ message: z.ZodString;
9
+ }, z.core.$strip>>;
10
+ next_cursor: z.ZodNullable<z.ZodString>;
11
+ }, z.core.$strip>, "profile:read" | "audit:read" | "prompts:read">;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,130 @@
1
+ import type { z } from 'zod';
2
+ import type { CallToolResult, GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/server';
3
+ export type McpUserProfile = {
4
+ id: string;
5
+ email: string;
6
+ name: string;
7
+ image: string | null;
8
+ role: string;
9
+ };
10
+ export type McpContext = {
11
+ userId: string;
12
+ user: McpUserProfile;
13
+ /**
14
+ * OBS-001: the same request identifier `application.ts` generated at
15
+ * the HTTP boundary (`X-Request-Id`), carried through OAuth token
16
+ * validation (`McpRequestAuthExtra.requestId`) into every tool,
17
+ * resource, and prompt handler. Lets one connector action be traced end
18
+ * to end through logs without correlating on anything secret (a bearer
19
+ * token, a session cookie). Optional because standalone test contexts
20
+ * (`createTestContext`) have no real HTTP request to derive one from.
21
+ */
22
+ requestId?: string;
23
+ /**
24
+ * PROTO-002: the SDK's own per-request `AbortSignal`
25
+ * (`ctx.mcpReq.signal`), threaded through so a handler that awaits a
26
+ * cancellable operation (e.g. `runWithStandardizedTimeout` from
27
+ * `long-running-operation-support.ts`) can pass it straight through and
28
+ * genuinely stop work when the caller disconnects or sends
29
+ * `notifications/cancelled` — not just abandon a wrapper promise.
30
+ */
31
+ signal: AbortSignal;
32
+ /**
33
+ * PROTO-002 / S-11: publishes a `notifications/resources/updated` event
34
+ * for `uri`, scoped to only the authenticated user this context was
35
+ * built for (see `applications/web/src/lib/mcp-user-event-bus.ts`).
36
+ * Undefined when no event bus is wired for this request (e.g. a
37
+ * standalone test context) — nothing to publish to in that case.
38
+ */
39
+ publishResourceUpdate?: (uri: string) => Promise<void>;
40
+ };
41
+ /**
42
+ * META-001: the four tool-safety hints the `2026-07-28` era gives real
43
+ * weight to. All four are required (not optional) so a tool definition
44
+ * that omits one is a compile-time error, not a silent gap a reviewer has
45
+ * to notice by hand.
46
+ */
47
+ export type McpToolAnnotations = {
48
+ /** The tool only reads data; it never mutates state. */
49
+ readOnlyHint: boolean;
50
+ /** Calling the tool can cause irreversible or destructive effects. */
51
+ destructiveHint: boolean;
52
+ /** Calling the tool twice with the same input has no additional effect. */
53
+ idempotentHint: boolean;
54
+ /** The tool interacts with an open-ended external world, not a fixed set of resources. */
55
+ openWorldHint: boolean;
56
+ };
57
+ /**
58
+ * META-001: `title`, `description`, and `annotations` are required (not
59
+ * optional), which is what turns "forgot to add metadata" into a
60
+ * `tsc` failure on the tool's own file instead of a silent gap discovered
61
+ * later against a live connector. `outputSchema` stays optional — a tool
62
+ * with no structured result genuinely has none to declare — but when it
63
+ * is present the handler's return type is checked against it, so a
64
+ * mismatched `structuredContent` is also a compile-time error.
65
+ *
66
+ * `InputSchema`/`OutputSchema` default to the widest legal type so
67
+ * `McpToolDefinition` (no type arguments) can still be used as the
68
+ * element type of a heterogeneous `allTools` array; individual tool
69
+ * files should let `defineTool` infer their concrete schema types instead
70
+ * of writing the type arguments out by hand.
71
+ */
72
+ export type McpToolDefinition<InputSchema extends z.ZodType = z.ZodType, OutputSchema extends z.ZodType | undefined = z.ZodType | undefined, Scope extends string = string> = {
73
+ name: string;
74
+ title: string;
75
+ description: string;
76
+ inputSchema: InputSchema;
77
+ outputSchema?: OutputSchema;
78
+ annotations: McpToolAnnotations;
79
+ /**
80
+ * AUTHZ-001: the single OAuth scope a caller's access token must carry to
81
+ * invoke this tool, checked before `handler` runs (never before —
82
+ * `tools/list` is unaffected, so a client can still see a tool it does
83
+ * not currently have the scope to call). Required, not optional: an
84
+ * operation with no meaningfully distinct access requirement still
85
+ * declares the scope that best describes what it does, rather than the
86
+ * type system silently allowing "no scope check" to mean "public."
87
+ */
88
+ requiredScope: Scope;
89
+ /** MCP Apps UI metadata (`_meta.ui.resourceUri`, `_meta.ui.visibility`). See the package `CLAUDE.md`. */
90
+ _meta?: Record<string, unknown>;
91
+ handler(input: z.infer<InputSchema>, context: McpContext): Promise<OutputSchema extends z.ZodType ? // The SDK only validates `structuredContent` against `outputSchema`
92
+ CallToolResult & {
93
+ structuredContent?: z.infer<OutputSchema>;
94
+ } : CallToolResult>;
95
+ };
96
+ /**
97
+ * Identity helper that exists only for inference: writing
98
+ * `export const fooTool = defineTool({ ... })` lets TypeScript infer
99
+ * `InputSchema`/`OutputSchema` from the literal `inputSchema`/`outputSchema`
100
+ * values instead of the author spelling out `McpToolDefinition<X, Y>` by
101
+ * hand on every tool.
102
+ */
103
+ export declare function defineTool<InputSchema extends z.ZodType, OutputSchema extends z.ZodType | undefined = undefined, Scope extends string = string>(definition: McpToolDefinition<InputSchema, OutputSchema, Scope>): McpToolDefinition<InputSchema, OutputSchema, Scope>;
104
+ export type McpResourceDefinition<Scope extends string = string> = {
105
+ name: string;
106
+ title: string;
107
+ uri: string;
108
+ description: string;
109
+ mimeType: string;
110
+ /** AUTHZ-001: see `McpToolDefinition.requiredScope` — same contract, checked before `resources/read` reaches `handler`. */
111
+ requiredScope: Scope;
112
+ handler(uri: URL, context: McpContext): Promise<ReadResourceResult>;
113
+ };
114
+ /**
115
+ * Identity helper matching `defineTool`, so a resource can be written
116
+ * against a vocabulary-bound definer rather than a bare type annotation.
117
+ */
118
+ export declare function defineResource<Scope extends string = string>(definition: McpResourceDefinition<Scope>): McpResourceDefinition<Scope>;
119
+ export type McpPromptDefinition<Arguments extends Record<string, z.ZodType> | undefined = Record<string, z.ZodType> | undefined, Scope extends string = string> = {
120
+ name: string;
121
+ title: string;
122
+ description: string;
123
+ arguments: Arguments;
124
+ /** AUTHZ-001: see `McpToolDefinition.requiredScope` — same contract, checked before `prompts/get` reaches `handler`. */
125
+ requiredScope: Scope;
126
+ handler(arguments_: Arguments extends Record<string, z.ZodType> ? {
127
+ [Key in keyof Arguments]: z.infer<Arguments[Key]>;
128
+ } : Record<string, never>, context: McpContext): Promise<GetPromptResult>;
129
+ };
130
+ export declare function definePrompt<Arguments extends Record<string, z.ZodType> | undefined, Scope extends string = string>(definition: McpPromptDefinition<Arguments, Scope>): McpPromptDefinition<Arguments, Scope>;
@@ -0,0 +1,20 @@
1
+ import type { McpRegistry } from './scope-vocabulary.js';
2
+ /**
3
+ * CONTENT-001 / review finding: advertising the MCP Apps UI extension is
4
+ * not just gated on the `MCP_ENABLE_UI_EXTENSION` flag (which defaults off,
5
+ * but an operator -- or this repository's own setup wizard -- can still
6
+ * turn it on) -- it also requires at least one registered resource that is
7
+ * actually an MCP App (`RESOURCE_MIME_TYPE`). `packages/mcp-apps` ships no
8
+ * application today, so this predicate is always `false` in this
9
+ * repository, mechanically keeping the capability advertised as absent
10
+ * even if the flag is turned on by mistake.
11
+ *
12
+ * This is the single source of truth for that predicate. `server.ts`'s
13
+ * real `/mcp` capabilities and `oauth-routes.ts`'s authorization-server
14
+ * metadata `extensions` field both call this function rather than each
15
+ * re-deriving their own copy of it, so a client can never discover UI
16
+ * extension support in OAuth metadata and then receive server capabilities
17
+ * without it (or vice versa) -- the two advertisements are mechanically
18
+ * kept in agreement, not just conventionally.
19
+ */
20
+ export declare function hasRegisteredUiExtensionResource(registry: McpRegistry): boolean;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The version this server advertises over the wire.
3
+ *
4
+ * A checked-in constant rather than a read of `package.json`, for two
5
+ * reasons that pull in the same direction:
6
+ *
7
+ * - A plain string literal survives every bundler by construction. The
8
+ * alternative a consumer would otherwise inherit —
9
+ * `createRequire(import.meta.url)('../package.json')` — resolves
10
+ * relative to the *generated bundle* rather than to this source file,
11
+ * so a host that bundles this package advertises the host's version, or
12
+ * fails outright for a nested output chunk.
13
+ * - It reads nothing at runtime, so it cannot be the reason importing this
14
+ * package touches the filesystem.
15
+ *
16
+ * The obvious cost of a duplicated literal is drift, and that is exactly
17
+ * what `version.test.ts` removes: it asserts this constant equals
18
+ * `package.json`'s `version`, so bumping one without the other is a red
19
+ * test rather than a wrong number on the wire. That test is the only
20
+ * thing making this approach safe — do not delete it to silence a release
21
+ * bump; update this constant instead.
22
+ */
23
+ export declare const PACKAGE_VERSION = "0.1.0";
@@ -0,0 +1,6 @@
1
+ import {
2
+ PACKAGE_VERSION
3
+ } from "./chunk-mf3t0afg.js";
4
+ export {
5
+ PACKAGE_VERSION
6
+ };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@lostgradient/mcp",
3
+ "version": "0.1.0",
4
+ "description": "A Model Context Protocol server engine: registries, scope vocabularies, and an OAuth-ready request boundary.",
5
+ "license": "MIT",
6
+ "author": "Steve Kinney <hello@stevekinney.net>",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "!dist/**/*.test.*",
12
+ "!dist/**/*.map",
13
+ "README.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./logger": {
25
+ "types": "./dist/logger.d.ts",
26
+ "import": "./dist/logger.js",
27
+ "default": "./dist/logger.js"
28
+ },
29
+ "./env": {
30
+ "types": "./dist/env.d.ts",
31
+ "import": "./dist/env.js",
32
+ "default": "./dist/env.js"
33
+ },
34
+ "./metrics": {
35
+ "types": "./dist/metrics.d.ts",
36
+ "import": "./dist/metrics.js",
37
+ "default": "./dist/metrics.js"
38
+ },
39
+ "./environment-schema": {
40
+ "types": "./dist/environment-schema.d.ts",
41
+ "import": "./dist/environment-schema.js",
42
+ "default": "./dist/environment-schema.js"
43
+ },
44
+ "./version": {
45
+ "types": "./dist/version.d.ts",
46
+ "import": "./dist/version.js",
47
+ "default": "./dist/version.js"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "scripts": {
52
+ "build": "bun run build.ts",
53
+ "lint": "eslint src/",
54
+ "test": "LOG_LEVEL=info NODE_ENV=test DATABASE_URL=postgresql://test:test@localhost/test bun test",
55
+ "test:conformance": "NODE_ENV=test MCP_CONFORMANCE_PORT=3137 bun ./src/conformance-server.ts",
56
+ "typecheck": "tsc --noEmit",
57
+ "verify:package": "bun run verify-package.ts"
58
+ },
59
+ "dependencies": {
60
+ "@modelcontextprotocol/core": "^2.0.0",
61
+ "@modelcontextprotocol/ext-apps": "^1.7.5",
62
+ "@modelcontextprotocol/node": "^2.0.0",
63
+ "@modelcontextprotocol/server": "^2.0.0",
64
+ "pino": "^10.3.1",
65
+ "zod": "^4.4.3"
66
+ },
67
+ "devDependencies": {
68
+ "@modelcontextprotocol/client": "^2.0.0",
69
+ "@types/node": "^26.2.0",
70
+ "pino-pretty": "^13.1.3",
71
+ "typescript": "6.0.3"
72
+ }
73
+ }