@bluehive/sdk-mcp 0.1.0-alpha.2

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 (139) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +188 -0
  3. package/compat.d.mts +56 -0
  4. package/compat.d.mts.map +1 -0
  5. package/compat.d.ts +56 -0
  6. package/compat.d.ts.map +1 -0
  7. package/compat.js +382 -0
  8. package/compat.js.map +1 -0
  9. package/compat.mjs +373 -0
  10. package/compat.mjs.map +1 -0
  11. package/dynamic-tools.d.mts +12 -0
  12. package/dynamic-tools.d.mts.map +1 -0
  13. package/dynamic-tools.d.ts +12 -0
  14. package/dynamic-tools.d.ts.map +1 -0
  15. package/dynamic-tools.js +135 -0
  16. package/dynamic-tools.js.map +1 -0
  17. package/dynamic-tools.mjs +132 -0
  18. package/dynamic-tools.mjs.map +1 -0
  19. package/index.d.mts +3 -0
  20. package/index.d.mts.map +1 -0
  21. package/index.d.ts +3 -0
  22. package/index.d.ts.map +1 -0
  23. package/index.js +86 -0
  24. package/index.js.map +1 -0
  25. package/index.mjs +84 -0
  26. package/index.mjs.map +1 -0
  27. package/options.d.mts +14 -0
  28. package/options.d.mts.map +1 -0
  29. package/options.d.ts +14 -0
  30. package/options.d.ts.map +1 -0
  31. package/options.js +296 -0
  32. package/options.js.map +1 -0
  33. package/options.mjs +290 -0
  34. package/options.mjs.map +1 -0
  35. package/package.json +121 -0
  36. package/server.d.mts +47 -0
  37. package/server.d.mts.map +1 -0
  38. package/server.d.ts +47 -0
  39. package/server.d.ts.map +1 -0
  40. package/server.js +114 -0
  41. package/server.js.map +1 -0
  42. package/server.mjs +101 -0
  43. package/server.mjs.map +1 -0
  44. package/src/compat.ts +478 -0
  45. package/src/dynamic-tools.ts +153 -0
  46. package/src/index.ts +104 -0
  47. package/src/options.ts +319 -0
  48. package/src/server.ts +145 -0
  49. package/src/tools/database/check-health-database.ts +31 -0
  50. package/src/tools/fax/list-providers-fax.ts +31 -0
  51. package/src/tools/fax/retrieve-status-fax.ts +36 -0
  52. package/src/tools/fax/send-fax.ts +76 -0
  53. package/src/tools/health/check-health.ts +31 -0
  54. package/src/tools/index.ts +83 -0
  55. package/src/tools/providers/lookup-providers.ts +49 -0
  56. package/src/tools/types.ts +103 -0
  57. package/src/tools/version/retrieve-version.ts +31 -0
  58. package/src/tools.ts +1 -0
  59. package/src/tsconfig.json +11 -0
  60. package/tools/database/check-health-database.d.mts +45 -0
  61. package/tools/database/check-health-database.d.mts.map +1 -0
  62. package/tools/database/check-health-database.d.ts +45 -0
  63. package/tools/database/check-health-database.d.ts.map +1 -0
  64. package/tools/database/check-health-database.js +27 -0
  65. package/tools/database/check-health-database.js.map +1 -0
  66. package/tools/database/check-health-database.mjs +23 -0
  67. package/tools/database/check-health-database.mjs.map +1 -0
  68. package/tools/fax/list-providers-fax.d.mts +45 -0
  69. package/tools/fax/list-providers-fax.d.mts.map +1 -0
  70. package/tools/fax/list-providers-fax.d.ts +45 -0
  71. package/tools/fax/list-providers-fax.d.ts.map +1 -0
  72. package/tools/fax/list-providers-fax.js +27 -0
  73. package/tools/fax/list-providers-fax.js.map +1 -0
  74. package/tools/fax/list-providers-fax.mjs +23 -0
  75. package/tools/fax/list-providers-fax.mjs.map +1 -0
  76. package/tools/fax/retrieve-status-fax.d.mts +45 -0
  77. package/tools/fax/retrieve-status-fax.d.mts.map +1 -0
  78. package/tools/fax/retrieve-status-fax.d.ts +45 -0
  79. package/tools/fax/retrieve-status-fax.d.ts.map +1 -0
  80. package/tools/fax/retrieve-status-fax.js +32 -0
  81. package/tools/fax/retrieve-status-fax.js.map +1 -0
  82. package/tools/fax/retrieve-status-fax.mjs +28 -0
  83. package/tools/fax/retrieve-status-fax.mjs.map +1 -0
  84. package/tools/fax/send-fax.d.mts +45 -0
  85. package/tools/fax/send-fax.d.mts.map +1 -0
  86. package/tools/fax/send-fax.d.ts +45 -0
  87. package/tools/fax/send-fax.d.ts.map +1 -0
  88. package/tools/fax/send-fax.js +72 -0
  89. package/tools/fax/send-fax.js.map +1 -0
  90. package/tools/fax/send-fax.mjs +68 -0
  91. package/tools/fax/send-fax.mjs.map +1 -0
  92. package/tools/health/check-health.d.mts +45 -0
  93. package/tools/health/check-health.d.mts.map +1 -0
  94. package/tools/health/check-health.d.ts +45 -0
  95. package/tools/health/check-health.d.ts.map +1 -0
  96. package/tools/health/check-health.js +27 -0
  97. package/tools/health/check-health.js.map +1 -0
  98. package/tools/health/check-health.mjs +23 -0
  99. package/tools/health/check-health.mjs.map +1 -0
  100. package/tools/index.d.mts +10 -0
  101. package/tools/index.d.mts.map +1 -0
  102. package/tools/index.d.ts +10 -0
  103. package/tools/index.d.ts.map +1 -0
  104. package/tools/index.js +67 -0
  105. package/tools/index.js.map +1 -0
  106. package/tools/index.mjs +60 -0
  107. package/tools/index.mjs.map +1 -0
  108. package/tools/providers/lookup-providers.d.mts +45 -0
  109. package/tools/providers/lookup-providers.d.mts.map +1 -0
  110. package/tools/providers/lookup-providers.d.ts +45 -0
  111. package/tools/providers/lookup-providers.d.ts.map +1 -0
  112. package/tools/providers/lookup-providers.js +45 -0
  113. package/tools/providers/lookup-providers.js.map +1 -0
  114. package/tools/providers/lookup-providers.mjs +41 -0
  115. package/tools/providers/lookup-providers.mjs.map +1 -0
  116. package/tools/types.d.mts +51 -0
  117. package/tools/types.d.mts.map +1 -0
  118. package/tools/types.d.ts +51 -0
  119. package/tools/types.d.ts.map +1 -0
  120. package/tools/types.js +46 -0
  121. package/tools/types.js.map +1 -0
  122. package/tools/types.mjs +42 -0
  123. package/tools/types.mjs.map +1 -0
  124. package/tools/version/retrieve-version.d.mts +45 -0
  125. package/tools/version/retrieve-version.d.mts.map +1 -0
  126. package/tools/version/retrieve-version.d.ts +45 -0
  127. package/tools/version/retrieve-version.d.ts.map +1 -0
  128. package/tools/version/retrieve-version.js +27 -0
  129. package/tools/version/retrieve-version.js.map +1 -0
  130. package/tools/version/retrieve-version.mjs +23 -0
  131. package/tools/version/retrieve-version.mjs.map +1 -0
  132. package/tools.d.mts +2 -0
  133. package/tools.d.mts.map +1 -0
  134. package/tools.d.ts +2 -0
  135. package/tools.d.ts.map +1 -0
  136. package/tools.js +18 -0
  137. package/tools.js.map +1 -0
  138. package/tools.mjs +2 -0
  139. package/tools.mjs.map +1 -0
package/src/index.ts ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { init, selectTools, server } from './server';
5
+ import { Endpoint, endpoints } from './tools';
6
+ import { McpOptions, parseOptions } from './options';
7
+
8
+ async function main() {
9
+ const options = parseOptionsOrError();
10
+
11
+ if (options.list) {
12
+ listAllTools();
13
+ return;
14
+ }
15
+
16
+ const includedTools = selectToolsOrError(endpoints, options);
17
+
18
+ console.error(
19
+ `MCP Server starting with ${includedTools.length} tools:`,
20
+ includedTools.map((e) => e.tool.name),
21
+ );
22
+
23
+ init({ server, endpoints: includedTools });
24
+
25
+ const transport = new StdioServerTransport();
26
+ await server.connect(transport);
27
+ console.error('MCP Server running on stdio');
28
+ }
29
+
30
+ if (require.main === module) {
31
+ main().catch((error) => {
32
+ console.error('Fatal error in main():', error);
33
+ process.exit(1);
34
+ });
35
+ }
36
+
37
+ function parseOptionsOrError() {
38
+ try {
39
+ return parseOptions();
40
+ } catch (error) {
41
+ console.error('Error parsing options:', error);
42
+ process.exit(1);
43
+ }
44
+ }
45
+
46
+ function selectToolsOrError(endpoints: Endpoint[], options: McpOptions) {
47
+ try {
48
+ const includedTools = selectTools(endpoints, options);
49
+ if (includedTools.length === 0) {
50
+ console.error('No tools match the provided filters.');
51
+ process.exit(1);
52
+ }
53
+ return includedTools;
54
+ } catch (error) {
55
+ if (error instanceof Error) {
56
+ console.error('Error filtering tools:', error.message);
57
+ } else {
58
+ console.error('Error filtering tools:', error);
59
+ }
60
+ process.exit(1);
61
+ }
62
+ }
63
+
64
+ function listAllTools() {
65
+ if (endpoints.length === 0) {
66
+ console.log('No tools available.');
67
+ return;
68
+ }
69
+ console.log('Available tools:\n');
70
+
71
+ // Group endpoints by resource
72
+ const resourceGroups = new Map<string, typeof endpoints>();
73
+
74
+ for (const endpoint of endpoints) {
75
+ const resource = endpoint.metadata.resource;
76
+ if (!resourceGroups.has(resource)) {
77
+ resourceGroups.set(resource, []);
78
+ }
79
+ resourceGroups.get(resource)!.push(endpoint);
80
+ }
81
+
82
+ // Sort resources alphabetically
83
+ const sortedResources = Array.from(resourceGroups.keys()).sort();
84
+
85
+ // Display hierarchically by resource
86
+ for (const resource of sortedResources) {
87
+ console.log(`Resource: ${resource}`);
88
+
89
+ const resourceEndpoints = resourceGroups.get(resource)!;
90
+ // Sort endpoints by tool name
91
+ resourceEndpoints.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
92
+
93
+ for (const endpoint of resourceEndpoints) {
94
+ const {
95
+ tool,
96
+ metadata: { operation, tags },
97
+ } = endpoint;
98
+
99
+ console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
100
+ console.log(` Description: ${tool.description}`);
101
+ }
102
+ console.log('');
103
+ }
104
+ }
package/src/options.ts ADDED
@@ -0,0 +1,319 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { endpoints, Filter } from './tools';
4
+ import { ClientCapabilities, knownClients, ClientType } from './compat';
5
+
6
+ export type CLIOptions = McpOptions & {
7
+ list: boolean;
8
+ };
9
+
10
+ export type McpOptions = {
11
+ client: ClientType | undefined;
12
+ includeDynamicTools: boolean | undefined;
13
+ includeAllTools: boolean | undefined;
14
+ filters: Filter[];
15
+ capabilities?: Partial<ClientCapabilities>;
16
+ };
17
+
18
+ const CAPABILITY_CHOICES = [
19
+ 'top-level-unions',
20
+ 'valid-json',
21
+ 'refs',
22
+ 'unions',
23
+ 'formats',
24
+ 'tool-name-length',
25
+ ] as const;
26
+
27
+ type Capability = (typeof CAPABILITY_CHOICES)[number];
28
+
29
+ function parseCapabilityValue(cap: string): { name: Capability; value?: number } {
30
+ if (cap.startsWith('tool-name-length=')) {
31
+ const parts = cap.split('=');
32
+ if (parts.length === 2) {
33
+ const length = parseInt(parts[1]!, 10);
34
+ if (!isNaN(length)) {
35
+ return { name: 'tool-name-length', value: length };
36
+ }
37
+ throw new Error(`Invalid tool-name-length value: ${parts[1]}. Expected a number.`);
38
+ }
39
+ throw new Error(`Invalid format for tool-name-length. Expected tool-name-length=N.`);
40
+ }
41
+ if (!CAPABILITY_CHOICES.includes(cap as Capability)) {
42
+ throw new Error(`Unknown capability: ${cap}. Valid capabilities are: ${CAPABILITY_CHOICES.join(', ')}`);
43
+ }
44
+ return { name: cap as Capability };
45
+ }
46
+
47
+ export function parseOptions(): CLIOptions {
48
+ const opts = yargs(hideBin(process.argv))
49
+ .option('tools', {
50
+ type: 'string',
51
+ array: true,
52
+ choices: ['dynamic', 'all'],
53
+ description: 'Use dynamic tools or all tools',
54
+ })
55
+ .option('no-tools', {
56
+ type: 'string',
57
+ array: true,
58
+ choices: ['dynamic', 'all'],
59
+ description: 'Do not use any dynamic or all tools',
60
+ })
61
+ .option('tool', {
62
+ type: 'string',
63
+ array: true,
64
+ description: 'Include tools matching the specified names',
65
+ })
66
+ .option('resource', {
67
+ type: 'string',
68
+ array: true,
69
+ description: 'Include tools matching the specified resources',
70
+ })
71
+ .option('operation', {
72
+ type: 'string',
73
+ array: true,
74
+ choices: ['read', 'write'],
75
+ description: 'Include tools matching the specified operations',
76
+ })
77
+ .option('tag', {
78
+ type: 'string',
79
+ array: true,
80
+ description: 'Include tools with the specified tags',
81
+ })
82
+ .option('no-tool', {
83
+ type: 'string',
84
+ array: true,
85
+ description: 'Exclude tools matching the specified names',
86
+ })
87
+ .option('no-resource', {
88
+ type: 'string',
89
+ array: true,
90
+ description: 'Exclude tools matching the specified resources',
91
+ })
92
+ .option('no-operation', {
93
+ type: 'string',
94
+ array: true,
95
+ description: 'Exclude tools matching the specified operations',
96
+ })
97
+ .option('no-tag', {
98
+ type: 'string',
99
+ array: true,
100
+ description: 'Exclude tools with the specified tags',
101
+ })
102
+ .option('list', {
103
+ type: 'boolean',
104
+ description: 'List all tools and exit',
105
+ })
106
+ .option('client', {
107
+ type: 'string',
108
+ choices: Object.keys(knownClients),
109
+ description: 'Specify the MCP client being used',
110
+ })
111
+ .option('capability', {
112
+ type: 'string',
113
+ array: true,
114
+ description: 'Specify client capabilities',
115
+ coerce: (values: string[]) => {
116
+ return values.flatMap((v) => v.split(','));
117
+ },
118
+ })
119
+ .option('no-capability', {
120
+ type: 'string',
121
+ array: true,
122
+ description: 'Unset client capabilities',
123
+ choices: CAPABILITY_CHOICES,
124
+ coerce: (values: string[]) => {
125
+ return values.flatMap((v) => v.split(','));
126
+ },
127
+ })
128
+ .option('describe-capabilities', {
129
+ type: 'boolean',
130
+ description: 'Print detailed explanation of client capabilities and exit',
131
+ })
132
+ .help();
133
+
134
+ for (const [command, desc] of examples()) {
135
+ opts.example(command, desc);
136
+ }
137
+
138
+ const argv = opts.parseSync();
139
+
140
+ // Handle describe-capabilities flag
141
+ if (argv.describeCapabilities) {
142
+ console.log(getCapabilitiesExplanation());
143
+ process.exit(0);
144
+ }
145
+
146
+ const filters: Filter[] = [];
147
+
148
+ // Helper function to support comma-separated values
149
+ const splitValues = (values: string[] | undefined): string[] => {
150
+ if (!values) return [];
151
+ return values.flatMap((v) => v.split(','));
152
+ };
153
+
154
+ for (const tag of splitValues(argv.tag)) {
155
+ filters.push({ type: 'tag', op: 'include', value: tag });
156
+ }
157
+
158
+ for (const tag of splitValues(argv.noTag)) {
159
+ filters.push({ type: 'tag', op: 'exclude', value: tag });
160
+ }
161
+
162
+ for (const resource of splitValues(argv.resource)) {
163
+ filters.push({ type: 'resource', op: 'include', value: resource });
164
+ }
165
+
166
+ for (const resource of splitValues(argv.noResource)) {
167
+ filters.push({ type: 'resource', op: 'exclude', value: resource });
168
+ }
169
+
170
+ for (const tool of splitValues(argv.tool)) {
171
+ filters.push({ type: 'tool', op: 'include', value: tool });
172
+ }
173
+
174
+ for (const tool of splitValues(argv.noTool)) {
175
+ filters.push({ type: 'tool', op: 'exclude', value: tool });
176
+ }
177
+
178
+ for (const operation of splitValues(argv.operation)) {
179
+ filters.push({ type: 'operation', op: 'include', value: operation });
180
+ }
181
+
182
+ for (const operation of splitValues(argv.noOperation)) {
183
+ filters.push({ type: 'operation', op: 'exclude', value: operation });
184
+ }
185
+
186
+ // Parse client capabilities
187
+ const clientCapabilities: ClientCapabilities = {
188
+ topLevelUnions: true,
189
+ validJson: true,
190
+ refs: true,
191
+ unions: true,
192
+ formats: true,
193
+ toolNameLength: undefined,
194
+ };
195
+
196
+ // Apply individual capability overrides
197
+ if (Array.isArray(argv.capability)) {
198
+ for (const cap of argv.capability) {
199
+ const parsedCap = parseCapabilityValue(cap);
200
+ if (parsedCap.name === 'top-level-unions') {
201
+ clientCapabilities.topLevelUnions = true;
202
+ } else if (parsedCap.name === 'valid-json') {
203
+ clientCapabilities.validJson = true;
204
+ } else if (parsedCap.name === 'refs') {
205
+ clientCapabilities.refs = true;
206
+ } else if (parsedCap.name === 'unions') {
207
+ clientCapabilities.unions = true;
208
+ } else if (parsedCap.name === 'formats') {
209
+ clientCapabilities.formats = true;
210
+ } else if (parsedCap.name === 'tool-name-length') {
211
+ clientCapabilities.toolNameLength = parsedCap.value;
212
+ }
213
+ }
214
+ }
215
+
216
+ // Handle no-capability options to unset capabilities
217
+ if (Array.isArray(argv.noCapability)) {
218
+ for (const cap of argv.noCapability) {
219
+ if (cap === 'top-level-unions') {
220
+ clientCapabilities.topLevelUnions = false;
221
+ } else if (cap === 'valid-json') {
222
+ clientCapabilities.validJson = false;
223
+ } else if (cap === 'refs') {
224
+ clientCapabilities.refs = false;
225
+ } else if (cap === 'unions') {
226
+ clientCapabilities.unions = false;
227
+ } else if (cap === 'formats') {
228
+ clientCapabilities.formats = false;
229
+ } else if (cap === 'tool-name-length') {
230
+ clientCapabilities.toolNameLength = undefined;
231
+ }
232
+ }
233
+ }
234
+
235
+ const explicitTools = Boolean(argv.tools || argv.noTools);
236
+ const includeDynamicTools =
237
+ explicitTools ? argv.tools?.includes('dynamic') && !argv.noTools?.includes('dynamic') : undefined;
238
+ const includeAllTools =
239
+ explicitTools ? argv.tools?.includes('all') && !argv.noTools?.includes('all') : undefined;
240
+
241
+ const client = argv.client as ClientType;
242
+ return {
243
+ client: client && knownClients[client] ? client : undefined,
244
+ includeDynamicTools,
245
+ includeAllTools,
246
+ filters,
247
+ capabilities: clientCapabilities,
248
+ list: argv.list || false,
249
+ };
250
+ }
251
+
252
+ function getCapabilitiesExplanation(): string {
253
+ return `
254
+ Client Capabilities Explanation:
255
+
256
+ Different Language Models (LLMs) and the MCP clients that use them have varying limitations in how they handle tool schemas. Capability flags allow you to inform the MCP server about these limitations.
257
+
258
+ When a capability flag is set to false, the MCP server will automatically adjust the tool schemas to work around that limitation, ensuring broader compatibility.
259
+
260
+ Available Capabilities:
261
+
262
+ # top-level-unions
263
+ Some clients/LLMs do not support JSON schemas with a union type (anyOf) at the root level. If a client lacks this capability, the MCP server splits tools with top-level unions into multiple separate tools, one for each variant in the union.
264
+
265
+ # refs
266
+ Some clients/LLMs do not support $ref pointers for schema reuse. If a client lacks this capability, the MCP server automatically inlines all references ($defs) directly into the schema. Properties that would cause circular references are removed during this process.
267
+
268
+ # valid-json
269
+ Some clients/LLMs may incorrectly send arguments as a JSON-encoded string instead of a proper JSON object. If a client *has* this capability, the MCP server will attempt to parse string values as JSON if the initial validation against the schema fails.
270
+
271
+ # unions
272
+ Some clients/LLMs do not support union types (anyOf) in JSON schemas. If a client lacks this capability, the MCP server removes all anyOf fields and uses only the first variant as the schema.
273
+
274
+ # formats
275
+ Some clients/LLMs do not support the 'format' keyword in JSON Schema specifications. If a client lacks this capability, the MCP server removes all format fields and appends the format information to the field's description in parentheses.
276
+
277
+ # tool-name-length=N
278
+ Some clients/LLMs impose a maximum length on tool names. If this capability is set, the MCP server will automatically truncate tool names exceeding the specified length (N), ensuring uniqueness by appending numbers if necessary.
279
+
280
+ Client Presets (--client):
281
+ Presets like '--client=openai-agents' or '--client=cursor' automatically configure these capabilities based on current known limitations of those clients, simplifying setup.
282
+
283
+ Current presets:
284
+ ${JSON.stringify(knownClients, null, 2)}
285
+ `;
286
+ }
287
+
288
+ function examples(): [string, string][] {
289
+ const firstEndpoint = endpoints[0]!;
290
+ const secondEndpoint =
291
+ endpoints.find((e) => e.metadata.resource !== firstEndpoint.metadata.resource) || endpoints[1];
292
+ const tag = endpoints.find((e) => e.metadata.tags.length > 0)?.metadata.tags[0];
293
+ const otherEndpoint = secondEndpoint || firstEndpoint;
294
+
295
+ return [
296
+ [
297
+ `--tool="${firstEndpoint.tool.name}" ${secondEndpoint ? `--tool="${secondEndpoint.tool.name}"` : ''}`,
298
+ 'Include tools by name',
299
+ ],
300
+ [
301
+ `--resource="${firstEndpoint.metadata.resource}" --operation="read"`,
302
+ 'Filter by resource and operation',
303
+ ],
304
+ [
305
+ `--resource="${otherEndpoint.metadata.resource}*" --no-tool="${otherEndpoint.tool.name}"`,
306
+ 'Use resource wildcards and exclusions',
307
+ ],
308
+ [`--client="cursor"`, 'Adjust schemas to be more compatible with Cursor'],
309
+ [
310
+ `--capability="top-level-unions" --capability="tool-name-length=40"`,
311
+ 'Specify individual client capabilities',
312
+ ],
313
+ [
314
+ `--client="cursor" --no-capability="tool-name-length"`,
315
+ 'Use cursor client preset but remove tool name length limit',
316
+ ],
317
+ ...(tag ? [[`--tag="${tag}"`, 'Filter based on tags'] as [string, string]] : []),
318
+ ];
319
+ }
package/src/server.ts ADDED
@@ -0,0 +1,145 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { Endpoint, endpoints, HandlerFunction, query } from './tools';
6
+ import { CallToolRequestSchema, ListToolsRequestSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
7
+ import { ClientOptions } from '@bluehive/sdk';
8
+ import BlueHive from '@bluehive/sdk';
9
+ import {
10
+ applyCompatibilityTransformations,
11
+ ClientCapabilities,
12
+ defaultClientCapabilities,
13
+ knownClients,
14
+ parseEmbeddedJSON,
15
+ } from './compat';
16
+ import { dynamicTools } from './dynamic-tools';
17
+ import { McpOptions } from './options';
18
+
19
+ export { McpOptions } from './options';
20
+ export { ClientType } from './compat';
21
+ export { Filter } from './tools';
22
+ export { ClientOptions } from '@bluehive/sdk';
23
+ export { endpoints } from './tools';
24
+
25
+ // Create server instance
26
+ export const server = new McpServer(
27
+ {
28
+ name: 'blue_hive_sdk_api',
29
+ version: '0.1.0-alpha.2',
30
+ },
31
+ {
32
+ capabilities: {
33
+ tools: {},
34
+ },
35
+ },
36
+ );
37
+
38
+ /**
39
+ * Initializes the provided MCP Server with the given tools and handlers.
40
+ * If not provided, the default client, tools and handlers will be used.
41
+ */
42
+ export function initMcpServer(params: {
43
+ server: Server | McpServer;
44
+ clientOptions: ClientOptions;
45
+ mcpOptions: McpOptions;
46
+ endpoints?: { tool: Tool; handler: HandlerFunction }[];
47
+ }) {
48
+ const transformedEndpoints = selectTools(endpoints, params.mcpOptions);
49
+ const client = new BlueHive(params.clientOptions);
50
+ const capabilities = {
51
+ ...defaultClientCapabilities,
52
+ ...(params.mcpOptions.client ? knownClients[params.mcpOptions.client] : params.mcpOptions.capabilities),
53
+ };
54
+ init({ server: params.server, client, endpoints: transformedEndpoints, capabilities });
55
+ }
56
+
57
+ export function init(params: {
58
+ server: Server | McpServer;
59
+ client?: BlueHive;
60
+ endpoints?: { tool: Tool; handler: HandlerFunction }[];
61
+ capabilities?: Partial<ClientCapabilities>;
62
+ }) {
63
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
64
+ const providedEndpoints = params.endpoints || endpoints;
65
+
66
+ const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
67
+
68
+ const client = params.client || new BlueHive({ defaultHeaders: { 'X-Stainless-MCP': 'true' } });
69
+
70
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
71
+ return {
72
+ tools: providedEndpoints.map((endpoint) => endpoint.tool),
73
+ };
74
+ });
75
+
76
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
77
+ const { name, arguments: args } = request.params;
78
+ const endpoint = endpointMap[name];
79
+ if (!endpoint) {
80
+ throw new Error(`Unknown tool: ${name}`);
81
+ }
82
+
83
+ return executeHandler(endpoint.tool, endpoint.handler, client, args, params.capabilities);
84
+ });
85
+ }
86
+
87
+ /**
88
+ * Selects the tools to include in the MCP Server based on the provided options.
89
+ */
90
+ export function selectTools(endpoints: Endpoint[], options: McpOptions) {
91
+ const filteredEndpoints = query(options.filters, endpoints);
92
+
93
+ let includedTools = filteredEndpoints;
94
+
95
+ if (includedTools.length > 0) {
96
+ if (options.includeDynamicTools) {
97
+ includedTools = dynamicTools(includedTools);
98
+ }
99
+ } else {
100
+ if (options.includeAllTools) {
101
+ includedTools = endpoints;
102
+ } else if (options.includeDynamicTools) {
103
+ includedTools = dynamicTools(endpoints);
104
+ } else {
105
+ includedTools = endpoints;
106
+ }
107
+ }
108
+
109
+ const capabilities = { ...defaultClientCapabilities, ...options.capabilities };
110
+ return applyCompatibilityTransformations(includedTools, capabilities);
111
+ }
112
+
113
+ /**
114
+ * Runs the provided handler with the given client and arguments.
115
+ */
116
+ export async function executeHandler(
117
+ tool: Tool,
118
+ handler: HandlerFunction,
119
+ client: BlueHive,
120
+ args: Record<string, unknown> | undefined,
121
+ compatibilityOptions?: Partial<ClientCapabilities>,
122
+ ) {
123
+ const options = { ...defaultClientCapabilities, ...compatibilityOptions };
124
+ if (options.validJson && args) {
125
+ args = parseEmbeddedJSON(args, tool.inputSchema);
126
+ }
127
+ return await handler(client, args || {});
128
+ }
129
+
130
+ export const readEnv = (env: string): string | undefined => {
131
+ if (typeof (globalThis as any).process !== 'undefined') {
132
+ return (globalThis as any).process.env?.[env]?.trim();
133
+ } else if (typeof (globalThis as any).Deno !== 'undefined') {
134
+ return (globalThis as any).Deno.env?.get?.(env)?.trim();
135
+ }
136
+ return;
137
+ };
138
+
139
+ export const readEnvOrError = (env: string): string => {
140
+ let envValue = readEnv(env);
141
+ if (envValue === undefined) {
142
+ throw new Error(`Environment variable ${env} is not set`);
143
+ }
144
+ return envValue;
145
+ };
@@ -0,0 +1,31 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { asTextContentResult } from '@bluehive/sdk-mcp/tools/types';
4
+
5
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
+ import type { Metadata } from '../';
7
+ import BlueHive from '@bluehive/sdk';
8
+
9
+ export const metadata: Metadata = {
10
+ resource: 'database',
11
+ operation: 'read',
12
+ tags: [],
13
+ httpMethod: 'get',
14
+ httpPath: '/v1/database/health',
15
+ operationId: 'checkDatabaseHealth',
16
+ };
17
+
18
+ export const tool: Tool = {
19
+ name: 'check_health_database',
20
+ description: 'Check MongoDB database connectivity and retrieve health statistics.',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {},
24
+ },
25
+ };
26
+
27
+ export const handler = async (client: BlueHive, args: Record<string, unknown> | undefined) => {
28
+ return asTextContentResult(await client.database.checkHealth());
29
+ };
30
+
31
+ export default { metadata, tool, handler };
@@ -0,0 +1,31 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { asTextContentResult } from '@bluehive/sdk-mcp/tools/types';
4
+
5
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
+ import type { Metadata } from '../';
7
+ import BlueHive from '@bluehive/sdk';
8
+
9
+ export const metadata: Metadata = {
10
+ resource: 'fax',
11
+ operation: 'read',
12
+ tags: [],
13
+ httpMethod: 'get',
14
+ httpPath: '/v1/fax/providers',
15
+ operationId: 'listFaxProviders',
16
+ };
17
+
18
+ export const tool: Tool = {
19
+ name: 'list_providers_fax',
20
+ description: 'Get a list of available fax providers and their configuration status.',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {},
24
+ },
25
+ };
26
+
27
+ export const handler = async (client: BlueHive, args: Record<string, unknown> | undefined) => {
28
+ return asTextContentResult(await client.fax.listProviders());
29
+ };
30
+
31
+ export default { metadata, tool, handler };
@@ -0,0 +1,36 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { asTextContentResult } from '@bluehive/sdk-mcp/tools/types';
4
+
5
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
+ import type { Metadata } from '../';
7
+ import BlueHive from '@bluehive/sdk';
8
+
9
+ export const metadata: Metadata = {
10
+ resource: 'fax',
11
+ operation: 'read',
12
+ tags: [],
13
+ httpMethod: 'get',
14
+ httpPath: '/v1/fax/status/{id}',
15
+ operationId: 'getFaxStatus',
16
+ };
17
+
18
+ export const tool: Tool = {
19
+ name: 'retrieve_status_fax',
20
+ description: 'Retrieve the current status and details of a fax by its ID.',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {
24
+ id: {
25
+ type: 'string',
26
+ },
27
+ },
28
+ },
29
+ };
30
+
31
+ export const handler = async (client: BlueHive, args: Record<string, unknown> | undefined) => {
32
+ const { id, ...body } = args as any;
33
+ return asTextContentResult(await client.fax.retrieveStatus(id));
34
+ };
35
+
36
+ export default { metadata, tool, handler };