toolcraft 0.0.119 → 0.0.121

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 (153) hide show
  1. package/composition.json +17 -2
  2. package/dist/composition.json +17 -2
  3. package/dist/http.compile-check.d.ts +1 -0
  4. package/dist/http.compile-check.js +31 -0
  5. package/dist/http.d.ts +19 -0
  6. package/dist/http.js +62 -0
  7. package/dist/mcp.js +26 -11
  8. package/node_modules/jose/LICENSE.md +21 -0
  9. package/node_modules/jose/README.md +153 -0
  10. package/node_modules/jose/dist/types/index.d.ts +55 -0
  11. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +31 -0
  12. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +65 -0
  13. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +31 -0
  14. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +83 -0
  15. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +38 -0
  16. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +74 -0
  17. package/node_modules/jose/dist/types/jwk/embedded.d.ts +17 -0
  18. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +32 -0
  19. package/node_modules/jose/dist/types/jwks/local.d.ts +29 -0
  20. package/node_modules/jose/dist/types/jwks/remote.d.ts +237 -0
  21. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +36 -0
  22. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +33 -0
  23. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +42 -0
  24. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +33 -0
  25. package/node_modules/jose/dist/types/jws/general/sign.d.ts +53 -0
  26. package/node_modules/jose/dist/types/jws/general/verify.d.ts +41 -0
  27. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +35 -0
  28. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +91 -0
  29. package/node_modules/jose/dist/types/jwt/sign.d.ts +43 -0
  30. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +43 -0
  31. package/node_modules/jose/dist/types/jwt/verify.d.ts +37 -0
  32. package/node_modules/jose/dist/types/key/export.d.ts +33 -0
  33. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +47 -0
  34. package/node_modules/jose/dist/types/key/generate_secret.d.ts +35 -0
  35. package/node_modules/jose/dist/types/key/import.d.ts +83 -0
  36. package/node_modules/jose/dist/types/types.d.ts +852 -0
  37. package/node_modules/jose/dist/types/util/base64url.d.ts +9 -0
  38. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +18 -0
  39. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +17 -0
  40. package/node_modules/jose/dist/types/util/errors.d.ts +213 -0
  41. package/node_modules/jose/dist/webapi/index.js +32 -0
  42. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +27 -0
  43. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +27 -0
  44. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +159 -0
  45. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +167 -0
  46. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +31 -0
  47. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +182 -0
  48. package/node_modules/jose/dist/webapi/jwk/embedded.js +17 -0
  49. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +68 -0
  50. package/node_modules/jose/dist/webapi/jwks/local.js +119 -0
  51. package/node_modules/jose/dist/webapi/jwks/remote.js +179 -0
  52. package/node_modules/jose/dist/webapi/jws/compact/sign.js +18 -0
  53. package/node_modules/jose/dist/webapi/jws/compact/verify.js +21 -0
  54. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +89 -0
  55. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +110 -0
  56. package/node_modules/jose/dist/webapi/jws/general/sign.js +70 -0
  57. package/node_modules/jose/dist/webapi/jws/general/verify.js +24 -0
  58. package/node_modules/jose/dist/webapi/jwt/decrypt.js +23 -0
  59. package/node_modules/jose/dist/webapi/jwt/encrypt.js +101 -0
  60. package/node_modules/jose/dist/webapi/jwt/sign.js +52 -0
  61. package/node_modules/jose/dist/webapi/jwt/unsecured.js +63 -0
  62. package/node_modules/jose/dist/webapi/jwt/verify.js +15 -0
  63. package/node_modules/jose/dist/webapi/key/export.js +11 -0
  64. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +97 -0
  65. package/node_modules/jose/dist/webapi/key/generate_secret.js +40 -0
  66. package/node_modules/jose/dist/webapi/key/import.js +57 -0
  67. package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +15 -0
  68. package/node_modules/jose/dist/webapi/lib/aeskw.js +25 -0
  69. package/node_modules/jose/dist/webapi/lib/asn1.js +243 -0
  70. package/node_modules/jose/dist/webapi/lib/base64.js +22 -0
  71. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +43 -0
  72. package/node_modules/jose/dist/webapi/lib/check_key_type.js +122 -0
  73. package/node_modules/jose/dist/webapi/lib/content_encryption.js +217 -0
  74. package/node_modules/jose/dist/webapi/lib/crypto_key.js +136 -0
  75. package/node_modules/jose/dist/webapi/lib/deflate.js +44 -0
  76. package/node_modules/jose/dist/webapi/lib/ecdhes.js +52 -0
  77. package/node_modules/jose/dist/webapi/lib/helpers.js +19 -0
  78. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +27 -0
  79. package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -0
  80. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +107 -0
  81. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +238 -0
  82. package/node_modules/jose/dist/webapi/lib/key_management.js +186 -0
  83. package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +31 -0
  84. package/node_modules/jose/dist/webapi/lib/normalize_key.js +166 -0
  85. package/node_modules/jose/dist/webapi/lib/pbes2kw.js +42 -0
  86. package/node_modules/jose/dist/webapi/lib/rsaes.js +24 -0
  87. package/node_modules/jose/dist/webapi/lib/signing.js +68 -0
  88. package/node_modules/jose/dist/webapi/lib/type_checks.js +40 -0
  89. package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +10 -0
  90. package/node_modules/jose/dist/webapi/lib/validate_crit.js +33 -0
  91. package/node_modules/jose/dist/webapi/util/base64url.js +30 -0
  92. package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -0
  93. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +34 -0
  94. package/node_modules/jose/dist/webapi/util/errors.js +99 -0
  95. package/node_modules/jose/package.json +200 -0
  96. package/node_modules/tiny-http-mcp-server/LICENSE +21 -0
  97. package/node_modules/tiny-http-mcp-server/README.md +778 -0
  98. package/node_modules/tiny-http-mcp-server/dist/auth.d.ts +69 -0
  99. package/node_modules/tiny-http-mcp-server/dist/auth.js +261 -0
  100. package/node_modules/tiny-http-mcp-server/dist/cli.d.ts +20 -0
  101. package/node_modules/tiny-http-mcp-server/dist/cli.js +465 -0
  102. package/node_modules/tiny-http-mcp-server/dist/composition.json +30 -0
  103. package/node_modules/tiny-http-mcp-server/dist/express-middleware.d.ts +18 -0
  104. package/node_modules/tiny-http-mcp-server/dist/express-middleware.js +90 -0
  105. package/node_modules/tiny-http-mcp-server/dist/http-server.d.ts +49 -0
  106. package/node_modules/tiny-http-mcp-server/dist/http-server.js +264 -0
  107. package/node_modules/tiny-http-mcp-server/dist/http-transport.d.ts +164 -0
  108. package/node_modules/tiny-http-mcp-server/dist/http-transport.js +897 -0
  109. package/node_modules/tiny-http-mcp-server/dist/index.d.ts +13 -0
  110. package/node_modules/tiny-http-mcp-server/dist/index.js +6 -0
  111. package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.d.ts +6 -0
  112. package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.js +43 -0
  113. package/node_modules/tiny-http-mcp-server/dist/parse-body.d.ts +22 -0
  114. package/node_modules/tiny-http-mcp-server/dist/parse-body.js +150 -0
  115. package/node_modules/tiny-http-mcp-server/dist/server.d.ts +9 -0
  116. package/node_modules/tiny-http-mcp-server/dist/server.js +4 -0
  117. package/node_modules/tiny-http-mcp-server/dist/session.d.ts +18 -0
  118. package/node_modules/tiny-http-mcp-server/dist/session.js +37 -0
  119. package/node_modules/tiny-http-mcp-server/dist/sse.d.ts +11 -0
  120. package/node_modules/tiny-http-mcp-server/dist/sse.js +22 -0
  121. package/node_modules/tiny-http-mcp-server/dist/test-support.d.ts +10 -0
  122. package/node_modules/tiny-http-mcp-server/dist/test-support.js +398 -0
  123. package/node_modules/tiny-http-mcp-server/dist/testing.d.ts +59 -0
  124. package/node_modules/tiny-http-mcp-server/dist/testing.js +191 -0
  125. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/LICENSE +21 -0
  126. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +70 -0
  127. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +14 -0
  128. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +169 -0
  129. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +8 -0
  130. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +47 -0
  131. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +3 -0
  132. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +627 -0
  133. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +20 -0
  134. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.js +207 -0
  135. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.d.ts +2 -0
  136. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +7 -0
  137. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +40 -0
  138. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +164 -0
  139. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.d.ts +113 -0
  140. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.js +1 -0
  141. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +10 -0
  142. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +7 -0
  143. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.d.ts +1 -0
  144. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.js +11 -0
  145. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +32 -0
  146. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +388 -0
  147. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.d.ts +1 -0
  148. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.js +22 -0
  149. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/package.json +28 -0
  150. package/node_modules/tiny-http-mcp-server/package.json +59 -0
  151. package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
  152. package/node_modules/toolcraft-schema/package.json +1 -1
  153. package/package.json +11 -4
@@ -0,0 +1,13 @@
1
+ export { createServer, defineSchema, Image, Audio, File, toContentBlocks, fileTypeFromBuffer, JSON_RPC_ERROR_CODES, ToolError } from "tiny-stdio-mcp-server";
2
+ export type { Server, TypedSchema, ImageContent, AudioContent, EmbeddedResource, TextResourceContents, BlobResourceContents, ContentBlock, TextContent, FileTypeResult, ToolReturn, ServerOptions, ToolHandler, ToolDefinition, Tool, ToolAnnotations, ToolExecution, Icon, ContentAnnotations, ResourceLink, CallToolResult, PromptContentItem, PromptArgument, Prompt, PromptMessage, GetPromptResult, PromptHandler, PromptDefinition, Resource, ResourceTemplate, ResourceContents, ReadResourceResult, ResourceHandler, ResourceDefinition, ResourceTemplateDefinition, HandleResult, ContentItem, JSONSchema, JSONSchemaProperty, Transport, SDKTransport, JSONRPCRequest, JSONRPCResponse, JSONRPCError, JSONRPCMessage, JSONRPCNotification, InitializeResult } from "tiny-stdio-mcp-server";
3
+ export { createExpressMiddleware, createExpressOAuthHandlers, createProtectedResourceMetadataRouter } from "./express-middleware.js";
4
+ export type { CreateExpressOAuthHandlersOptions } from "./express-middleware.js";
5
+ export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
6
+ export type { HttpToolContext, HttpToolHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
7
+ export { TokenVerificationError } from "./auth.js";
8
+ export type { RequestAuthInfo, TokenVerifier, VerifiedAccessToken } from "./auth.js";
9
+ export { StreamableHttpTransport } from "./http-transport.js";
10
+ export type { HttpObservabilityEvent, HttpObservabilityOptions, StreamableHttpTransportOptions } from "./http-transport.js";
11
+ export type { Session, SessionStore } from "./session.js";
12
+ export { createJwksTokenVerifier } from "mcp-oauth";
13
+ export type { JwksTokenVerifier, JwksTokenVerifierOptions, JwksVerifiedAccessToken } from "mcp-oauth";
@@ -0,0 +1,6 @@
1
+ export { createServer, defineSchema, Image, Audio, File, toContentBlocks, fileTypeFromBuffer, JSON_RPC_ERROR_CODES, ToolError } from "tiny-stdio-mcp-server";
2
+ export { createExpressMiddleware, createExpressOAuthHandlers, createProtectedResourceMetadataRouter } from "./express-middleware.js";
3
+ export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
4
+ export { TokenVerificationError } from "./auth.js";
5
+ export { StreamableHttpTransport } from "./http-transport.js";
6
+ export { createJwksTokenVerifier } from "mcp-oauth";
@@ -0,0 +1,6 @@
1
+ import type { TokenVerifier } from "./auth.js";
2
+ export declare function loadOAuthVerifier(input: {
3
+ modulePath: string;
4
+ exportName?: string;
5
+ cwd?: string;
6
+ }): Promise<TokenVerifier>;
@@ -0,0 +1,43 @@
1
+ import path from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ function isWindowsAbsolutePath(value) {
4
+ if (value.length < 3) {
5
+ return false;
6
+ }
7
+ const drive = value.charCodeAt(0);
8
+ const separator = value[2];
9
+ const isLetter = (drive >= 65 && drive <= 90) || (drive >= 97 && drive <= 122);
10
+ return isLetter && value[1] === ":" && (separator === "\\" || separator === "/");
11
+ }
12
+ function resolveModuleSpecifier(modulePath, cwd) {
13
+ if (modulePath.startsWith("file:")) {
14
+ return modulePath;
15
+ }
16
+ if (modulePath.startsWith(".")
17
+ || modulePath.startsWith("/")
18
+ || isWindowsAbsolutePath(modulePath)) {
19
+ const resolvedPath = path.isAbsolute(modulePath)
20
+ ? modulePath
21
+ : path.resolve(cwd, modulePath);
22
+ return pathToFileURL(resolvedPath).href;
23
+ }
24
+ return modulePath;
25
+ }
26
+ function isTokenVerifier(value) {
27
+ if (typeof value !== "object"
28
+ || value === null
29
+ || !Object.prototype.hasOwnProperty.call(value, "verify")) {
30
+ return false;
31
+ }
32
+ return typeof value.verify === "function";
33
+ }
34
+ export async function loadOAuthVerifier(input) {
35
+ const exportName = input.exportName ?? "default";
36
+ const moduleSpecifier = resolveModuleSpecifier(input.modulePath, input.cwd ?? process.cwd());
37
+ const loadedModule = (await import(moduleSpecifier));
38
+ const verifier = loadedModule[exportName];
39
+ if (!isTokenVerifier(verifier)) {
40
+ throw new Error(`OAuth verifier export "${exportName}" from "${input.modulePath}" must be an object with a verify() method.`);
41
+ }
42
+ return verifier;
43
+ }
@@ -0,0 +1,22 @@
1
+ import type { IncomingMessage } from "node:http";
2
+ import type { JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse } from "tiny-stdio-mcp-server";
3
+ export interface ClassifiedBody {
4
+ entries: Array<JSONRPCMessage | null>;
5
+ messages: JSONRPCMessage[];
6
+ hasRequests: boolean;
7
+ hasNotifications: boolean;
8
+ hasResponses: boolean;
9
+ requests: JSONRPCRequest[];
10
+ notifications: JSONRPCNotification[];
11
+ responses: JSONRPCResponse[];
12
+ }
13
+ export interface BodyReadOptions {
14
+ maxBytes?: number;
15
+ maxBatchSize?: number;
16
+ }
17
+ export declare class JsonRpcMessageError extends Error {
18
+ readonly id: string | number | null;
19
+ readonly code: number;
20
+ constructor(id: string | number | null, code: number, message: string);
21
+ }
22
+ export declare function readAndClassifyBody(req: IncomingMessage, preParsed?: unknown, options?: BodyReadOptions): Promise<ClassifiedBody>;
@@ -0,0 +1,150 @@
1
+ import { parseMessage } from "tiny-stdio-mcp-server/jsonrpc";
2
+ export class JsonRpcMessageError extends Error {
3
+ id;
4
+ code;
5
+ constructor(id, code, message) {
6
+ super(message);
7
+ this.id = id;
8
+ this.code = code;
9
+ }
10
+ }
11
+ function isObjectRecord(value) {
12
+ return typeof value === "object" && value !== null && !Array.isArray(value);
13
+ }
14
+ function hasOwn(value, property) {
15
+ return Object.prototype.hasOwnProperty.call(value, property);
16
+ }
17
+ function isValidResponse(value) {
18
+ if (!isObjectRecord(value) || value.jsonrpc !== "2.0" || hasOwn(value, "method")) {
19
+ return false;
20
+ }
21
+ if (!hasOwn(value, "id")) {
22
+ return false;
23
+ }
24
+ if (value.id !== null &&
25
+ typeof value.id !== "string" &&
26
+ typeof value.id !== "number") {
27
+ return false;
28
+ }
29
+ const hasResult = hasOwn(value, "result");
30
+ const hasError = hasOwn(value, "error");
31
+ if (hasResult === hasError) {
32
+ return false;
33
+ }
34
+ if (!hasError) {
35
+ return true;
36
+ }
37
+ return (isObjectRecord(value.error) &&
38
+ typeof value.error.code === "number" &&
39
+ typeof value.error.message === "string");
40
+ }
41
+ function hasResponseFields(value) {
42
+ return isObjectRecord(value) && (hasOwn(value, "result") || hasOwn(value, "error"));
43
+ }
44
+ async function readStreamBody(req, maxBytes) {
45
+ const chunks = [];
46
+ let totalBytes = 0;
47
+ for await (const chunk of req) {
48
+ let bytes;
49
+ if (typeof chunk === "string") {
50
+ bytes = Buffer.from(chunk);
51
+ }
52
+ else if (chunk instanceof Uint8Array) {
53
+ bytes = chunk;
54
+ }
55
+ else {
56
+ bytes = Buffer.from(String(chunk));
57
+ }
58
+ totalBytes += bytes.byteLength;
59
+ if (maxBytes !== undefined && totalBytes > maxBytes) {
60
+ throw new Error("Payload too large");
61
+ }
62
+ chunks.push(bytes);
63
+ }
64
+ return Buffer.concat(chunks).toString("utf8");
65
+ }
66
+ async function readRawBody(req, preParsed, options) {
67
+ if (preParsed !== undefined) {
68
+ return preParsed;
69
+ }
70
+ const reqWithBody = req;
71
+ if (reqWithBody.body !== undefined) {
72
+ return reqWithBody.body;
73
+ }
74
+ const raw = await readStreamBody(req, options.maxBytes);
75
+ try {
76
+ return JSON.parse(raw);
77
+ }
78
+ catch {
79
+ throw new Error("Parse error");
80
+ }
81
+ }
82
+ function toMessageList(body, maxBatchSize) {
83
+ if (Array.isArray(body)) {
84
+ if (body.length === 0) {
85
+ throw new Error("Invalid Request");
86
+ }
87
+ if (maxBatchSize !== undefined && body.length > maxBatchSize) {
88
+ throw new Error("Batch size exceeds configured limit");
89
+ }
90
+ return body;
91
+ }
92
+ if (isObjectRecord(body)) {
93
+ return [body];
94
+ }
95
+ throw new Error("Invalid Request");
96
+ }
97
+ export async function readAndClassifyBody(req, preParsed, options = {}) {
98
+ const body = await readRawBody(req, preParsed, options);
99
+ const inputMessages = toMessageList(body, options.maxBatchSize);
100
+ const isBatch = Array.isArray(body);
101
+ const entries = [];
102
+ const requests = [];
103
+ const notifications = [];
104
+ const responses = [];
105
+ const messages = [];
106
+ for (const message of inputMessages) {
107
+ if (isValidResponse(message)) {
108
+ responses.push(message);
109
+ messages.push(message);
110
+ entries.push(message);
111
+ continue;
112
+ }
113
+ if (hasResponseFields(message)) {
114
+ if (!isBatch) {
115
+ throw new Error("Invalid Request");
116
+ }
117
+ entries.push(null);
118
+ continue;
119
+ }
120
+ const parsed = parseMessage(JSON.stringify(message));
121
+ if (!parsed.success) {
122
+ if (!isBatch) {
123
+ throw new JsonRpcMessageError(parsed.id, parsed.error.code, parsed.error.message);
124
+ }
125
+ entries.push(null);
126
+ continue;
127
+ }
128
+ if (parsed.isNotification) {
129
+ const notification = parsed.request;
130
+ notifications.push(notification);
131
+ messages.push(notification);
132
+ entries.push(notification);
133
+ continue;
134
+ }
135
+ const request = parsed.request;
136
+ requests.push(request);
137
+ messages.push(request);
138
+ entries.push(request);
139
+ }
140
+ return {
141
+ entries,
142
+ messages,
143
+ hasRequests: requests.length > 0,
144
+ hasNotifications: notifications.length > 0,
145
+ hasResponses: responses.length > 0,
146
+ requests,
147
+ notifications,
148
+ responses,
149
+ };
150
+ }
@@ -0,0 +1,9 @@
1
+ export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
2
+ export type { HttpToolContext, HttpToolHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
3
+ export { TokenVerificationError } from "./auth.js";
4
+ export type { RequestAuthInfo, TokenVerifier, VerifiedAccessToken } from "./auth.js";
5
+ export { StreamableHttpTransport } from "./http-transport.js";
6
+ export type { HttpObservabilityEvent, HttpObservabilityOptions, StreamableHttpTransportOptions } from "./http-transport.js";
7
+ export type { Session, SessionStore } from "./session.js";
8
+ export { createJwksTokenVerifier } from "mcp-oauth";
9
+ export type { JwksTokenVerifier, JwksTokenVerifierOptions, JwksVerifiedAccessToken } from "mcp-oauth";
@@ -0,0 +1,4 @@
1
+ export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
2
+ export { TokenVerificationError } from "./auth.js";
3
+ export { StreamableHttpTransport } from "./http-transport.js";
4
+ export { createJwksTokenVerifier } from "mcp-oauth";
@@ -0,0 +1,18 @@
1
+ export interface Session {
2
+ id: string;
3
+ initialized: boolean;
4
+ authSubject?: string;
5
+ protocolVersion?: string;
6
+ createdAt: Date;
7
+ lastSeenAt: Date;
8
+ }
9
+ export interface SessionStore {
10
+ create(id: string): Session;
11
+ get(id: string): Session | undefined;
12
+ delete(id: string): boolean;
13
+ has(id: string): boolean;
14
+ touch?(id: string): void;
15
+ entries?(): Iterable<Session>;
16
+ }
17
+ export declare function defaultSessionIdGenerator(): string;
18
+ export declare function createSessionStore(): SessionStore;
@@ -0,0 +1,37 @@
1
+ import { randomUUID } from "node:crypto";
2
+ export function defaultSessionIdGenerator() {
3
+ return randomUUID();
4
+ }
5
+ export function createSessionStore() {
6
+ const sessions = new Map();
7
+ return {
8
+ create(id) {
9
+ const session = {
10
+ id,
11
+ initialized: false,
12
+ createdAt: new Date(),
13
+ lastSeenAt: new Date(),
14
+ };
15
+ sessions.set(id, session);
16
+ return session;
17
+ },
18
+ get(id) {
19
+ return sessions.get(id);
20
+ },
21
+ delete(id) {
22
+ return sessions.delete(id);
23
+ },
24
+ has(id) {
25
+ return sessions.has(id);
26
+ },
27
+ touch(id) {
28
+ const session = sessions.get(id);
29
+ if (session !== undefined) {
30
+ session.lastSeenAt = new Date();
31
+ }
32
+ },
33
+ entries() {
34
+ return sessions.values();
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,11 @@
1
+ export interface SseEvent {
2
+ data: string;
3
+ id?: string;
4
+ event?: string;
5
+ }
6
+ export declare const SSE_HEADERS: {
7
+ readonly "Content-Type": "text/event-stream";
8
+ readonly "Cache-Control": "no-cache";
9
+ readonly Connection: "keep-alive";
10
+ };
11
+ export declare function formatSseEvent(event: SseEvent): string;
@@ -0,0 +1,22 @@
1
+ export const SSE_HEADERS = {
2
+ "Content-Type": "text/event-stream",
3
+ "Cache-Control": "no-cache",
4
+ Connection: "keep-alive",
5
+ };
6
+ export function formatSseEvent(event) {
7
+ const lines = [];
8
+ if (event.id !== undefined) {
9
+ lines.push(`id: ${event.id}`);
10
+ }
11
+ if (event.event !== undefined) {
12
+ lines.push(`event: ${event.event}`);
13
+ }
14
+ const dataLines = event.data
15
+ .replaceAll("\r\n", "\n")
16
+ .replaceAll("\r", "\n")
17
+ .split("\n");
18
+ for (const dataLine of dataLines) {
19
+ lines.push(`data: ${dataLine}`);
20
+ }
21
+ return `${lines.join("\n")}\n\n`;
22
+ }
@@ -0,0 +1,10 @@
1
+ import { type HttpServer } from "./http-server.js";
2
+ export declare function installInMemoryHttp(): void;
3
+ export declare function nodeFetch(input: string | URL, init?: RequestInit): Promise<Response>;
4
+ export declare function createTestMcpServer(options?: Partial<{
5
+ name: string;
6
+ version: string;
7
+ enableJsonResponse: boolean;
8
+ sessionIdGenerator: (() => string) | undefined;
9
+ oauth: import("./http-server.js").TinyHttpMcpServerOAuthOptions;
10
+ }>): HttpServer;