Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anythingmcp",
"version": "0.55.7",
"version": "0.55.8",
"description": "Turn any REST/OpenAPI, SOAP/WSDL, GraphQL, OData or SQL API into MCP tools for Claude, ChatGPT and Copilot, no code. 957 pre-built adapters for ERP, e-commerce and more (SAP S/4HANA, SAP Business One, Odoo, Xentral, JTL-Wawi, Shopware, WooCommerce, Amazon Seller). Self-hosted, open source (AGPL-3.0).",
"private": true,
"license": "AGPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anythingmcp/backend",
"version": "0.55.7",
"version": "0.55.8",
"description": "AnythingMCP — NestJS Backend + Dynamic MCP Server",
"private": true,
"license": "AGPL-3.0-only",
Expand Down
25 changes: 24 additions & 1 deletion packages/backend/src/adapters/adapters.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BadRequestException } from '@nestjs/common';
import { AdaptersService } from './adapters.service';
import { AdaptersService, trimTrailingDotsAndSpace } from './adapters.service';
import { outboundRequest } from '../common/outbound-http';

// The pre-sign-in check of the app keys (Etsy) goes out through this; no
Expand Down Expand Up @@ -1526,3 +1526,26 @@ describe('AdaptersService check — a server that only accepts approved IPs', ()
expect(info.requiresIpAllowlist).toBe(true);
});
});

describe('trimTrailingDotsAndSpace', () => {
it.each([
['Request failed with status code 500', 'Request failed with status code 500'],
['Upstream error. ', 'Upstream error'],
['Timed out...\n\t', 'Timed out'],
['v1.2 is gone .\u00a0', 'v1.2 is gone'],
[' keep leading', ' keep leading'],
['. . .', ''],
['', ''],
])('%j becomes %j', (value, expected) => {
expect(trimTrailingDotsAndSpace(value)).toBe(expected);
expect(trimTrailingDotsAndSpace(value)).toBe(value.replace(/[.\s]+$/, ''));
});

it('answers a message with a long run of spaces at once', () => {
const message = `a${' '.repeat(50_000)}x`;
const started = Date.now();
expect(trimTrailingDotsAndSpace(message)).toBe(message);
expect(trimTrailingDotsAndSpace(`${message}${' .'.repeat(25_000)}`)).toBe(message);
expect(Date.now() - started).toBeLessThan(200);
});
});
19 changes: 17 additions & 2 deletions packages/backend/src/adapters/adapters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,21 @@ function rawResponseText(err: any): string {
}
}

/**
* `text` without its trailing dots and whitespace: what `/[.\s]+$/` removes,
* in one pass from the end. The regex retries every run of spaces in the
* middle of a long message, which is quadratic in its length.
*/
export function trimTrailingDotsAndSpace(text: string): string {
let end = text.length;
while (end > 0) {
const ch = text[end - 1];
if (ch !== '.' && !/\s/.test(ch)) break;
end--;
}
return text.slice(0, end);
}

function withResponseExcerpt(message: string, err: any, max = 200): string {
const data = err?.response?.data;
if (data === undefined || data === null || message.includes('body=')) return message;
Expand All @@ -1640,10 +1655,10 @@ function withResponseExcerpt(message: string, err: any, max = 200): string {
return message;
}
// A web page instead of API data: its readable words, never its markup.
if (looksLikeHtml(body)) return `${message.replace(/[.\s]+$/, '')}: ${describeHtmlAnswer(body, max)}`;
if (looksLikeHtml(body)) return `${trimTrailingDotsAndSpace(message)}: ${describeHtmlAnswer(body, max)}`;
body = body.replace(/\s+/g, ' ').trim();
if (!body || body === '{}' || body === '""' || message.includes(body)) return message;
return `${message.replace(/[.\s]+$/, '')}: ${body.length > max ? `${body.slice(0, max)}…` : body}`;
return `${trimTrailingDotsAndSpace(message)}: ${body.length > max ? `${body.slice(0, max)}…` : body}`;
}

function truncateSample(value: unknown, max = 600): string {
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/adapters/intl/gohighlevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
},
"page_limit": {
"type": "integer",
"description": "Contacts per page, at most 500 (default 20)."
"description": "Contacts per page, at most 500 (default 20).",
"default": 20
},
"search_after": {
"type": "array",
Expand Down
59 changes: 59 additions & 0 deletions packages/backend/src/adapters/intl/gohighlevel.live.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import axios from 'axios';
import * as adapter from './gohighlevel.json';
import { RestEngine } from '../../connectors/engines/rest.engine';
import { OAuth2TokenService } from '../../connectors/engines/oauth2-token.service';
import { LoginTokenService } from '../../connectors/engines/login-token.service';
import { applySchemaDefaults } from '../../common/schema-defaults.util';
import { interpolateConnectorConfig, interpolateDeep } from '../../common/env-interpolation.util';

/**
* HighLevel API v2 (marketplace.gohighlevel.com/docs, OpenAPI at github.com/GoHighLevel/highlevel-api-docs):
Expand All @@ -8,6 +14,18 @@ import * as adapter from './gohighlevel.json';
* GOHIGHLEVEL_API_TOKEN=... GOHIGHLEVEL_LOCATION_ID=... RUN_GOHIGHLEVEL_LIVE=1 npx jest src/adapters/intl/gohighlevel
*/

jest.mock('axios', () => {
const actual = jest.requireActual('axios');
const mocked = jest.fn();
return {
__esModule: true,
// Keep every real static (getUri, getAdapter...), mock only the call itself.
default: Object.assign(mocked, actual.default, { __actual: actual.default }),
AxiosError: actual.AxiosError,
};
});
const mockedAxios = axios as unknown as jest.Mock;

type Tool = {
name: string;
description: string;
Expand Down Expand Up @@ -53,6 +71,30 @@ const used = (t: Tool) => {
};
const PREFIX = 'gohighlevel_';

// Runs a tool the way DynamicMcpTools.executeTool does: {{VAR}} interpolated,
// the schema defaults filled in for arguments the caller left out, then the
// REST engine builds the request (axios is mocked, nothing leaves the test).
const ENV_VALUES = { GOHIGHLEVEL_API_TOKEN: 'pit-test-token', GOHIGHLEVEL_LOCATION_ID: 've9EPM428h8vShlRW1KT' };
const execute = (name: string, params: Record<string, unknown>) => {
const t = tool(name);
const { config, endpointMapping } = interpolateConnectorConfig(
{ baseUrl: a.connector.baseUrl, headers: a.connector.headers },
t.endpointMapping as Parameters<typeof interpolateConnectorConfig>[1],
ENV_VALUES,
);
return new RestEngine({} as OAuth2TokenService, {} as LoginTokenService).execute(
{
baseUrl: config.baseUrl,
authType: a.connector.authType,
authConfig: interpolateDeep({ ...a.connector.authConfig }, ENV_VALUES),
headers: config.headers,
},
endpointMapping,
applySchemaDefaults(t.parameters, params),
);
};
const sent = () => mockedAxios.mock.calls[0][0];

describe('gohighlevel adapter: static spec conformance', () => {

const LOC = '{{GOHIGHLEVEL_LOCATION_ID}}';
Expand Down Expand Up @@ -88,6 +130,23 @@ describe('gohighlevel adapter: static spec conformance', () => {
expect((tool(n).endpointMapping.queryParams as Record<string, unknown>).locationId).toBe(LOC);
});

describe('contact search page size', () => {
beforeEach(() => mockedAxios.mockReset().mockResolvedValue({ data: { contacts: [], total: 0 } }));

// HighLevel answers 422 "pageLimit must be a number" when the body has no pageLimit.
it('sends pageLimit 20 when the caller leaves page_limit out', async () => {
expect(tool('gohighlevel_search_contacts').parameters?.properties?.page_limit?.default).toBe(20);
await execute('gohighlevel_search_contacts', { query: 'anna' });
expect(sent()).toMatchObject({ method: 'POST', url: 'https://services.leadconnectorhq.com/contacts/search' });
expect(sent().data).toEqual({ locationId: ENV_VALUES.GOHIGHLEVEL_LOCATION_ID, query: 'anna', pageLimit: 20 });
});

it('keeps the page_limit the caller gives', async () => {
await execute('gohighlevel_search_contacts', { page_limit: 100, page: 2 });
expect(sent().data).toEqual({ locationId: ENV_VALUES.GOHIGHLEVEL_LOCATION_ID, page: 2, pageLimit: 100 });
});
});

it('maps contacts, workflows, messages, opportunities, appointments and invoices', () => {
expect(tool('gohighlevel_upsert_contact').endpointMapping).toMatchObject({ method: 'POST', path: '/contacts/upsert' });
expect(tool('gohighlevel_update_contact').endpointMapping).toMatchObject({ method: 'PUT', path: '/contacts/{contact_id}' });
Expand Down
Loading
Loading