@codemem/mcp 0.31.3 → 0.32.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 (46) hide show
  1. package/dist/audit.d.ts +54 -0
  2. package/dist/audit.d.ts.map +1 -0
  3. package/dist/content.d.ts +13 -0
  4. package/dist/content.d.ts.map +1 -0
  5. package/dist/http.d.ts +38 -0
  6. package/dist/http.d.ts.map +1 -0
  7. package/dist/http.js +17075 -0
  8. package/dist/http.js.map +1 -0
  9. package/dist/index.d.ts +2 -10
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2 -602
  12. package/dist/memory-access.d.ts.map +1 -1
  13. package/dist/memory-kinds.d.ts +2 -0
  14. package/dist/memory-kinds.d.ts.map +1 -0
  15. package/dist/oauth.d.ts +176 -0
  16. package/dist/oauth.d.ts.map +1 -0
  17. package/dist/oidc.d.ts +35 -0
  18. package/dist/oidc.d.ts.map +1 -0
  19. package/dist/project-scope.d.ts +4 -0
  20. package/dist/project-scope.d.ts.map +1 -1
  21. package/dist/provider.d.ts +51 -0
  22. package/dist/provider.d.ts.map +1 -0
  23. package/dist/schemas.d.ts +36 -0
  24. package/dist/schemas.d.ts.map +1 -0
  25. package/dist/server-Djvf0Yik.js +488 -0
  26. package/dist/server-Djvf0Yik.js.map +1 -0
  27. package/dist/server.d.ts +5 -0
  28. package/dist/server.d.ts.map +1 -0
  29. package/dist/stdio.d.ts +9 -0
  30. package/dist/stdio.d.ts.map +1 -0
  31. package/dist/stdio.js +69 -0
  32. package/dist/stdio.js.map +1 -0
  33. package/dist/tool-context.d.ts +12 -0
  34. package/dist/tool-context.d.ts.map +1 -0
  35. package/dist/tools/items.d.ts +4 -0
  36. package/dist/tools/items.d.ts.map +1 -0
  37. package/dist/tools/learn.d.ts +3 -0
  38. package/dist/tools/learn.d.ts.map +1 -0
  39. package/dist/tools/schema.d.ts +3 -0
  40. package/dist/tools/schema.d.ts.map +1 -0
  41. package/dist/tools/search.d.ts +4 -0
  42. package/dist/tools/search.d.ts.map +1 -0
  43. package/dist/tools/timeline.d.ts +4 -0
  44. package/dist/tools/timeline.d.ts.map +1 -0
  45. package/package.json +19 -7
  46. package/dist/index.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @codemem/mcp — privacy-safe OAuth audit events.
3
+ *
4
+ * Phase 1 single-user remote MCP needs operator-visible security events
5
+ * (registration, authorize, OIDC callback, token issuance, revocation, bearer
6
+ * verification) without ever logging bearer tokens, authorization codes,
7
+ * client secrets, OIDC ID tokens, or private memory contents.
8
+ */
9
+ export type OAuthAuditKind = "registration" | "authorize" | "oidc_callback" | "token" | "refresh" | "rotation" | "revocation" | "bearer";
10
+ export type OAuthAuditOutcome = "success" | "denied" | "error";
11
+ export type BearerDenyReason = "missing_authorization_header" | "malformed_authorization_header" | "unknown_token" | "expired_token" | "revoked_token";
12
+ export interface OAuthAuditEventBase {
13
+ timestamp: string;
14
+ outcome: OAuthAuditOutcome;
15
+ reason?: string;
16
+ clientId?: string;
17
+ remoteAddress?: string;
18
+ }
19
+ export type OAuthAuditEvent = OAuthAuditEventBase & {
20
+ kind: OAuthAuditKind;
21
+ };
22
+ export type OAuthAuditEmitter = (event: OAuthAuditEvent) => void;
23
+ /**
24
+ * Build an audit event with redaction safety. Throws if a forbidden field
25
+ * leaks in; callers should never need to pass token/code material here.
26
+ */
27
+ export declare function buildOAuthAuditEvent(kind: OAuthAuditKind, fields: Omit<OAuthAuditEventBase, "timestamp"> & {
28
+ now?: number;
29
+ }): OAuthAuditEvent;
30
+ /**
31
+ * Wrap an audit emitter so any synchronous throw or stream-write failure stays
32
+ * contained. Audit logging is best-effort observability and must never break
33
+ * the OAuth/MCP request flow it observes. Failures are reported once per
34
+ * process to `console.error` so they remain visible without flooding output.
35
+ */
36
+ export declare function wrapAuditEmitterBestEffort(emit: OAuthAuditEmitter): OAuthAuditEmitter;
37
+ /**
38
+ * Default audit emitter writes one JSON object per line to stderr. This keeps
39
+ * MCP HTTP stdout reserved for protocol traffic and is greppable by operators
40
+ * via `journalctl` or a redirected log file.
41
+ */
42
+ export declare function createDefaultOAuthAuditEmitter(stream?: NodeJS.WriteStream): OAuthAuditEmitter;
43
+ /**
44
+ * No-op emitter, used when CODEMEM_MCP_AUDIT=0 or when callers explicitly
45
+ * want to suppress audit output (for example, embedded tests).
46
+ */
47
+ export declare function createSilentOAuthAuditEmitter(): OAuthAuditEmitter;
48
+ /**
49
+ * Resolve an emitter from environment configuration. `CODEMEM_MCP_AUDIT=0`,
50
+ * `false`, or `no` disables audit logging; anything else (including unset)
51
+ * uses the default stderr emitter.
52
+ */
53
+ export declare function resolveOAuthAuditEmitterFromEnv(value?: string | undefined): OAuthAuditEmitter;
54
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,cAAc,GACvB,cAAc,GACd,WAAW,GACX,eAAe,GACf,OAAO,GACP,SAAS,GACT,UAAU,GACV,YAAY,GACZ,QAAQ,CAAC;AAEZ,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GACzB,8BAA8B,GAC9B,gCAAgC,GAChC,eAAe,GACf,eAAe,GACf,eAAe,CAAC;AAEnB,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AAyBjE;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D,eAAe,CAYjB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,CAYrF;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC7C,MAAM,GAAE,MAAM,CAAC,WAA4B,GACzC,iBAAiB,CAInB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,IAAI,iBAAiB,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC9C,KAAK,qBAAgC,GACnC,iBAAiB,CAMnB"}
@@ -0,0 +1,13 @@
1
+ export declare function jsonContent(data: unknown): {
2
+ content: {
3
+ type: "text";
4
+ text: string;
5
+ }[];
6
+ };
7
+ export declare function errorContent(message: string): {
8
+ content: {
9
+ type: "text";
10
+ text: string;
11
+ }[];
12
+ };
13
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO;;;;;EAExC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM;;;;;EAE3C"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @codemem/mcp — MCP Streamable HTTP server bootstrap.
4
+ *
5
+ * Local-first HTTP transport for MCP clients. OAuth metadata and Dynamic Client
6
+ * Registration are exposed for remote MCP setup; public MCP requests require
7
+ * OAuth bearer tokens.
8
+ */
9
+ import { type Server } from "node:http";
10
+ import { MemoryStore } from "@codemem/core";
11
+ import { type OAuthAuditEmitter } from "./audit.js";
12
+ import { type OAuthAccessTokenStore } from "./oauth.js";
13
+ export declare const DEFAULT_MCP_HTTP_HOST = "127.0.0.1";
14
+ export declare const DEFAULT_MCP_HTTP_PORT = 38889;
15
+ export interface CodememMcpHttpOptions {
16
+ host?: string;
17
+ port?: number | string;
18
+ dbPath?: string;
19
+ allowUnsafePublic?: boolean;
20
+ publicUrl?: string;
21
+ oauthAccessTokenStore?: OAuthAccessTokenStore;
22
+ auditEmitter?: OAuthAuditEmitter;
23
+ }
24
+ export interface CodememMcpHttpServer {
25
+ server: Server;
26
+ store: MemoryStore;
27
+ url: string;
28
+ close: () => Promise<void>;
29
+ }
30
+ export declare function validateMcpHttpHost(host: string | undefined, allowUnsafePublic?: boolean): string;
31
+ export declare function isLoopbackHost(host: string): boolean;
32
+ export declare function isUnsafePublicBindAllowed(value?: string | undefined): boolean;
33
+ export declare function isAllowedMcpHttpRequestHost(header: string | undefined, expectedPort: number): boolean;
34
+ export declare function isAllowedMcpHttpRequestOrigin(header: string | undefined, expectedPort: number): boolean;
35
+ export declare function isAllowedMcpHttpRequestRemoteAddress(address: string | undefined): boolean;
36
+ export declare function parseMcpHttpPort(port: number | string | undefined): number;
37
+ export declare function startCodememMcpHttpServer(options?: CodememMcpHttpOptions): Promise<CodememMcpHttpServer>;
38
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAEH,OAAO,EAAsC,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAS3D,OAAO,EAGN,KAAK,iBAAiB,EAGtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAWN,KAAK,qBAAqB,EAC1B,MAAM,YAAY,CAAC;AASpB,eAAO,MAAM,qBAAqB,cAAc,CAAC;AACjD,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAU3C,MAAM,WAAW,qBAAq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