@kontext-dev/js-sdk 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.
- package/README.md +70 -0
- package/dist/adapters/ai/index.cjs +175 -0
- package/dist/adapters/ai/index.cjs.map +1 -0
- package/dist/adapters/ai/index.d.cts +51 -0
- package/dist/adapters/ai/index.d.ts +51 -0
- package/dist/adapters/ai/index.js +173 -0
- package/dist/adapters/ai/index.js.map +1 -0
- package/dist/adapters/cloudflare/index.cjs +598 -0
- package/dist/adapters/cloudflare/index.cjs.map +1 -0
- package/dist/adapters/cloudflare/index.d.cts +214 -0
- package/dist/adapters/cloudflare/index.d.ts +214 -0
- package/dist/adapters/cloudflare/index.js +594 -0
- package/dist/adapters/cloudflare/index.js.map +1 -0
- package/dist/adapters/cloudflare/react.cjs +156 -0
- package/dist/adapters/cloudflare/react.cjs.map +1 -0
- package/dist/adapters/cloudflare/react.d.cts +68 -0
- package/dist/adapters/cloudflare/react.d.ts +68 -0
- package/dist/adapters/cloudflare/react.js +152 -0
- package/dist/adapters/cloudflare/react.js.map +1 -0
- package/dist/adapters/react/index.cjs +146 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +103 -0
- package/dist/adapters/react/index.d.ts +103 -0
- package/dist/adapters/react/index.js +142 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/client/index.cjs +2415 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +125 -0
- package/dist/client/index.d.ts +125 -0
- package/dist/client/index.js +2412 -0
- package/dist/client/index.js.map +1 -0
- package/dist/errors.cjs +213 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +161 -0
- package/dist/errors.d.ts +161 -0
- package/dist/errors.js +201 -0
- package/dist/errors.js.map +1 -0
- package/dist/index-D5hS5PGn.d.ts +54 -0
- package/dist/index-DcL4a5Vq.d.cts +54 -0
- package/dist/index.cjs +4046 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4029 -0
- package/dist/index.js.map +1 -0
- package/dist/kontext-CgIBANFo.d.cts +308 -0
- package/dist/kontext-CgIBANFo.d.ts +308 -0
- package/dist/management/index.cjs +867 -0
- package/dist/management/index.cjs.map +1 -0
- package/dist/management/index.d.cts +467 -0
- package/dist/management/index.d.ts +467 -0
- package/dist/management/index.js +855 -0
- package/dist/management/index.js.map +1 -0
- package/dist/mcp/index.cjs +799 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +231 -0
- package/dist/mcp/index.d.ts +231 -0
- package/dist/mcp/index.js +797 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/oauth/index.cjs +418 -0
- package/dist/oauth/index.cjs.map +1 -0
- package/dist/oauth/index.d.cts +235 -0
- package/dist/oauth/index.d.ts +235 -0
- package/dist/oauth/index.js +414 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/server/index.cjs +1634 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +1629 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-CzhnlJHW.d.cts +397 -0
- package/dist/types-CzhnlJHW.d.ts +397 -0
- package/dist/types-RIzHnRpk.d.cts +23 -0
- package/dist/types-RIzHnRpk.d.ts +23 -0
- package/dist/verifier-CoJmYiw3.d.cts +109 -0
- package/dist/verifier-CoJmYiw3.d.ts +109 -0
- package/dist/verify/index.cjs +319 -0
- package/dist/verify/index.cjs.map +1 -0
- package/dist/verify/index.d.cts +63 -0
- package/dist/verify/index.d.ts +63 -0
- package/dist/verify/index.js +315 -0
- package/dist/verify/index.js.map +1 -0
- package/package.json +221 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { KontextMcp } from '../mcp/index.cjs';
|
|
2
|
+
import { K as KontextStorage } from '../types-RIzHnRpk.cjs';
|
|
3
|
+
import { KontextError } from '../errors.cjs';
|
|
4
|
+
import '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
+
import '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* KontextClient — protocol-agnostic facade over KontextMcp.
|
|
9
|
+
*
|
|
10
|
+
* Hides all MCP internals (SEARCH_TOOLS, EXECUTE_TOOL, -32042) behind a
|
|
11
|
+
* clean, typed API. Advanced users can access the underlying KontextMcp
|
|
12
|
+
* via `client.mcp`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { createKontextClient } from '@kontext-dev/js-sdk';
|
|
17
|
+
*
|
|
18
|
+
* const client = createKontextClient({
|
|
19
|
+
* clientId: 'your-client-id',
|
|
20
|
+
* redirectUri: 'http://localhost:3000/callback',
|
|
21
|
+
* onAuthRequired: (url) => open(url.toString()),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* await client.connect();
|
|
25
|
+
* const tools = await client.tools.list();
|
|
26
|
+
* const result = await client.tools.execute('github:repos', { query: 'mcp' });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @packageDocumentation
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
type ClientState = "idle" | "connecting" | "ready" | "needs_auth" | "failed";
|
|
33
|
+
interface KontextClientConfig {
|
|
34
|
+
clientId: string;
|
|
35
|
+
redirectUri: string;
|
|
36
|
+
/**
|
|
37
|
+
* Full URL of the MCP server endpoint.
|
|
38
|
+
* When provided, the client connects directly to this URL.
|
|
39
|
+
*
|
|
40
|
+
* @example "https://my-server.com/mcp"
|
|
41
|
+
*/
|
|
42
|
+
url?: string;
|
|
43
|
+
serverUrl?: string;
|
|
44
|
+
storage?: KontextStorage;
|
|
45
|
+
sessionKey?: string;
|
|
46
|
+
onAuthRequired: (url: URL) => string | URL | void | Promise<string | URL | void>;
|
|
47
|
+
onIntegrationRequired?: (url: string, info: {
|
|
48
|
+
id: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
}) => void | Promise<void>;
|
|
51
|
+
onStateChange?: (state: ClientState) => void;
|
|
52
|
+
}
|
|
53
|
+
interface KontextTool {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
inputSchema?: object;
|
|
58
|
+
server?: {
|
|
59
|
+
id: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface IntegrationInfo {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
connected: boolean;
|
|
67
|
+
connectUrl?: string;
|
|
68
|
+
reason?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ToolResult {
|
|
71
|
+
content: string;
|
|
72
|
+
raw: unknown;
|
|
73
|
+
}
|
|
74
|
+
interface ConnectSessionResult {
|
|
75
|
+
connectUrl: string;
|
|
76
|
+
sessionId: string;
|
|
77
|
+
expiresAt: string;
|
|
78
|
+
}
|
|
79
|
+
interface KontextClient {
|
|
80
|
+
readonly state: ClientState;
|
|
81
|
+
connect(): Promise<void>;
|
|
82
|
+
disconnect(): Promise<void>;
|
|
83
|
+
getConnectPageUrl(): Promise<ConnectSessionResult>;
|
|
84
|
+
readonly auth: {
|
|
85
|
+
signIn(): Promise<void>;
|
|
86
|
+
signOut(): Promise<void>;
|
|
87
|
+
handleCallback(url: string | URL): Promise<void>;
|
|
88
|
+
isCallback(url: string | URL): boolean;
|
|
89
|
+
readonly isAuthenticated: boolean;
|
|
90
|
+
};
|
|
91
|
+
readonly integrations: {
|
|
92
|
+
list(): Promise<IntegrationInfo[]>;
|
|
93
|
+
};
|
|
94
|
+
readonly tools: {
|
|
95
|
+
list(options?: {
|
|
96
|
+
limit?: number;
|
|
97
|
+
}): Promise<KontextTool[]>;
|
|
98
|
+
execute(toolId: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
99
|
+
};
|
|
100
|
+
on(event: "stateChange", handler: (state: ClientState) => void): () => void;
|
|
101
|
+
on(event: "error", handler: (error: KontextError) => void): () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Advanced escape hatch to the raw MCP client.
|
|
104
|
+
*
|
|
105
|
+
* Note: In hybrid/orchestrator mode (`createKontextClient` called without
|
|
106
|
+
* `url`), this is the gateway MCP client only. Tools from direct internal
|
|
107
|
+
* integrations are exposed through `client.tools`, not through this property.
|
|
108
|
+
*/
|
|
109
|
+
readonly mcp: KontextMcp;
|
|
110
|
+
}
|
|
111
|
+
declare function createSingleEndpointKontextClient(config: KontextClientConfig): KontextClient;
|
|
112
|
+
/**
|
|
113
|
+
* Primary SDK client entrypoint.
|
|
114
|
+
*
|
|
115
|
+
* - `config.url` set: single-endpoint mode.
|
|
116
|
+
* - `config.url` omitted: hybrid orchestrated mode.
|
|
117
|
+
*/
|
|
118
|
+
declare function createKontextClient(config: KontextClientConfig & {
|
|
119
|
+
url: string;
|
|
120
|
+
}): KontextClient;
|
|
121
|
+
declare function createKontextClient(config: Omit<KontextClientConfig, "url"> & {
|
|
122
|
+
url?: undefined;
|
|
123
|
+
}): KontextClient;
|
|
124
|
+
|
|
125
|
+
export { type ClientState, type ConnectSessionResult, type IntegrationInfo, type KontextClient, type KontextClientConfig, type KontextTool, type ToolResult, createKontextClient, createSingleEndpointKontextClient };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { KontextMcp } from '../mcp/index.js';
|
|
2
|
+
import { K as KontextStorage } from '../types-RIzHnRpk.js';
|
|
3
|
+
import { KontextError } from '../errors.js';
|
|
4
|
+
import '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
+
import '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* KontextClient — protocol-agnostic facade over KontextMcp.
|
|
9
|
+
*
|
|
10
|
+
* Hides all MCP internals (SEARCH_TOOLS, EXECUTE_TOOL, -32042) behind a
|
|
11
|
+
* clean, typed API. Advanced users can access the underlying KontextMcp
|
|
12
|
+
* via `client.mcp`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { createKontextClient } from '@kontext-dev/js-sdk';
|
|
17
|
+
*
|
|
18
|
+
* const client = createKontextClient({
|
|
19
|
+
* clientId: 'your-client-id',
|
|
20
|
+
* redirectUri: 'http://localhost:3000/callback',
|
|
21
|
+
* onAuthRequired: (url) => open(url.toString()),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* await client.connect();
|
|
25
|
+
* const tools = await client.tools.list();
|
|
26
|
+
* const result = await client.tools.execute('github:repos', { query: 'mcp' });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @packageDocumentation
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
type ClientState = "idle" | "connecting" | "ready" | "needs_auth" | "failed";
|
|
33
|
+
interface KontextClientConfig {
|
|
34
|
+
clientId: string;
|
|
35
|
+
redirectUri: string;
|
|
36
|
+
/**
|
|
37
|
+
* Full URL of the MCP server endpoint.
|
|
38
|
+
* When provided, the client connects directly to this URL.
|
|
39
|
+
*
|
|
40
|
+
* @example "https://my-server.com/mcp"
|
|
41
|
+
*/
|
|
42
|
+
url?: string;
|
|
43
|
+
serverUrl?: string;
|
|
44
|
+
storage?: KontextStorage;
|
|
45
|
+
sessionKey?: string;
|
|
46
|
+
onAuthRequired: (url: URL) => string | URL | void | Promise<string | URL | void>;
|
|
47
|
+
onIntegrationRequired?: (url: string, info: {
|
|
48
|
+
id: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
}) => void | Promise<void>;
|
|
51
|
+
onStateChange?: (state: ClientState) => void;
|
|
52
|
+
}
|
|
53
|
+
interface KontextTool {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
inputSchema?: object;
|
|
58
|
+
server?: {
|
|
59
|
+
id: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface IntegrationInfo {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
connected: boolean;
|
|
67
|
+
connectUrl?: string;
|
|
68
|
+
reason?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ToolResult {
|
|
71
|
+
content: string;
|
|
72
|
+
raw: unknown;
|
|
73
|
+
}
|
|
74
|
+
interface ConnectSessionResult {
|
|
75
|
+
connectUrl: string;
|
|
76
|
+
sessionId: string;
|
|
77
|
+
expiresAt: string;
|
|
78
|
+
}
|
|
79
|
+
interface KontextClient {
|
|
80
|
+
readonly state: ClientState;
|
|
81
|
+
connect(): Promise<void>;
|
|
82
|
+
disconnect(): Promise<void>;
|
|
83
|
+
getConnectPageUrl(): Promise<ConnectSessionResult>;
|
|
84
|
+
readonly auth: {
|
|
85
|
+
signIn(): Promise<void>;
|
|
86
|
+
signOut(): Promise<void>;
|
|
87
|
+
handleCallback(url: string | URL): Promise<void>;
|
|
88
|
+
isCallback(url: string | URL): boolean;
|
|
89
|
+
readonly isAuthenticated: boolean;
|
|
90
|
+
};
|
|
91
|
+
readonly integrations: {
|
|
92
|
+
list(): Promise<IntegrationInfo[]>;
|
|
93
|
+
};
|
|
94
|
+
readonly tools: {
|
|
95
|
+
list(options?: {
|
|
96
|
+
limit?: number;
|
|
97
|
+
}): Promise<KontextTool[]>;
|
|
98
|
+
execute(toolId: string, args?: Record<string, unknown>): Promise<ToolResult>;
|
|
99
|
+
};
|
|
100
|
+
on(event: "stateChange", handler: (state: ClientState) => void): () => void;
|
|
101
|
+
on(event: "error", handler: (error: KontextError) => void): () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Advanced escape hatch to the raw MCP client.
|
|
104
|
+
*
|
|
105
|
+
* Note: In hybrid/orchestrator mode (`createKontextClient` called without
|
|
106
|
+
* `url`), this is the gateway MCP client only. Tools from direct internal
|
|
107
|
+
* integrations are exposed through `client.tools`, not through this property.
|
|
108
|
+
*/
|
|
109
|
+
readonly mcp: KontextMcp;
|
|
110
|
+
}
|
|
111
|
+
declare function createSingleEndpointKontextClient(config: KontextClientConfig): KontextClient;
|
|
112
|
+
/**
|
|
113
|
+
* Primary SDK client entrypoint.
|
|
114
|
+
*
|
|
115
|
+
* - `config.url` set: single-endpoint mode.
|
|
116
|
+
* - `config.url` omitted: hybrid orchestrated mode.
|
|
117
|
+
*/
|
|
118
|
+
declare function createKontextClient(config: KontextClientConfig & {
|
|
119
|
+
url: string;
|
|
120
|
+
}): KontextClient;
|
|
121
|
+
declare function createKontextClient(config: Omit<KontextClientConfig, "url"> & {
|
|
122
|
+
url?: undefined;
|
|
123
|
+
}): KontextClient;
|
|
124
|
+
|
|
125
|
+
export { type ClientState, type ConnectSessionResult, type IntegrationInfo, type KontextClient, type KontextClientConfig, type KontextTool, type ToolResult, createKontextClient, createSingleEndpointKontextClient };
|