@hmharness/kernel 0.9.3 → 0.9.5

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/dist/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export * from './config.ts';
11
11
  export * from './context.ts';
12
12
  export * from './mcp.ts';
13
13
  export * from './goal.ts';
14
+ export * from './mcp2026.ts';
package/dist/index.js CHANGED
@@ -11,3 +11,4 @@ export * from "./config.js";
11
11
  export * from "./context.js";
12
12
  export * from "./mcp.js";
13
13
  export * from "./goal.js";
14
+ export * from "./mcp2026.js";
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @hmharness/kernel - MCP 2026-07-28 Conformance (P0-03)
3
+ *
4
+ * Updates the MCP client to conform to the 2026-07-28 specification:
5
+ * 1. Stateless core: operations don't require session state
6
+ * 2. Header-based routing: Mcp-Session-Id, Mcp-Protocol-Version headers
7
+ * 3. Tasks extension: long-running task lifecycle management
8
+ * 4. Authorization hardening: per-request auth validation
9
+ * 5. Cacheable list results: ETag/If-None-Match for tools/resources lists
10
+ *
11
+ * Reference: https://modelcontextprotocol.io/specification/2025-11-25
12
+ * (2026-07-28 is the latest ratification with these additions)
13
+ */
14
+ /** MCP protocol version we conform to */
15
+ export declare const MCP_PROTOCOL_VERSION = "2026-07-28";
16
+ /** Headers defined by the 2026-07-28 spec */
17
+ export declare const MCP_HEADERS: {
18
+ readonly sessionId: "Mcp-Session-Id";
19
+ readonly protocolVersion: "Mcp-Protocol-Version";
20
+ readonly lastEventId: "Last-Event-Id";
21
+ };
22
+ /** Task lifecycle states (Tasks extension) */
23
+ export type McpTaskStatus = 'submitted' | 'working' | 'input-required' | 'completed' | 'cancelled' | 'failed';
24
+ export interface McpTask {
25
+ id: string;
26
+ status: McpTaskStatus;
27
+ result?: unknown;
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ }
31
+ /**
32
+ * Build headers for an MCP request per the 2026-07-28 spec.
33
+ * Pure - testable.
34
+ */
35
+ export declare function buildMcpHeaders(opts: {
36
+ sessionId?: string;
37
+ protocolVersion?: string;
38
+ lastEventId?: string;
39
+ authorization?: string;
40
+ }): Record<string, string>;
41
+ /**
42
+ * Validate MCP response headers for protocol compliance.
43
+ * Pure - testable.
44
+ */
45
+ export declare function validateMcpResponseHeaders(headers: Record<string, string>): {
46
+ valid: boolean;
47
+ issues: string[];
48
+ sessionId?: string;
49
+ };
50
+ /**
51
+ * Determine if a tools/resources list response can be cached.
52
+ * The 2026-07-28 spec makes list results cacheable via ETag.
53
+ * Pure - testable.
54
+ */
55
+ export declare function isCacheableListResponse(headers: Record<string, string>): {
56
+ cacheable: boolean;
57
+ etag?: string;
58
+ };
59
+ /**
60
+ * Build a conditional list request using a cached ETag.
61
+ * Pure - testable.
62
+ */
63
+ export declare function buildConditionalListRequest(cachedEtag?: string): Record<string, string>;
64
+ /**
65
+ * Check if an HTTP 304 response means the cached list is still valid.
66
+ * Pure - testable.
67
+ */
68
+ export declare function isNotModified(status: number): boolean;
69
+ /**
70
+ * Task state machine per the Tasks extension.
71
+ * Pure - testable.
72
+ */
73
+ export declare function canTransitionTask(from: McpTaskStatus, to: McpTaskStatus): boolean;
74
+ /**
75
+ * Authorization check per the 2026-07-28 hardening requirements.
76
+ * Pure - testable.
77
+ */
78
+ export declare function validateMcpAuth(config: {
79
+ type: 'stdio' | 'http';
80
+ headers?: Record<string, string>;
81
+ }): {
82
+ authorized: boolean;
83
+ reason: string;
84
+ };
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @hmharness/kernel - MCP 2026-07-28 Conformance (P0-03)
3
+ *
4
+ * Updates the MCP client to conform to the 2026-07-28 specification:
5
+ * 1. Stateless core: operations don't require session state
6
+ * 2. Header-based routing: Mcp-Session-Id, Mcp-Protocol-Version headers
7
+ * 3. Tasks extension: long-running task lifecycle management
8
+ * 4. Authorization hardening: per-request auth validation
9
+ * 5. Cacheable list results: ETag/If-None-Match for tools/resources lists
10
+ *
11
+ * Reference: https://modelcontextprotocol.io/specification/2025-11-25
12
+ * (2026-07-28 is the latest ratification with these additions)
13
+ */
14
+ /** MCP protocol version we conform to */
15
+ export const MCP_PROTOCOL_VERSION = '2026-07-28';
16
+ /** Headers defined by the 2026-07-28 spec */
17
+ export const MCP_HEADERS = {
18
+ sessionId: 'Mcp-Session-Id',
19
+ protocolVersion: 'Mcp-Protocol-Version',
20
+ lastEventId: 'Last-Event-Id',
21
+ };
22
+ /**
23
+ * Build headers for an MCP request per the 2026-07-28 spec.
24
+ * Pure - testable.
25
+ */
26
+ export function buildMcpHeaders(opts) {
27
+ const headers = {
28
+ 'Content-Type': 'application/json',
29
+ [MCP_HEADERS.protocolVersion]: opts.protocolVersion ?? MCP_PROTOCOL_VERSION,
30
+ };
31
+ if (opts.sessionId)
32
+ headers[MCP_HEADERS.sessionId] = opts.sessionId;
33
+ if (opts.lastEventId)
34
+ headers[MCP_HEADERS.lastEventId] = opts.lastEventId;
35
+ if (opts.authorization)
36
+ headers['Authorization'] = opts.authorization;
37
+ return headers;
38
+ }
39
+ /**
40
+ * Validate MCP response headers for protocol compliance.
41
+ * Pure - testable.
42
+ */
43
+ export function validateMcpResponseHeaders(headers) {
44
+ const issues = [];
45
+ const version = headers[MCP_HEADERS.protocolVersion];
46
+ if (!version)
47
+ issues.push(`missing ${MCP_HEADERS.protocolVersion} header`);
48
+ else if (!version.startsWith('2026-'))
49
+ issues.push(`unsupported protocol version: ${version}`);
50
+ const sid = headers[MCP_HEADERS.sessionId];
51
+ if (sid)
52
+ return { valid: issues.length === 0, issues, sessionId: sid };
53
+ return { valid: issues.length === 0, issues };
54
+ }
55
+ /**
56
+ * Determine if a tools/resources list response can be cached.
57
+ * The 2026-07-28 spec makes list results cacheable via ETag.
58
+ * Pure - testable.
59
+ */
60
+ export function isCacheableListResponse(headers) {
61
+ const etag = headers['ETag'] || headers['etag'];
62
+ return { cacheable: Boolean(etag), etag };
63
+ }
64
+ /**
65
+ * Build a conditional list request using a cached ETag.
66
+ * Pure - testable.
67
+ */
68
+ export function buildConditionalListRequest(cachedEtag) {
69
+ if (!cachedEtag)
70
+ return {};
71
+ return { 'If-None-Match': cachedEtag };
72
+ }
73
+ /**
74
+ * Check if an HTTP 304 response means the cached list is still valid.
75
+ * Pure - testable.
76
+ */
77
+ export function isNotModified(status) {
78
+ return status === 304;
79
+ }
80
+ /**
81
+ * Task state machine per the Tasks extension.
82
+ * Pure - testable.
83
+ */
84
+ export function canTransitionTask(from, to) {
85
+ const transitions = {
86
+ 'submitted': ['working', 'cancelled', 'failed'],
87
+ 'working': ['input-required', 'completed', 'cancelled', 'failed'],
88
+ 'input-required': ['working', 'cancelled', 'failed'],
89
+ 'completed': [], // terminal
90
+ 'cancelled': [], // terminal
91
+ 'failed': [], // terminal
92
+ };
93
+ return transitions[from]?.includes(to) ?? false;
94
+ }
95
+ /**
96
+ * Authorization check per the 2026-07-28 hardening requirements.
97
+ * Pure - testable.
98
+ */
99
+ export function validateMcpAuth(config) {
100
+ if (config.type === 'stdio') {
101
+ // stdio doesn't need HTTP auth (local process boundary)
102
+ return { authorized: true, reason: 'stdio transport (local trust)' };
103
+ }
104
+ // HTTP transport requires Authorization header
105
+ const auth = config.headers?.['Authorization'];
106
+ if (!auth)
107
+ return { authorized: false, reason: 'HTTP transport requires Authorization header' };
108
+ if (!auth.startsWith('Bearer ') && !auth.startsWith('Basic ')) {
109
+ return { authorized: false, reason: 'Authorization must be Bearer or Basic scheme' };
110
+ }
111
+ return { authorized: true, reason: 'valid authorization scheme' };
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/kernel",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",