ogment 0.2.2 → 0.2.3

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/config.d.ts CHANGED
@@ -19,5 +19,5 @@ export declare const CONFIG_DIR: string;
19
19
  export declare const CREDENTIALS_PATH: string;
20
20
  export declare const CLI_CLIENT_NAME = "Ogment CLI";
21
21
  export declare const CLI_REDIRECT_HOST = "127.0.0.1";
22
- export declare const VERSION = "0.2.2";
22
+ export declare const VERSION = "0.2.3";
23
23
  //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -33,4 +33,4 @@ export const CLI_REDIRECT_HOST = '127.0.0.1';
33
33
  // ---------------------------------------------------------------------------
34
34
  // Version
35
35
  // ---------------------------------------------------------------------------
36
- export const VERSION = '0.2.2';
36
+ export const VERSION = '0.2.3';
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * MCP HTTP client — sends JSON-RPC requests to Ogment's MCP proxy.
3
3
  *
4
- * Shared by both the stdio bridge (serve.ts) and CLI commands (servers, call).
4
+ * Handles the MCP Streamable HTTP transport:
5
+ * 1. Initialize session on first request to a server
6
+ * 2. Cache session ID (mcp-session-id header)
7
+ * 3. Re-initialize automatically if session expires
5
8
  */
6
9
  export interface McpTool {
7
10
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../src/mcp-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAmDD,qDAAqD;AACrD,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,sBAKlF;AAED,qDAAqD;AACrD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,8BAM9B"}
1
+ {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../src/mcp-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAyHD,qDAAqD;AACrD,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,sBAKlF;AAED,qDAAqD;AACrD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,8BAM9B"}
@@ -1,14 +1,62 @@
1
1
  /**
2
2
  * MCP HTTP client — sends JSON-RPC requests to Ogment's MCP proxy.
3
3
  *
4
- * Shared by both the stdio bridge (serve.ts) and CLI commands (servers, call).
4
+ * Handles the MCP Streamable HTTP transport:
5
+ * 1. Initialize session on first request to a server
6
+ * 2. Cache session ID (mcp-session-id header)
7
+ * 3. Re-initialize automatically if session expires
5
8
  */
6
- import { MCP_ENDPOINT } from './config.js';
9
+ import { MCP_ENDPOINT, VERSION } from './config.js';
7
10
  // ---------------------------------------------------------------------------
8
- // Core JSON-RPC request
11
+ // Session management
12
+ // ---------------------------------------------------------------------------
13
+ /** Per-endpoint session cache (endpoint URL → session ID). */
14
+ const sessions = new Map();
15
+ /** Initialize an MCP session and return the session ID. */
16
+ async function initializeSession(endpoint, token) {
17
+ const res = await fetch(endpoint, {
18
+ method: 'POST',
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ Authorization: `Bearer ${token}`,
22
+ },
23
+ body: JSON.stringify({
24
+ jsonrpc: '2.0',
25
+ method: 'initialize',
26
+ id: Date.now(),
27
+ params: {
28
+ protocolVersion: '2024-11-05',
29
+ capabilities: {},
30
+ clientInfo: { name: 'ogment-cli', version: VERSION },
31
+ },
32
+ }),
33
+ });
34
+ if (!res.ok) {
35
+ const text = await res.text();
36
+ const sanitized = text.length > 200 ? text.slice(0, 200) + '…' : text;
37
+ throw new Error(`MCP session init failed (${res.status}): ${sanitized}`);
38
+ }
39
+ const sessionId = res.headers.get('mcp-session-id');
40
+ if (!sessionId) {
41
+ throw new Error('MCP server did not return a session ID');
42
+ }
43
+ return sessionId;
44
+ }
45
+ /** Ensure a session exists for the given endpoint, initializing if needed. */
46
+ async function ensureSession(endpoint, token) {
47
+ const existing = sessions.get(endpoint);
48
+ if (existing)
49
+ return existing;
50
+ const sessionId = await initializeSession(endpoint, token);
51
+ sessions.set(endpoint, sessionId);
52
+ return sessionId;
53
+ }
54
+ // ---------------------------------------------------------------------------
55
+ // Core JSON-RPC request (with session handling)
9
56
  // ---------------------------------------------------------------------------
10
57
  async function mcpRequest(orgSlug, serverPath, token, method, params) {
11
58
  const endpoint = MCP_ENDPOINT(orgSlug, serverPath);
59
+ const sessionId = await ensureSession(endpoint, token);
12
60
  const body = {
13
61
  jsonrpc: '2.0',
14
62
  method,
@@ -16,17 +64,32 @@ async function mcpRequest(orgSlug, serverPath, token, method, params) {
16
64
  };
17
65
  if (params)
18
66
  body.params = params;
19
- const res = await fetch(endpoint, {
67
+ let res = await fetch(endpoint, {
20
68
  method: 'POST',
21
69
  headers: {
22
70
  'Content-Type': 'application/json',
23
71
  Authorization: `Bearer ${token}`,
72
+ 'mcp-session-id': sessionId,
24
73
  },
25
74
  body: JSON.stringify(body),
26
75
  });
76
+ // Session expired — re-initialize once and retry
77
+ if (res.status === 404 || res.status === 400) {
78
+ sessions.delete(endpoint);
79
+ const newSessionId = await initializeSession(endpoint, token);
80
+ sessions.set(endpoint, newSessionId);
81
+ res = await fetch(endpoint, {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ Authorization: `Bearer ${token}`,
86
+ 'mcp-session-id': newSessionId,
87
+ },
88
+ body: JSON.stringify(body),
89
+ });
90
+ }
27
91
  if (!res.ok) {
28
92
  const text = await res.text();
29
- // Truncate error bodies to avoid leaking server internals into agent logs
30
93
  const sanitized = text.length > 200 ? text.slice(0, 200) + '…' : text;
31
94
  throw new Error(`MCP request failed (${res.status}): ${sanitized}`);
32
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ogment",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Ogment Vault CLI — secure your AI agents' SaaS credentials",
5
5
  "type": "module",
6
6
  "bin": {