integrate-sdk 0.3.7 → 0.3.8

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 (40) hide show
  1. package/dist/index.js +40 -0
  2. package/dist/server.js +15 -0
  3. package/dist/src/adapters/nextjs-oauth-redirect.d.ts +34 -0
  4. package/dist/src/adapters/nextjs-oauth-redirect.d.ts.map +1 -0
  5. package/dist/src/index.d.ts +3 -1
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/oauth/types.d.ts +0 -9
  8. package/dist/src/oauth/types.d.ts.map +1 -1
  9. package/dist/src/oauth/window-manager.d.ts +1 -1
  10. package/dist/src/oauth/window-manager.d.ts.map +1 -1
  11. package/package.json +3 -15
  12. package/dist/src/adapters/nextjs-callback.d.ts +0 -44
  13. package/dist/src/adapters/nextjs-callback.d.ts.map +0 -1
  14. package/src/adapters/auto-routes.ts +0 -217
  15. package/src/adapters/base-handler.ts +0 -212
  16. package/src/adapters/nextjs-callback.tsx +0 -160
  17. package/src/adapters/nextjs.ts +0 -318
  18. package/src/adapters/tanstack-start.ts +0 -264
  19. package/src/client.ts +0 -952
  20. package/src/config/types.ts +0 -180
  21. package/src/errors.ts +0 -207
  22. package/src/index.ts +0 -110
  23. package/src/integrations/vercel-ai.ts +0 -104
  24. package/src/oauth/manager.ts +0 -307
  25. package/src/oauth/pkce.ts +0 -127
  26. package/src/oauth/types.ts +0 -101
  27. package/src/oauth/window-manager.ts +0 -322
  28. package/src/plugins/generic.ts +0 -119
  29. package/src/plugins/github-client.ts +0 -345
  30. package/src/plugins/github.ts +0 -122
  31. package/src/plugins/gmail-client.ts +0 -114
  32. package/src/plugins/gmail.ts +0 -108
  33. package/src/plugins/server-client.ts +0 -20
  34. package/src/plugins/types.ts +0 -89
  35. package/src/protocol/jsonrpc.ts +0 -88
  36. package/src/protocol/messages.ts +0 -145
  37. package/src/server.ts +0 -117
  38. package/src/transport/http-session.ts +0 -322
  39. package/src/transport/http-stream.ts +0 -331
  40. package/src/utils/naming.ts +0 -52
@@ -1,89 +0,0 @@
1
- /**
2
- * Plugin System Types
3
- * Inspired by BetterAuth's provider pattern
4
- */
5
-
6
- import type { MCPClient } from "../client.js";
7
-
8
- /**
9
- * OAuth Configuration for a plugin
10
- *
11
- * CLIENT-SIDE: You no longer need to provide clientId/clientSecret in the browser.
12
- * These should be kept server-side in your OAuth API routes for security.
13
- *
14
- * SERVER-SIDE: OAuth credentials are provided via API route configuration
15
- * using createNextOAuthHandler() or createTanStackOAuthHandler().
16
- */
17
- export interface OAuthConfig {
18
- /** OAuth provider identifier (e.g., 'github', 'google') */
19
- provider: string;
20
-
21
- /**
22
- * OAuth client ID (optional - only needed for legacy direct MCP server calls)
23
- * @deprecated Keep client ID server-side in OAuth API route configuration
24
- */
25
- clientId?: string | undefined;
26
-
27
- /**
28
- * OAuth client secret (optional - only needed for legacy direct MCP server calls)
29
- * @deprecated Keep client secret server-side in OAuth API route configuration
30
- */
31
- clientSecret?: string | undefined;
32
-
33
- /** Required OAuth scopes */
34
- scopes: string[];
35
-
36
- /** Redirect URI for OAuth flow */
37
- redirectUri?: string;
38
-
39
- /** Provider-specific configuration */
40
- config?: unknown;
41
- }
42
-
43
- /**
44
- * MCP Plugin Interface
45
- *
46
- * Plugins enable specific tools and configure OAuth providers
47
- */
48
- export interface MCPPlugin {
49
- /** Unique plugin identifier */
50
- id: string;
51
-
52
- /** List of tool names this plugin enables */
53
- tools: string[];
54
-
55
- /** OAuth configuration for this plugin */
56
- oauth?: OAuthConfig;
57
-
58
- /** Called when the plugin is initialized with the client */
59
- onInit?: (client: MCPClient<any>) => Promise<void> | void;
60
-
61
- /** Called before the client connects to the server */
62
- onBeforeConnect?: (client: MCPClient<any>) => Promise<void> | void;
63
-
64
- /** Called after the client successfully connects */
65
- onAfterConnect?: (client: MCPClient<any>) => Promise<void> | void;
66
-
67
- /** Called when the client disconnects */
68
- onDisconnect?: (client: MCPClient<any>) => Promise<void> | void;
69
- }
70
-
71
- /**
72
- * Helper type to extract plugin IDs from an array of plugins
73
- */
74
- export type ExtractPluginIds<T extends readonly MCPPlugin[]> = T[number]["id"];
75
-
76
- /**
77
- * Helper type to extract tools from an array of plugins
78
- */
79
- export type ExtractPluginTools<T extends readonly MCPPlugin[]> = T[number]["tools"][number];
80
-
81
- /**
82
- * Type guard to check if a plugin has OAuth configuration
83
- */
84
- export function hasOAuthConfig(
85
- plugin: MCPPlugin
86
- ): plugin is MCPPlugin & { oauth: OAuthConfig } {
87
- return plugin.oauth !== undefined;
88
- }
89
-
@@ -1,88 +0,0 @@
1
- /**
2
- * JSON-RPC 2.0 Implementation
3
- */
4
-
5
- import type {
6
- JSONRPCRequest,
7
- JSONRPCResponse,
8
- JSONRPCNotification,
9
- } from "./messages.js";
10
-
11
- /**
12
- * Generate a unique request ID
13
- */
14
- let requestIdCounter = 0;
15
- export function generateRequestId(): number {
16
- return ++requestIdCounter;
17
- }
18
-
19
- /**
20
- * Create a JSON-RPC request
21
- */
22
- export function createRequest(
23
- method: string,
24
- params?: unknown
25
- ): JSONRPCRequest {
26
- return {
27
- jsonrpc: "2.0",
28
- id: generateRequestId(),
29
- method,
30
- params: params as Record<string, unknown> | unknown[] | undefined,
31
- };
32
- }
33
-
34
- /**
35
- * Create a JSON-RPC notification (no response expected)
36
- */
37
- export function createNotification(
38
- method: string,
39
- params?: unknown
40
- ): JSONRPCNotification {
41
- return {
42
- jsonrpc: "2.0",
43
- method,
44
- params: params as Record<string, unknown> | unknown[] | undefined,
45
- };
46
- }
47
-
48
- /**
49
- * Check if a response is an error
50
- */
51
- export function isErrorResponse(
52
- response: JSONRPCResponse
53
- ): response is JSONRPCResponse & { error: NonNullable<unknown> } {
54
- return "error" in response;
55
- }
56
-
57
- /**
58
- * Extract result from a successful response
59
- */
60
- export function getResult<T>(response: JSONRPCResponse<T>): T {
61
- if (isErrorResponse(response)) {
62
- throw new Error(
63
- `JSON-RPC Error ${response.error.code}: ${response.error.message}`
64
- );
65
- }
66
- return response.result;
67
- }
68
-
69
- /**
70
- * Parse a JSON-RPC message from string
71
- */
72
- export function parseMessage(message: string): JSONRPCResponse | JSONRPCNotification {
73
- try {
74
- return JSON.parse(message);
75
- } catch (error) {
76
- throw new Error(`Failed to parse JSON-RPC message: ${error}`);
77
- }
78
- }
79
-
80
- /**
81
- * Serialize a JSON-RPC message to string
82
- */
83
- export function serializeMessage(
84
- message: JSONRPCRequest | JSONRPCNotification
85
- ): string {
86
- return JSON.stringify(message);
87
- }
88
-
@@ -1,145 +0,0 @@
1
- /**
2
- * MCP Protocol Message Types
3
- * Based on JSON-RPC 2.0 specification with MCP extensions
4
- */
5
-
6
- /**
7
- * JSON-RPC 2.0 Request
8
- */
9
- export interface JSONRPCRequest {
10
- jsonrpc: "2.0";
11
- id: string | number;
12
- method: string;
13
- params?: Record<string, unknown> | unknown[];
14
- }
15
-
16
- /**
17
- * JSON-RPC 2.0 Response (Success)
18
- */
19
- export interface JSONRPCSuccessResponse<T = unknown> {
20
- jsonrpc: "2.0";
21
- id: string | number;
22
- result: T;
23
- }
24
-
25
- /**
26
- * JSON-RPC 2.0 Response (Error)
27
- */
28
- export interface JSONRPCErrorResponse {
29
- jsonrpc: "2.0";
30
- id: string | number;
31
- error: {
32
- code: number;
33
- message: string;
34
- data?: unknown;
35
- };
36
- }
37
-
38
- /**
39
- * JSON-RPC 2.0 Notification (no response expected)
40
- */
41
- export interface JSONRPCNotification {
42
- jsonrpc: "2.0";
43
- method: string;
44
- params?: Record<string, unknown> | unknown[];
45
- }
46
-
47
- /**
48
- * Union type for any JSON-RPC response
49
- */
50
- export type JSONRPCResponse<T = unknown> =
51
- | JSONRPCSuccessResponse<T>
52
- | JSONRPCErrorResponse;
53
-
54
- /**
55
- * MCP Tool Definition
56
- */
57
- export interface MCPTool {
58
- name: string;
59
- description?: string;
60
- inputSchema: {
61
- type: "object";
62
- properties?: Record<string, unknown>;
63
- required?: string[];
64
- [key: string]: unknown;
65
- };
66
- }
67
-
68
- /**
69
- * MCP Tools List Response
70
- */
71
- export interface MCPToolsListResponse {
72
- tools: MCPTool[];
73
- }
74
-
75
- /**
76
- * MCP Tool Call Request Parameters
77
- */
78
- export interface MCPToolCallParams {
79
- name: string;
80
- arguments?: Record<string, unknown>;
81
- }
82
-
83
- /**
84
- * MCP Tool Call Response
85
- */
86
- export interface MCPToolCallResponse {
87
- content: Array<{
88
- type: "text" | "image" | "resource";
89
- text?: string;
90
- data?: string;
91
- mimeType?: string;
92
- [key: string]: unknown;
93
- }>;
94
- isError?: boolean;
95
- structuredContent?: Record<string, unknown>;
96
- _meta?: Record<string, unknown>;
97
- }
98
-
99
- /**
100
- * MCP Protocol Methods
101
- */
102
- export enum MCPMethod {
103
- INITIALIZE = "initialize",
104
- TOOLS_LIST = "tools/list",
105
- TOOLS_CALL = "tools/call",
106
- RESOURCES_LIST = "resources/list",
107
- RESOURCES_READ = "resources/read",
108
- PROMPTS_LIST = "prompts/list",
109
- PROMPTS_GET = "prompts/get",
110
- }
111
-
112
- /**
113
- * Initialize request parameters
114
- */
115
- export interface MCPInitializeParams {
116
- protocolVersion: string;
117
- capabilities: {
118
- tools?: Record<string, unknown>;
119
- resources?: Record<string, unknown>;
120
- prompts?: Record<string, unknown>;
121
- [key: string]: unknown;
122
- };
123
- clientInfo: {
124
- name: string;
125
- version: string;
126
- };
127
- }
128
-
129
- /**
130
- * Initialize response
131
- */
132
- export interface MCPInitializeResponse {
133
- protocolVersion: string;
134
- capabilities: {
135
- tools?: Record<string, unknown>;
136
- resources?: Record<string, unknown>;
137
- prompts?: Record<string, unknown>;
138
- [key: string]: unknown;
139
- };
140
- serverInfo: {
141
- name: string;
142
- version: string;
143
- };
144
- }
145
-
package/src/server.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * Server-Side SDK
3
- * Use this for server-side configuration with OAuth secrets
4
- */
5
-
6
- import { MCPClient } from './client.js';
7
- import type { MCPClientConfig } from './config/types.js';
8
- import type { MCPPlugin } from './plugins/types.js';
9
-
10
- /**
11
- * Create MCP Server instance with OAuth secrets
12
- *
13
- * This is for SERVER-SIDE ONLY - includes OAuth secrets from environment variables.
14
- * Use this in your server configuration file (e.g., lib/integrate-server.ts)
15
- *
16
- * @example
17
- * ```typescript
18
- * // lib/integrate-server.ts (server-side only!)
19
- * import { createMCPServer, githubPlugin, gmailPlugin } from 'integrate-sdk/server';
20
- *
21
- * export const { client: serverClient, POST, GET } = createMCPServer({
22
- * plugins: [
23
- * githubPlugin({
24
- * clientId: process.env.GITHUB_CLIENT_ID!,
25
- * clientSecret: process.env.GITHUB_CLIENT_SECRET!,
26
- * scopes: ['repo', 'user'],
27
- * }),
28
- * gmailPlugin({
29
- * clientId: process.env.GMAIL_CLIENT_ID!,
30
- * clientSecret: process.env.GMAIL_CLIENT_SECRET!,
31
- * scopes: ['gmail.readonly'],
32
- * }),
33
- * ],
34
- * });
35
- * ```
36
- *
37
- * Then in your route file:
38
- * ```typescript
39
- * // app/api/integrate/oauth/[action]/route.ts
40
- * export { POST, GET } from '@/lib/integrate-server';
41
- * ```
42
- */
43
- export function createMCPServer<TPlugins extends readonly MCPPlugin[]>(
44
- config: MCPClientConfig<TPlugins>
45
- ) {
46
- // Validate we're on the server
47
- if (typeof window !== 'undefined') {
48
- throw new Error(
49
- 'createMCPServer() should only be called on the server-side. ' +
50
- 'Use createMCPClient() for client-side code.'
51
- );
52
- }
53
-
54
- // Extract OAuth providers from plugins
55
- const providers: Record<string, {
56
- clientId: string;
57
- clientSecret: string;
58
- redirectUri?: string;
59
- }> = {};
60
-
61
- for (const plugin of config.plugins) {
62
- if (plugin.oauth) {
63
- const { clientId, clientSecret, redirectUri } = plugin.oauth;
64
-
65
- if (!clientId || !clientSecret) {
66
- console.warn(
67
- `Warning: Plugin "${plugin.id}" is missing OAuth credentials. ` +
68
- `Provide clientId and clientSecret in the plugin configuration.`
69
- );
70
- continue;
71
- }
72
-
73
- providers[plugin.id] = {
74
- clientId,
75
- clientSecret,
76
- redirectUri,
77
- };
78
- }
79
- }
80
-
81
- // Create the client instance
82
- const client = new MCPClient(config);
83
-
84
- // Create route handlers with the provider configuration
85
- const { POST, GET } = createOAuthRouteHandlers({ providers });
86
-
87
- return {
88
- /** Server-side MCP client instance */
89
- client,
90
-
91
- /** OAuth POST handler - export this from your route file */
92
- POST,
93
-
94
- /** OAuth GET handler - export this from your route file */
95
- GET,
96
- };
97
- }
98
-
99
- /**
100
- * Create OAuth route handlers for Next.js App Router
101
- * Internal function used by createMCPServer
102
- */
103
- function createOAuthRouteHandlers(config: { providers: Record<string, any> }) {
104
- const { createNextOAuthHandler } = require('./adapters/nextjs.js');
105
- const handler = createNextOAuthHandler(config);
106
- return handler.createRoutes();
107
- }
108
-
109
- // Re-export plugin types for convenience
110
- export type { MCPPlugin } from './plugins/types.js';
111
- export type { MCPClientConfig } from './config/types.js';
112
-
113
- // Re-export plugins
114
- export { githubPlugin } from './plugins/github.js';
115
- export { gmailPlugin } from './plugins/gmail.js';
116
- export { genericOAuthPlugin, createSimplePlugin } from './plugins/generic.js';
117
-