@uidbai/mcp-server 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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/dist/cli.d.ts +13 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +117 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/core/api-client.d.ts +45 -0
  8. package/dist/core/api-client.d.ts.map +1 -0
  9. package/dist/core/api-client.js +98 -0
  10. package/dist/core/api-client.js.map +1 -0
  11. package/dist/core/auth.d.ts +42 -0
  12. package/dist/core/auth.d.ts.map +1 -0
  13. package/dist/core/auth.js +198 -0
  14. package/dist/core/auth.js.map +1 -0
  15. package/dist/core/errors.d.ts +32 -0
  16. package/dist/core/errors.d.ts.map +1 -0
  17. package/dist/core/errors.js +72 -0
  18. package/dist/core/errors.js.map +1 -0
  19. package/dist/core/index.d.ts +10 -0
  20. package/dist/core/index.d.ts.map +1 -0
  21. package/dist/core/index.js +10 -0
  22. package/dist/core/index.js.map +1 -0
  23. package/dist/core/types.d.ts +124 -0
  24. package/dist/core/types.d.ts.map +1 -0
  25. package/dist/core/types.js +52 -0
  26. package/dist/core/types.js.map +1 -0
  27. package/dist/index.d.ts +15 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +20 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/prompts/component-guidance.d.ts +16 -0
  32. package/dist/prompts/component-guidance.d.ts.map +1 -0
  33. package/dist/prompts/component-guidance.js +98 -0
  34. package/dist/prompts/component-guidance.js.map +1 -0
  35. package/dist/prompts/index.d.ts +6 -0
  36. package/dist/prompts/index.d.ts.map +1 -0
  37. package/dist/prompts/index.js +6 -0
  38. package/dist/prompts/index.js.map +1 -0
  39. package/dist/prompts/registry.d.ts +37 -0
  40. package/dist/prompts/registry.d.ts.map +1 -0
  41. package/dist/prompts/registry.js +40 -0
  42. package/dist/prompts/registry.js.map +1 -0
  43. package/dist/resources/index.d.ts +6 -0
  44. package/dist/resources/index.d.ts.map +1 -0
  45. package/dist/resources/index.js +6 -0
  46. package/dist/resources/index.js.map +1 -0
  47. package/dist/resources/project-config.d.ts +33 -0
  48. package/dist/resources/project-config.d.ts.map +1 -0
  49. package/dist/resources/project-config.js +146 -0
  50. package/dist/resources/project-config.js.map +1 -0
  51. package/dist/resources/registry.d.ts +20 -0
  52. package/dist/resources/registry.d.ts.map +1 -0
  53. package/dist/resources/registry.js +45 -0
  54. package/dist/resources/registry.js.map +1 -0
  55. package/dist/server.d.ts +9 -0
  56. package/dist/server.d.ts.map +1 -0
  57. package/dist/server.js +111 -0
  58. package/dist/server.js.map +1 -0
  59. package/dist/tools/ask-intent.d.ts +35 -0
  60. package/dist/tools/ask-intent.d.ts.map +1 -0
  61. package/dist/tools/ask-intent.js +50 -0
  62. package/dist/tools/ask-intent.js.map +1 -0
  63. package/dist/tools/ask-question.d.ts +40 -0
  64. package/dist/tools/ask-question.d.ts.map +1 -0
  65. package/dist/tools/ask-question.js +58 -0
  66. package/dist/tools/ask-question.js.map +1 -0
  67. package/dist/tools/detect-pattern.d.ts +48 -0
  68. package/dist/tools/detect-pattern.d.ts.map +1 -0
  69. package/dist/tools/detect-pattern.js +64 -0
  70. package/dist/tools/detect-pattern.js.map +1 -0
  71. package/dist/tools/finalize.d.ts +35 -0
  72. package/dist/tools/finalize.d.ts.map +1 -0
  73. package/dist/tools/finalize.js +51 -0
  74. package/dist/tools/finalize.js.map +1 -0
  75. package/dist/tools/get-config.d.ts +28 -0
  76. package/dist/tools/get-config.d.ts.map +1 -0
  77. package/dist/tools/get-config.js +48 -0
  78. package/dist/tools/get-config.js.map +1 -0
  79. package/dist/tools/index.d.ts +18 -0
  80. package/dist/tools/index.d.ts.map +1 -0
  81. package/dist/tools/index.js +19 -0
  82. package/dist/tools/index.js.map +1 -0
  83. package/dist/tools/list-components.d.ts +28 -0
  84. package/dist/tools/list-components.d.ts.map +1 -0
  85. package/dist/tools/list-components.js +44 -0
  86. package/dist/tools/list-components.js.map +1 -0
  87. package/dist/tools/list-patterns.d.ts +28 -0
  88. package/dist/tools/list-patterns.d.ts.map +1 -0
  89. package/dist/tools/list-patterns.js +44 -0
  90. package/dist/tools/list-patterns.js.map +1 -0
  91. package/dist/tools/login.d.ts +35 -0
  92. package/dist/tools/login.d.ts.map +1 -0
  93. package/dist/tools/login.js +100 -0
  94. package/dist/tools/login.js.map +1 -0
  95. package/dist/tools/registry.d.ts +50 -0
  96. package/dist/tools/registry.d.ts.map +1 -0
  97. package/dist/tools/registry.js +75 -0
  98. package/dist/tools/registry.js.map +1 -0
  99. package/dist/tools/status.d.ts +28 -0
  100. package/dist/tools/status.d.ts.map +1 -0
  101. package/dist/tools/status.js +88 -0
  102. package/dist/tools/status.js.map +1 -0
  103. package/dist/tools/submit-pattern.d.ts +67 -0
  104. package/dist/tools/submit-pattern.d.ts.map +1 -0
  105. package/dist/tools/submit-pattern.js +94 -0
  106. package/dist/tools/submit-pattern.js.map +1 -0
  107. package/dist/tools/update-config.d.ts +48 -0
  108. package/dist/tools/update-config.d.ts.map +1 -0
  109. package/dist/tools/update-config.js +94 -0
  110. package/dist/tools/update-config.js.map +1 -0
  111. package/package.json +68 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 UIDB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @uidbai/mcp-server
2
+
3
+ Model Context Protocol (MCP) server for the UIDB Design System. Enables AI coding assistants (Cursor, Claude, etc.) to build consistent, accessible UI components.
4
+
5
+ ## Installation
6
+
7
+ No installation required! Use directly with `npx`:
8
+
9
+ ```bash
10
+ npx @uidbai/mcp-server
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### 1. Add to Cursor
16
+
17
+ Create `.cursor/mcp.json` in your project:
18
+
19
+ ```json
20
+ {
21
+ "mcpServers": {
22
+ "uidb": {
23
+ "command": "npx",
24
+ "args": ["-y", "@uidb/mcp-server"]
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### 2. Authenticate
31
+
32
+ Get your token from [portal.uidb.ai](https://portal.uidb.ai) → Your Project → Connect, then run:
33
+
34
+ ```bash
35
+ npx @uidbai/mcp-server login --token=YOUR_TOKEN
36
+ ```
37
+
38
+ ### 3. Restart Cursor
39
+
40
+ Restart your AI coding tool to load the UIDB MCP server.
41
+
42
+ ## Available Tools
43
+
44
+ | Tool | Description |
45
+ | ---------------------- | ----------------------------- |
46
+ | `uidb_ask_intent` | Start component guidance flow |
47
+ | `uidb_ask_question` | Continue guidance Q&A |
48
+ | `uidb_finalize` | Get final component code |
49
+ | `uidb_list_components` | List available components |
50
+ | `uidb_detect_pattern` | Check if code is a pattern |
51
+ | `uidb_submit_pattern` | Submit a new pattern |
52
+ | `uidb_list_patterns` | List project patterns |
53
+ | `uidb_get_config` | Get theme configuration |
54
+ | `uidb_update_config` | Update theme settings |
55
+ | `uidb_login` | Authenticate with UIDB |
56
+ | `uidb_status` | Check connection status |
57
+
58
+ ## CLI Commands
59
+
60
+ ```bash
61
+ # Start MCP server (default)
62
+ npx @uidbai/mcp-server
63
+
64
+ # Authenticate
65
+ npx @uidbai/mcp-server login --token=YOUR_TOKEN
66
+
67
+ # Check status
68
+ npx @uidbai/mcp-server status
69
+
70
+ # Logout
71
+ npx @uidbai/mcp-server logout
72
+ ```
73
+
74
+ ## Configuration for Other Tools
75
+
76
+ ### Claude Desktop
77
+
78
+ Add to `claude_desktop_config.json`:
79
+
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "uidb": {
84
+ "command": "npx",
85
+ "args": ["-y", "@uidb/mcp-server"]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Windsurf / Other MCP Tools
92
+
93
+ Follow your tool's MCP configuration guide, using:
94
+
95
+ - Command: `npx`
96
+ - Args: `["-y", "@uidb/mcp-server"]`
97
+
98
+ ## How It Works
99
+
100
+ 1. **Component Guidance**: When you need a UI component, ask your AI assistant. It will use `uidb_ask_intent` to start a guidance flow, walking you through selecting the right component, variant, size, and colors.
101
+
102
+ 2. **Pattern Detection**: After building multi-component UIs, the assistant can use `uidb_detect_pattern` to check if it's a reusable pattern worth documenting.
103
+
104
+ 3. **Theme Consistency**: The assistant uses `uidb_get_config` to ensure all components match your project's theme (accent color, gray scale, border radius).
105
+
106
+ ## Resources
107
+
108
+ The MCP server exposes these resources:
109
+
110
+ - `uidb://project/{slug}/config` - Design system configuration
111
+ - `uidb://project/{slug}/components` - Available components
112
+ - `uidb://project/{slug}/patterns` - Documented patterns
113
+
114
+ ## Prompts
115
+
116
+ Built-in prompts for common workflows:
117
+
118
+ - `uidb_component_guidance` - System prompt for component selection
119
+ - `uidb_pattern_detection` - System prompt for pattern detection
120
+
121
+ ## Credential Storage
122
+
123
+ Credentials are stored securely in `~/.uidb/credentials.json` with restricted file permissions. No credentials are stored in your project files.
124
+
125
+ ## Support
126
+
127
+ - **Portal**: [portal.uidb.ai](https://portal.uidb.ai)
128
+ - **Documentation**: [docs.uidb.ai](https://docs.uidb.ai)
129
+ - **Issues**: [github.com/uidb/mcp-server/issues](https://github.com/uidb/mcp-server/issues)
130
+
131
+ ## License
132
+
133
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UIDB MCP Server CLI
4
+ *
5
+ * Command-line interface for authentication and management.
6
+ *
7
+ * Usage:
8
+ * npx @uidbai/mcp-server login --token=YOUR_TOKEN
9
+ * npx @uidbai/mcp-server status
10
+ * npx @uidbai/mcp-server logout
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
package/dist/cli.js ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UIDB MCP Server CLI
4
+ *
5
+ * Command-line interface for authentication and management.
6
+ *
7
+ * Usage:
8
+ * npx @uidbai/mcp-server login --token=YOUR_TOKEN
9
+ * npx @uidbai/mcp-server status
10
+ * npx @uidbai/mcp-server logout
11
+ */
12
+ import { Command } from "commander";
13
+ import { exchangeToken, getAuthStatus, deleteCredentials, isAuthenticated, } from "./core/auth.js";
14
+ const program = new Command();
15
+ program
16
+ .name("uidb-mcp")
17
+ .description("UIDB Design System MCP Server CLI")
18
+ .version("0.1.0");
19
+ // ============================================================================
20
+ // Login Command
21
+ // ============================================================================
22
+ program
23
+ .command("login")
24
+ .description("Authenticate with UIDB using a one-time token from the portal")
25
+ .option("-t, --token <token>", "One-time authentication token from UIDB portal")
26
+ .action(async (options) => {
27
+ if (!options.token) {
28
+ // Check if already authenticated
29
+ const authenticated = await isAuthenticated();
30
+ if (authenticated) {
31
+ const status = await getAuthStatus();
32
+ console.log("\n✓ Already authenticated");
33
+ console.log(` Project: ${status.projectSlug}`);
34
+ console.log(` User: ${status.userEmail}`);
35
+ console.log(` Expires: ${status.expiresAt}`);
36
+ console.log("\nTo switch projects, get a new token from portal.uidb.ai");
37
+ return;
38
+ }
39
+ console.log("\n⚠ No token provided\n");
40
+ console.log("To authenticate with UIDB:");
41
+ console.log(" 1. Go to portal.uidb.ai");
42
+ console.log(" 2. Select your project → Connect");
43
+ console.log(" 3. Copy the login command with token");
44
+ console.log(" 4. Run: npx @uidbai/mcp-server login --token=YOUR_TOKEN\n");
45
+ process.exit(1);
46
+ }
47
+ try {
48
+ console.log("\n⏳ Authenticating...");
49
+ const credentials = await exchangeToken(options.token);
50
+ console.log("\n✓ Successfully authenticated!");
51
+ console.log(` Project: ${credentials.projectSlug}`);
52
+ console.log(` User: ${credentials.userEmail}`);
53
+ console.log(` Expires: ${credentials.expiresAt}`);
54
+ console.log("\nUIDB MCP server is now ready to use.");
55
+ console.log("Restart your AI coding tool to load the new credentials.\n");
56
+ }
57
+ catch (error) {
58
+ console.error("\n✗ Authentication failed");
59
+ console.error(` ${error instanceof Error ? error.message : "Unknown error"}`);
60
+ console.error("\nMake sure your token is valid and hasn't expired.");
61
+ console.error("Get a new token from portal.uidb.ai → Your Project → Connect\n");
62
+ process.exit(1);
63
+ }
64
+ });
65
+ // ============================================================================
66
+ // Status Command
67
+ // ============================================================================
68
+ program
69
+ .command("status")
70
+ .description("Check UIDB connection status")
71
+ .action(async () => {
72
+ const status = await getAuthStatus();
73
+ if (!status.authenticated) {
74
+ console.log("\n✗ Not connected to UIDB");
75
+ console.log("\nTo connect:");
76
+ console.log(" 1. Go to portal.uidb.ai");
77
+ console.log(" 2. Select your project → Connect");
78
+ console.log(" 3. Run the login command\n");
79
+ process.exit(1);
80
+ }
81
+ console.log("\n✓ Connected to UIDB");
82
+ console.log(` Project: ${status.projectSlug}`);
83
+ console.log(` User: ${status.userEmail}`);
84
+ console.log(` Expires: ${status.expiresAt}\n`);
85
+ });
86
+ // ============================================================================
87
+ // Logout Command
88
+ // ============================================================================
89
+ program
90
+ .command("logout")
91
+ .description("Remove UIDB credentials")
92
+ .action(async () => {
93
+ try {
94
+ await deleteCredentials();
95
+ console.log("\n✓ Logged out successfully");
96
+ console.log(" Credentials have been removed.\n");
97
+ }
98
+ catch (error) {
99
+ console.error("\n✗ Logout failed");
100
+ console.error(` ${error instanceof Error ? error.message : "Unknown error"}\n`);
101
+ process.exit(1);
102
+ }
103
+ });
104
+ // ============================================================================
105
+ // Default: Run MCP Server
106
+ // ============================================================================
107
+ program
108
+ .command("serve", { isDefault: true })
109
+ .description("Start the MCP server (default command)")
110
+ .action(async () => {
111
+ // Import and run server
112
+ const { runServer } = await import("./server.js");
113
+ await runServer();
114
+ });
115
+ // Parse and execute
116
+ program.parse();
117
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,mCAAmC,CAAC;KAChD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,+DAA+D,CAAC;KAC5E,MAAM,CACL,qBAAqB,EACrB,gDAAgD,CACjD;KACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACnB,iCAAiC;QACjC,MAAM,aAAa,GAAG,M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,EAAE,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,cAAc,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC;AAEL,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,yBAAyB,CAAC;KACtC,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,iBAAiB,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACnC,OAAO,CAAC,KAAK,CACX,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,IAAI,CAClE,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,OAAO;KACJ,OAAO,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KACrC,WAAW,CAAC,wCAAwC,CAAC;KACrD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,wBAAwB;IACxB,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,SAAS,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC;AAEL,oBAAoB;AACpB,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * UIDB MCP Server - API Client
3
+ *
4
+ * HTTP client for communicating with the UIDB REST API.
5
+ * Handles authentication headers and error responses.
6
+ */
7
+ import { UIDBCredentials } from "./types.js";
8
+ export interface RequestOptions {
9
+ method?: "GET" | "POST" | "PUT" | "DELETE";
10
+ body?: unknown;
11
+ headers?: Record<string, string>;
12
+ }
13
+ /**
14
+ * Make an authenticated request to the UIDB API
15
+ */
16
+ export declare function apiRequest<T>(endpoint: string, options?: RequestOptions): Promise<T>;
17
+ /**
18
+ * Make a request with explicit credentials
19
+ */
20
+ export declare function apiRequestWithCredentials<T>(endpoint: string, credentials: UIDBCredentials, options?: RequestOptions): Promise<T>;
21
+ /**
22
+ * GET request
23
+ */
24
+ export declare function get<T>(endpoint: string): Promise<T>;
25
+ /**
26
+ * POST request
27
+ */
28
+ export declare function post<T>(endpoint: string, body: unknown): Promise<T>;
29
+ /**
30
+ * PUT request
31
+ */
32
+ export declare function put<T>(endpoint: string, body: unknown): Promise<T>;
33
+ /**
34
+ * DELETE request
35
+ */
36
+ export declare function del<T>(endpoint: string): Promise<T>;
37
+ export declare const apiClient: {
38
+ get: typeof get;
39
+ post: typeof post;
40
+ put: typeof put;
41
+ delete: typeof del;
42
+ request: typeof apiRequest;
43
+ };
44
+ export default apiClient;
45
+ //# sourceMappingURL=api-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/core/api-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAgB,eAAe,EAAE,MAAM,YAAY,CAAC;AAQ3D,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC3C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAIZ;AAED;;GAEG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,eAAe,EAC5B,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAqDZ;AAMD;;GAEG;AACH,wBAAsB,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAEzD;AAED;;GAEG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAEzE;AAED;;GAEG;AACH,wBAAsB,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAExE;AAED;;GAEG;AACH,wBAAsB,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAEzD;AAMD,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * UIDB MCP Server - API Client
3
+ *
4
+ * HTTP client for communicating with the UIDB REST API.
5
+ * Handles authentication headers and error responses.
6
+ */
7
+ import { UIDB_API_URL } from "./types.js";
8
+ import { requireCredentials } from "./auth.js";
9
+ import { APIError, NetworkError, AuthenticationError } from "./errors.js";
10
+ /**
11
+ * Make an authenticated request to the UIDB API
12
+ */
13
+ export async function apiRequest(endpoint, options = {}) {
14
+ const credentials = await requireCredentials();
15
+ return apiRequestWithCredentials(endpoint, credentials, options);
16
+ }
17
+ /**
18
+ * Make a request with explicit credentials
19
+ */
20
+ export async function apiRequestWithCredentials(endpoint, credentials, options = {}) {
21
+ const { method = "GET", body, headers = {} } = options;
22
+ const url = `${UIDB_API_URL}${endpoint}`;
23
+ try {
24
+ const fetchOptions = {
25
+ method,
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ "X-UIDB-API-Key": credentials.accessToken,
29
+ "X-UIDB-Project-ID": credentials.projectId,
30
+ ...headers,
31
+ },
32
+ };
33
+ if (body) {
34
+ fetchOptions.body = JSON.stringify(body);
35
+ }
36
+ const response = await fetch(url, fetchOptions);
37
+ // Handle authentication errors
38
+ if (response.status === 401) {
39
+ throw new AuthenticationError("Session expired. Run 'npx @uidbai/mcp-server login' to reconnect.");
40
+ }
41
+ // Handle other errors
42
+ if (!response.ok) {
43
+ const errorData = await response.json().catch(() => ({}));
44
+ throw new APIError(errorData.message ||
45
+ errorData.error ||
46
+ `API request failed: ${response.status}`, response.status);
47
+ }
48
+ // Parse response
49
+ const data = await response.json();
50
+ return data;
51
+ }
52
+ catch (error) {
53
+ if (error instanceof APIError || error instanceof AuthenticationError) {
54
+ throw error;
55
+ }
56
+ // Network or other errors
57
+ throw new NetworkError(`Failed to reach UIDB API: ${error instanceof Error ? error.message : "Unknown error"}`);
58
+ }
59
+ }
60
+ // ============================================================================
61
+ // Convenience Methods
62
+ // ============================================================================
63
+ /**
64
+ * GET request
65
+ */
66
+ export async function get(endpoint) {
67
+ return apiRequest(endpoint, { method: "GET" });
68
+ }
69
+ /**
70
+ * POST request
71
+ */
72
+ export async function post(endpoint, body) {
73
+ return apiRequest(endpoint, { method: "POST", body });
74
+ }
75
+ /**
76
+ * PUT request
77
+ */
78
+ export async function put(endpoint, body) {
79
+ return apiRequest(endpoint, { method: "PUT", body });
80
+ }
81
+ /**
82
+ * DELETE request
83
+ */
84
+ export async function del(endpoint) {
85
+ return apiRequest(endpoint, { method: "DELETE" });
86
+ }
87
+ // ============================================================================
88
+ // API Client Instance
89
+ // ============================================================================
90
+ export const apiClient = {
91
+ get,
92
+ post,
93
+ put,
94
+ delete: del,
95
+ request: apiRequest,
96
+ };
97
+ export default apiClient;
98
+ //# sourceMappingURL=api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.js","sourceRoot":"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1D,OAAO,UAAU,CAAI,QAAQ,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAI,QAAgB;IAC3C,OAAO,UAAU,CAAI,QAAQ,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,GAAG;IACH,IAAI;IACJ,GAAG;IACH,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * UIDB MCP Server - Authentication
3
+ *
4
+ * Handles OAuth authentication and credential storage.
5
+ * Credentials are stored in ~/.uidb/credentials.json
6
+ */
7
+ import { UIDBCredentials } from "./types.js";
8
+ /**
9
+ * Load credentials from disk
10
+ */
11
+ export declare function loadCredentials(): Promise<UIDBCredentials | null>;
12
+ /**
13
+ * Save credentials to disk
14
+ */
15
+ export declare function saveCredentials(credentials: UIDBCredentials): Promise<void>;
16
+ /**
17
+ * Delete credentials from disk
18
+ */
19
+ export declare function deleteCredentials(): Promise<void>;
20
+ /**
21
+ * Exchange one-time token for access credentials
22
+ * Called by CLI: npx @uidbai/mcp-server login --token=xxx
23
+ */
24
+ export declare function exchangeToken(oneTimeToken: string): Promise<UIDBCredentials>;
25
+ /**
26
+ * Get current credentials or throw if not authenticated
27
+ */
28
+ export declare function requireCredentials(): Promise<UIDBCredentials>;
29
+ /**
30
+ * Check if user is authenticated
31
+ */
32
+ export declare function isAuthenticated(): Promise<boolean>;
33
+ /**
34
+ * Get authentication status info
35
+ */
36
+ export declare function getAuthStatus(): Promise<{
37
+ authenticated: boolean;
38
+ projectSlug?: string;
39
+ userEmail?: string;
40
+ expiresAt?: string;
41
+ }>;
42
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/core/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,eAAe,EAGhB,MAAM,YAAY,CAAC;AAoBpB;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA4BvE;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,eAAe,GAC3B,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAOvD;AAMD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC,CAuC1B;AAmDD;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC,CAQnE;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAOxD;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC;IAC7C,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAiBD"}