@oriva/mcp-server 0.1.3 → 0.2.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/dist/client.js CHANGED
@@ -1,55 +1,63 @@
1
+ import { rawClient, rawSdk } from '@oriva/sdk';
1
2
  const DEFAULT_BASE_URL = 'https://api.oriva.io';
2
- export async function callOperation(op, args, options) {
3
+ let configuredKey;
4
+ let configuredBaseUrl;
5
+ function ensureClientConfigured(options) {
3
6
  const baseUrl = options.baseUrl ?? process.env.ORIVA_API_BASE_URL ?? DEFAULT_BASE_URL;
4
- let path = op.path;
5
- for (const name of op.pathParams) {
6
- const value = args[name];
7
- if (value === undefined || value === null) {
8
- throw new Error(`Missing required path parameter: ${name}`);
9
- }
10
- path = path.replace(`{${name}}`, encodeURIComponent(String(value)));
7
+ if (configuredKey === options.apiKey && configuredBaseUrl === baseUrl)
8
+ return;
9
+ rawClient.setConfig({
10
+ baseUrl,
11
+ headers: {
12
+ Authorization: `Bearer ${options.apiKey}`,
13
+ 'User-Agent': '@oriva/mcp-server/0.2.0',
14
+ },
15
+ });
16
+ configuredKey = options.apiKey;
17
+ configuredBaseUrl = baseUrl;
18
+ }
19
+ function pickByKeys(args, keys) {
20
+ if (keys.length === 0)
21
+ return undefined;
22
+ const out = {};
23
+ for (const k of keys) {
24
+ if (args[k] !== undefined)
25
+ out[k] = args[k];
11
26
  }
12
- const qs = new URLSearchParams();
13
- for (const name of op.queryParams) {
14
- const value = args[name];
15
- if (value === undefined || value === null)
16
- continue;
17
- if (Array.isArray(value)) {
18
- for (const item of value)
19
- qs.append(name, String(item));
20
- }
21
- else {
22
- qs.set(name, String(value));
23
- }
27
+ return Object.keys(out).length > 0 ? out : undefined;
28
+ }
29
+ function buildBody(args, bodyFields) {
30
+ if (bodyFields.length === 0)
31
+ return undefined;
32
+ const out = {};
33
+ for (const { alias, original } of bodyFields) {
34
+ if (args[alias] !== undefined)
35
+ out[original] = args[alias];
24
36
  }
25
- const queryString = qs.toString();
26
- let body;
27
- let contentType;
28
- const methodAllowsBody = op.method !== 'get' && op.method !== 'head' && op.method !== 'delete';
29
- if (methodAllowsBody && op.bodyFields.length > 0) {
30
- const bodyObj = {};
31
- for (const { alias, original } of op.bodyFields) {
32
- if (args[alias] !== undefined)
33
- bodyObj[original] = args[alias];
34
- }
35
- if (Object.keys(bodyObj).length > 0) {
36
- body = JSON.stringify(bodyObj);
37
- contentType = 'application/json';
38
- }
37
+ return Object.keys(out).length > 0 ? out : undefined;
38
+ }
39
+ export async function callOperation(op, args, options) {
40
+ ensureClientConfigured(options);
41
+ const fn = rawSdk[op.toolName];
42
+ if (typeof fn !== 'function') {
43
+ throw new Error(`No SDK method for operationId: ${op.toolName}`);
39
44
  }
40
- const url = `${baseUrl}${path}${queryString ? '?' + queryString : ''}`;
41
- const headers = {
42
- Authorization: `Bearer ${options.apiKey}`,
43
- Accept: 'application/json',
44
- 'User-Agent': '@oriva/mcp-server/0.1.0',
45
+ const sdkOptions = {};
46
+ const path = pickByKeys(args, op.pathParams);
47
+ const query = pickByKeys(args, op.queryParams);
48
+ const body = buildBody(args, op.bodyFields);
49
+ if (path)
50
+ sdkOptions.path = path;
51
+ if (query)
52
+ sdkOptions.query = query;
53
+ if (body)
54
+ sdkOptions.body = body;
55
+ const result = await fn(sdkOptions);
56
+ const payload = result.data ?? result.error ?? null;
57
+ const text = payload === null ? '' : typeof payload === 'string' ? payload : JSON.stringify(payload);
58
+ return {
59
+ status: result.response.status,
60
+ text,
61
+ ok: result.response.ok,
45
62
  };
46
- if (contentType)
47
- headers['Content-Type'] = contentType;
48
- const res = await fetch(url, {
49
- method: op.method.toUpperCase(),
50
- headers,
51
- body,
52
- });
53
- const text = await res.text();
54
- return { status: res.status, text, ok: res.ok };
55
63
  }
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { dirname, join } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
6
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
- import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
7
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
8
8
  import { callOperation } from './client.js';
9
9
  import { getSpecInfo, projectTools } from './openapi.js';
10
10
  const __dirname = dirname(fileURLToPath(import.meta.url));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oriva/mcp-server",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Model Context Protocol server for the Oriva public API. Exposes all 46 public endpoints as MCP tools for use in Claude Code, Cursor, Continue, and Claude Desktop.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,8 @@
21
21
  "start": "node dist/index.js"
22
22
  },
23
23
  "dependencies": {
24
- "@modelcontextprotocol/sdk": "^1.6.0"
24
+ "@modelcontextprotocol/sdk": "^1.6.0",
25
+ "@oriva/sdk": "^0.1.0"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/node": "^20.0.0",