integrate-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/LICENSE +22 -0
- package/README.md +639 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/config/types.d.ts +34 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +440 -0
- package/dist/plugins/generic.d.ts +79 -0
- package/dist/plugins/generic.d.ts.map +1 -0
- package/dist/plugins/github.d.ts +51 -0
- package/dist/plugins/github.d.ts.map +1 -0
- package/dist/plugins/gmail.d.ts +48 -0
- package/dist/plugins/gmail.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +58 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/protocol/jsonrpc.d.ts +32 -0
- package/dist/protocol/jsonrpc.d.ts.map +1 -0
- package/dist/protocol/messages.d.ts +130 -0
- package/dist/protocol/messages.d.ts.map +1 -0
- package/dist/transport/http-session.d.ts +67 -0
- package/dist/transport/http-session.d.ts.map +1 -0
- package/dist/transport/http-stream.d.ts +69 -0
- package/dist/transport/http-stream.d.ts.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Plugin
|
|
3
|
+
* Enables GitHub tools with OAuth configuration
|
|
4
|
+
*/
|
|
5
|
+
import type { MCPPlugin } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* GitHub plugin configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface GitHubPluginConfig {
|
|
10
|
+
/** GitHub OAuth client ID */
|
|
11
|
+
clientId: string;
|
|
12
|
+
/** GitHub OAuth client secret */
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
/** Additional OAuth scopes (default: ['repo', 'user']) */
|
|
15
|
+
scopes?: string[];
|
|
16
|
+
/** OAuth redirect URI */
|
|
17
|
+
redirectUri?: string;
|
|
18
|
+
/** GitHub API base URL (default: https://api.github.com) */
|
|
19
|
+
apiBaseUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Default GitHub tools that this plugin enables
|
|
23
|
+
* These should match the tool names exposed by your MCP server
|
|
24
|
+
*/
|
|
25
|
+
declare const GITHUB_TOOLS: readonly ["github/createIssue", "github/listIssues", "github/getIssue", "github/updateIssue", "github/closeIssue", "github/createPullRequest", "github/listPullRequests", "github/getPullRequest", "github/mergePullRequest", "github/listRepositories", "github/getRepository", "github/createRepository", "github/listBranches", "github/createBranch", "github/getUser", "github/listCommits", "github/getCommit"];
|
|
26
|
+
/**
|
|
27
|
+
* GitHub Plugin
|
|
28
|
+
*
|
|
29
|
+
* Enables GitHub integration with OAuth authentication
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const client = createMCPClient({
|
|
34
|
+
* serverUrl: 'http://localhost:3000/mcp',
|
|
35
|
+
* plugins: [
|
|
36
|
+
* githubPlugin({
|
|
37
|
+
* clientId: process.env.GITHUB_CLIENT_ID!,
|
|
38
|
+
* clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
39
|
+
* scopes: ['repo', 'user', 'read:org'],
|
|
40
|
+
* }),
|
|
41
|
+
* ],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function githubPlugin(config: GitHubPluginConfig): MCPPlugin<GitHubPluginConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Export tool names for type inference
|
|
48
|
+
*/
|
|
49
|
+
export type GitHubTools = typeof GITHUB_TOOLS[number];
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=github.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/plugins/github.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,QAAA,MAAM,YAAY,uZAkBR,CAAC;AAEX;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC,CA0BtF;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gmail Plugin
|
|
3
|
+
* Enables Gmail tools with OAuth configuration
|
|
4
|
+
*/
|
|
5
|
+
import type { MCPPlugin } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Gmail plugin configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface GmailPluginConfig {
|
|
10
|
+
/** Google OAuth client ID */
|
|
11
|
+
clientId: string;
|
|
12
|
+
/** Google OAuth client secret */
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
/** Additional OAuth scopes (default: Gmail API scopes) */
|
|
15
|
+
scopes?: string[];
|
|
16
|
+
/** OAuth redirect URI */
|
|
17
|
+
redirectUri?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default Gmail tools that this plugin enables
|
|
21
|
+
* These should match the tool names exposed by your MCP server
|
|
22
|
+
*/
|
|
23
|
+
declare const GMAIL_TOOLS: readonly ["gmail/sendEmail", "gmail/listEmails", "gmail/getEmail", "gmail/deleteEmail", "gmail/searchEmails", "gmail/markAsRead", "gmail/markAsUnread", "gmail/addLabel", "gmail/removeLabel", "gmail/listLabels", "gmail/createLabel", "gmail/getDraft", "gmail/createDraft", "gmail/updateDraft", "gmail/deleteDraft", "gmail/sendDraft"];
|
|
24
|
+
/**
|
|
25
|
+
* Gmail Plugin
|
|
26
|
+
*
|
|
27
|
+
* Enables Gmail integration with OAuth authentication
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const client = createMCPClient({
|
|
32
|
+
* serverUrl: 'http://localhost:3000/mcp',
|
|
33
|
+
* plugins: [
|
|
34
|
+
* gmailPlugin({
|
|
35
|
+
* clientId: process.env.GMAIL_CLIENT_ID!,
|
|
36
|
+
* clientSecret: process.env.GMAIL_CLIENT_SECRET!,
|
|
37
|
+
* }),
|
|
38
|
+
* ],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function gmailPlugin(config: GmailPluginConfig): MCPPlugin<GmailPluginConfig>;
|
|
43
|
+
/**
|
|
44
|
+
* Export tool names for type inference
|
|
45
|
+
*/
|
|
46
|
+
export type GmailTools = typeof GMAIL_TOOLS[number];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=gmail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmail.d.ts","sourceRoot":"","sources":["../../src/plugins/gmail.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,QAAA,MAAM,WAAW,6UAiBP,CAAC;AAEX;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,CAAC,CA4BnF;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin System Types
|
|
3
|
+
* Inspired by BetterAuth's provider pattern
|
|
4
|
+
*/
|
|
5
|
+
import type { MCPClient } from "../client.js";
|
|
6
|
+
/**
|
|
7
|
+
* OAuth Configuration for a plugin
|
|
8
|
+
*/
|
|
9
|
+
export interface OAuthConfig<TConfig = Record<string, unknown>> {
|
|
10
|
+
/** OAuth provider identifier (e.g., 'github', 'google') */
|
|
11
|
+
provider: string;
|
|
12
|
+
/** OAuth client ID */
|
|
13
|
+
clientId: string;
|
|
14
|
+
/** OAuth client secret */
|
|
15
|
+
clientSecret: string;
|
|
16
|
+
/** Required OAuth scopes */
|
|
17
|
+
scopes: string[];
|
|
18
|
+
/** Redirect URI for OAuth flow */
|
|
19
|
+
redirectUri?: string;
|
|
20
|
+
/** Provider-specific configuration */
|
|
21
|
+
config?: TConfig;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* MCP Plugin Interface
|
|
25
|
+
*
|
|
26
|
+
* Plugins enable specific tools and configure OAuth providers
|
|
27
|
+
*/
|
|
28
|
+
export interface MCPPlugin<TConfig = Record<string, unknown>> {
|
|
29
|
+
/** Unique plugin identifier */
|
|
30
|
+
id: string;
|
|
31
|
+
/** List of tool names this plugin enables */
|
|
32
|
+
tools: string[];
|
|
33
|
+
/** OAuth configuration for this plugin */
|
|
34
|
+
oauth?: OAuthConfig<TConfig>;
|
|
35
|
+
/** Called when the plugin is initialized with the client */
|
|
36
|
+
onInit?: (client: MCPClient) => Promise<void> | void;
|
|
37
|
+
/** Called before the client connects to the server */
|
|
38
|
+
onBeforeConnect?: (client: MCPClient) => Promise<void> | void;
|
|
39
|
+
/** Called after the client successfully connects */
|
|
40
|
+
onAfterConnect?: (client: MCPClient) => Promise<void> | void;
|
|
41
|
+
/** Called when the client disconnects */
|
|
42
|
+
onDisconnect?: (client: MCPClient) => Promise<void> | void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper type to extract plugin IDs from an array of plugins
|
|
46
|
+
*/
|
|
47
|
+
export type ExtractPluginIds<T extends readonly MCPPlugin[]> = T[number]["id"];
|
|
48
|
+
/**
|
|
49
|
+
* Helper type to extract tools from an array of plugins
|
|
50
|
+
*/
|
|
51
|
+
export type ExtractPluginTools<T extends readonly MCPPlugin[]> = T[number]["tools"][number];
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if a plugin has OAuth configuration
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasOAuthConfig(plugin: MCPPlugin): plugin is MCPPlugin & {
|
|
56
|
+
oauth: OAuthConfig;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;CA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
import type { JSONRPCRequest, JSONRPCResponse, JSONRPCNotification } from "./messages.js";
|
|
5
|
+
export declare function generateRequestId(): number;
|
|
6
|
+
/**
|
|
7
|
+
* Create a JSON-RPC request
|
|
8
|
+
*/
|
|
9
|
+
export declare function createRequest(method: string, params?: unknown): JSONRPCRequest;
|
|
10
|
+
/**
|
|
11
|
+
* Create a JSON-RPC notification (no response expected)
|
|
12
|
+
*/
|
|
13
|
+
export declare function createNotification(method: string, params?: unknown): JSONRPCNotification;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a response is an error
|
|
16
|
+
*/
|
|
17
|
+
export declare function isErrorResponse(response: JSONRPCResponse): response is JSONRPCResponse & {
|
|
18
|
+
error: NonNullable<unknown>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Extract result from a successful response
|
|
22
|
+
*/
|
|
23
|
+
export declare function getResult<T>(response: JSONRPCResponse<T>): T;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a JSON-RPC message from string
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseMessage(message: string): JSONRPCResponse | JSONRPCNotification;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize a JSON-RPC message to string
|
|
30
|
+
*/
|
|
31
|
+
export declare function serializeMessage(message: JSONRPCRequest | JSONRPCNotification): string;
|
|
32
|
+
//# sourceMappingURL=jsonrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"","sources":["../../src/protocol/jsonrpc.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAMvB,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,OAAO,GACf,cAAc,CAOhB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,OAAO,GACf,mBAAmB,CAMrB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,eAAe,GACxB,QAAQ,IAAI,eAAe,GAAG;IAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAAE,CAE/D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAO5D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,mBAAmB,CAMnF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,cAAc,GAAG,mBAAmB,GAC5C,MAAM,CAER"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Protocol Message Types
|
|
3
|
+
* Based on JSON-RPC 2.0 specification with MCP extensions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* JSON-RPC 2.0 Request
|
|
7
|
+
*/
|
|
8
|
+
export interface JSONRPCRequest {
|
|
9
|
+
jsonrpc: "2.0";
|
|
10
|
+
id: string | number;
|
|
11
|
+
method: string;
|
|
12
|
+
params?: Record<string, unknown> | unknown[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* JSON-RPC 2.0 Response (Success)
|
|
16
|
+
*/
|
|
17
|
+
export interface JSONRPCSuccessResponse<T = unknown> {
|
|
18
|
+
jsonrpc: "2.0";
|
|
19
|
+
id: string | number;
|
|
20
|
+
result: T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* JSON-RPC 2.0 Response (Error)
|
|
24
|
+
*/
|
|
25
|
+
export interface JSONRPCErrorResponse {
|
|
26
|
+
jsonrpc: "2.0";
|
|
27
|
+
id: string | number;
|
|
28
|
+
error: {
|
|
29
|
+
code: number;
|
|
30
|
+
message: string;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* JSON-RPC 2.0 Notification (no response expected)
|
|
36
|
+
*/
|
|
37
|
+
export interface JSONRPCNotification {
|
|
38
|
+
jsonrpc: "2.0";
|
|
39
|
+
method: string;
|
|
40
|
+
params?: Record<string, unknown> | unknown[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Union type for any JSON-RPC response
|
|
44
|
+
*/
|
|
45
|
+
export type JSONRPCResponse<T = unknown> = JSONRPCSuccessResponse<T> | JSONRPCErrorResponse;
|
|
46
|
+
/**
|
|
47
|
+
* MCP Tool Definition
|
|
48
|
+
*/
|
|
49
|
+
export interface MCPTool {
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: "object";
|
|
54
|
+
properties?: Record<string, unknown>;
|
|
55
|
+
required?: string[];
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* MCP Tools List Response
|
|
61
|
+
*/
|
|
62
|
+
export interface MCPToolsListResponse {
|
|
63
|
+
tools: MCPTool[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* MCP Tool Call Request Parameters
|
|
67
|
+
*/
|
|
68
|
+
export interface MCPToolCallParams {
|
|
69
|
+
name: string;
|
|
70
|
+
arguments?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* MCP Tool Call Response
|
|
74
|
+
*/
|
|
75
|
+
export interface MCPToolCallResponse {
|
|
76
|
+
content: Array<{
|
|
77
|
+
type: "text" | "image" | "resource";
|
|
78
|
+
text?: string;
|
|
79
|
+
data?: string;
|
|
80
|
+
mimeType?: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
isError?: boolean;
|
|
84
|
+
_meta?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* MCP Protocol Methods
|
|
88
|
+
*/
|
|
89
|
+
export declare enum MCPMethod {
|
|
90
|
+
INITIALIZE = "initialize",
|
|
91
|
+
TOOLS_LIST = "tools/list",
|
|
92
|
+
TOOLS_CALL = "tools/call",
|
|
93
|
+
RESOURCES_LIST = "resources/list",
|
|
94
|
+
RESOURCES_READ = "resources/read",
|
|
95
|
+
PROMPTS_LIST = "prompts/list",
|
|
96
|
+
PROMPTS_GET = "prompts/get"
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Initialize request parameters
|
|
100
|
+
*/
|
|
101
|
+
export interface MCPInitializeParams {
|
|
102
|
+
protocolVersion: string;
|
|
103
|
+
capabilities: {
|
|
104
|
+
tools?: Record<string, unknown>;
|
|
105
|
+
resources?: Record<string, unknown>;
|
|
106
|
+
prompts?: Record<string, unknown>;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
};
|
|
109
|
+
clientInfo: {
|
|
110
|
+
name: string;
|
|
111
|
+
version: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Initialize response
|
|
116
|
+
*/
|
|
117
|
+
export interface MCPInitializeResponse {
|
|
118
|
+
protocolVersion: string;
|
|
119
|
+
capabilities: {
|
|
120
|
+
tools?: Record<string, unknown>;
|
|
121
|
+
resources?: Record<string, unknown>;
|
|
122
|
+
prompts?: Record<string, unknown>;
|
|
123
|
+
[key: string]: unknown;
|
|
124
|
+
};
|
|
125
|
+
serverInfo: {
|
|
126
|
+
name: string;
|
|
127
|
+
version: string;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/protocol/messages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,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BAAqB;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Session-Based Transport for MCP
|
|
3
|
+
* Uses POST for request/response and optional SSE for notifications
|
|
4
|
+
* Compatible with MCP StreamableHTTPServer with sessions
|
|
5
|
+
*/
|
|
6
|
+
import type { JSONRPCResponse, JSONRPCNotification } from "../protocol/messages.js";
|
|
7
|
+
export type MessageHandler = (message: JSONRPCResponse | JSONRPCNotification) => void;
|
|
8
|
+
export interface HttpSessionTransportOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** Timeout for requests in milliseconds */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* HTTP Session Transport
|
|
16
|
+
* Maintains a session with the MCP server
|
|
17
|
+
* - Sends requests via POST
|
|
18
|
+
* - Receives responses in POST response body
|
|
19
|
+
* - Optionally listens for notifications via SSE
|
|
20
|
+
*/
|
|
21
|
+
export declare class HttpSessionTransport {
|
|
22
|
+
private url;
|
|
23
|
+
private headers;
|
|
24
|
+
private timeout;
|
|
25
|
+
private messageHandlers;
|
|
26
|
+
private sessionId?;
|
|
27
|
+
private sseController?;
|
|
28
|
+
private connected;
|
|
29
|
+
constructor(options: HttpSessionTransportOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Initialize session (no persistent connection needed)
|
|
32
|
+
*/
|
|
33
|
+
connect(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Send a request to the server and get immediate response
|
|
36
|
+
*/
|
|
37
|
+
sendRequest<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Start SSE listener for server-initiated notifications
|
|
40
|
+
*/
|
|
41
|
+
private startSSEListener;
|
|
42
|
+
/**
|
|
43
|
+
* Process SSE stream for server notifications
|
|
44
|
+
*/
|
|
45
|
+
private processSSEStream;
|
|
46
|
+
/**
|
|
47
|
+
* Handle incoming notification from SSE
|
|
48
|
+
*/
|
|
49
|
+
private handleNotification;
|
|
50
|
+
/**
|
|
51
|
+
* Register a message handler for notifications
|
|
52
|
+
*/
|
|
53
|
+
onMessage(handler: MessageHandler): () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Disconnect from the server
|
|
56
|
+
*/
|
|
57
|
+
disconnect(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if transport is connected
|
|
60
|
+
*/
|
|
61
|
+
isConnected(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get current session ID
|
|
64
|
+
*/
|
|
65
|
+
getSessionId(): string | undefined;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=http-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-session.d.ts","sourceRoot":"","sources":["../../src/transport/http-session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,eAAe,GAAG,mBAAmB,KAC3C,IAAI,CAAC;AAEV,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAC,CAAkB;IACxC,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,EAAE,2BAA2B;IAMhD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;OAEG;IACG,WAAW,CAAC,CAAC,GAAG,OAAO,EAC3B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,CAAC,CAAC;IAiEb;;OAEG;YACW,gBAAgB;IAiC9B;;OAEG;YACW,gBAAgB;IAiC9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,IAAI;IAS9C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBjC;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;CAGnC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Streaming Transport for MCP
|
|
3
|
+
* Implements HTTP streaming with newline-delimited JSON (NDJSON)
|
|
4
|
+
* Compatible with MCP's StreamableHTTPServer
|
|
5
|
+
*/
|
|
6
|
+
import type { JSONRPCResponse, JSONRPCNotification } from "../protocol/messages.js";
|
|
7
|
+
export type MessageHandler = (message: JSONRPCResponse | JSONRPCNotification) => void;
|
|
8
|
+
export interface HttpStreamTransportOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** Timeout for requests in milliseconds */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
/** Heartbeat interval in milliseconds (default: 30000) */
|
|
14
|
+
heartbeatInterval?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* HTTP Streaming Transport
|
|
18
|
+
* Handles bidirectional communication with MCP server via HTTP streaming
|
|
19
|
+
* Uses newline-delimited JSON (NDJSON) over a single persistent connection
|
|
20
|
+
*/
|
|
21
|
+
export declare class HttpStreamTransport {
|
|
22
|
+
private url;
|
|
23
|
+
private headers;
|
|
24
|
+
private timeout;
|
|
25
|
+
private heartbeatInterval;
|
|
26
|
+
private messageHandlers;
|
|
27
|
+
private pendingRequests;
|
|
28
|
+
private streamController?;
|
|
29
|
+
private connected;
|
|
30
|
+
private heartbeatTimer?;
|
|
31
|
+
constructor(options: HttpStreamTransportOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Connect to the MCP server and establish SSE connection
|
|
34
|
+
*/
|
|
35
|
+
connect(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Process incoming SSE stream
|
|
38
|
+
*/
|
|
39
|
+
private processStream;
|
|
40
|
+
/**
|
|
41
|
+
* Start sending periodic heartbeats to keep connection alive
|
|
42
|
+
*/
|
|
43
|
+
private startHeartbeat;
|
|
44
|
+
/**
|
|
45
|
+
* Handle incoming message from server
|
|
46
|
+
*/
|
|
47
|
+
private handleMessage;
|
|
48
|
+
/**
|
|
49
|
+
* Send a raw message to the server via POST (internal use)
|
|
50
|
+
*/
|
|
51
|
+
private sendRawMessage;
|
|
52
|
+
/**
|
|
53
|
+
* Send a request to the server
|
|
54
|
+
*/
|
|
55
|
+
sendRequest<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Register a message handler for notifications and other messages
|
|
58
|
+
*/
|
|
59
|
+
onMessage(handler: MessageHandler): () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Disconnect from the server
|
|
62
|
+
*/
|
|
63
|
+
disconnect(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if transport is connected
|
|
66
|
+
*/
|
|
67
|
+
isConnected(): boolean;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=http-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-stream.d.ts","sourceRoot":"","sources":["../../src/transport/http-stream.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,eAAe,GAAG,mBAAmB,KAC3C,IAAI,CAAC;AAEV,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,eAAe,CAOT;IACd,OAAO,CAAC,gBAAgB,CAAC,CAAkB;IAC3C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,cAAc,CAAC,CAAiC;gBAE5C,OAAO,EAAE,0BAA0B;IAO/C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2C9B;;OAEG;YACW,aAAa;IAiD3B;;OAEG;IACH,OAAO,CAAC,cAAc;IAetB;;OAEG;IACH,OAAO,CAAC,aAAa;IA8BrB;;OAEG;YACW,cAAc;IAgB5B;;OAEG;IACG,WAAW,CAAC,CAAC,GAAG,OAAO,EAC3B,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,CAAC,CAAC;IA8Cb;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,IAAI;IAS9C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCjC;;OAEG;IACH,WAAW,IAAI,OAAO;CAGvB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "integrate-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type-safe TypeScript SDK for MCP Client with plugin-based OAuth provider configuration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/YOUR_USERNAME/integrate-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/YOUR_USERNAME/integrate-sdk/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/YOUR_USERNAME/integrate-sdk#readme",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "bun build src/index.ts --outdir dist --target node --format esm && bun run build:types",
|
|
28
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
29
|
+
"dev": "bun --watch src/index.ts",
|
|
30
|
+
"type-check": "tsc --noEmit",
|
|
31
|
+
"test": "bun test tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts",
|
|
32
|
+
"test:watch": "bun test --watch tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts",
|
|
33
|
+
"test:unit": "bun test tests/protocol tests/plugins tests/client",
|
|
34
|
+
"test:integration": "bun test tests/integration/simple-integration.test.ts",
|
|
35
|
+
"test:coverage": "bun test --coverage tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"mcp",
|
|
39
|
+
"client",
|
|
40
|
+
"sdk",
|
|
41
|
+
"typescript",
|
|
42
|
+
"oauth",
|
|
43
|
+
"plugin"
|
|
44
|
+
],
|
|
45
|
+
"author": "",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/bun": "latest",
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"typescript": ">=5.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|