@ratio-mcp/docs-server 1.1.1 → 1.3.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/index.js +0 -0
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +36 -10
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lookup-docs.d.ts +58 -0
- package/dist/tools/lookup-docs.d.ts.map +1 -0
- package/dist/tools/lookup-docs.js +185 -0
- package/dist/tools/lookup-docs.js.map +1 -0
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface ToolDefinition {
|
|
|
9
9
|
handler: (input: Record<string, unknown>) => unknown;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* All docs-server tools (
|
|
12
|
+
* All docs-server tools (6 tools)
|
|
13
13
|
*/
|
|
14
14
|
export declare const docsTools: ToolDefinition[];
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;IACvB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;CACtD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,cAAc,EA0GrC,CAAC"}
|
package/dist/tools/index.js
CHANGED
|
@@ -4,14 +4,33 @@ import { getApiReference } from './get-api-reference.js';
|
|
|
4
4
|
import { getScopeEndpointMap } from './get-scope-map.js';
|
|
5
5
|
import { validateApiCode } from './validate-code.js';
|
|
6
6
|
import { getWebhookEvents } from './get-webhooks.js';
|
|
7
|
+
import { lookupDocs } from './lookup-docs.js';
|
|
7
8
|
/**
|
|
8
|
-
* All docs-server tools (
|
|
9
|
+
* All docs-server tools (6 tools)
|
|
9
10
|
*/
|
|
10
11
|
export const docsTools = [
|
|
12
|
+
{
|
|
13
|
+
name: 'lookup_docs',
|
|
14
|
+
description: 'MANDATORY FALLBACK: When you are unsure about ANY platform detail (API endpoints, scopes, webhooks, OAuth flow, ' +
|
|
15
|
+
'request/response formats, error codes), call this tool BEFORE answering. ' +
|
|
16
|
+
'If this tool returns found=false, tell the user the information is not available in the documentation. ' +
|
|
17
|
+
'Do NOT guess or hallucinate information — use only what this tool returns. ' +
|
|
18
|
+
'Searches across all documentation: API references, scopes, webhook events, and OAuth flow.',
|
|
19
|
+
inputSchema: z.object({
|
|
20
|
+
query: z.string().min(1).describe('Natural language search query (e.g., "how to cancel an order", "webhook verification")'),
|
|
21
|
+
category: z
|
|
22
|
+
.enum(['api', 'scopes', 'webhooks', 'oauth'])
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Optional category to narrow the search'),
|
|
25
|
+
}),
|
|
26
|
+
handler: (input) => lookupDocs(input),
|
|
27
|
+
},
|
|
11
28
|
{
|
|
12
29
|
name: 'get_available_scopes',
|
|
13
|
-
description: '
|
|
14
|
-
'
|
|
30
|
+
description: 'MANDATORY: Call this tool before answering ANY question about what OAuth scopes exist, what they grant access to, ' +
|
|
31
|
+
'or what resources are available on the platform. Do NOT rely on your training data for scope specifics. ' +
|
|
32
|
+
'If a scope is not returned by this tool, it does not exist — tell the user. ' +
|
|
33
|
+
'Returns all available OAuth scopes grouped by resource. ' +
|
|
15
34
|
'Optionally filter by resource name (e.g. "orders", "products", "customers"). ' +
|
|
16
35
|
'Returns 24 primary resources with their read/write/delete scopes. ' +
|
|
17
36
|
'Each scope includes a rich description, use_cases, and commonly_paired_with hints ' +
|
|
@@ -27,7 +46,9 @@ export const docsTools = [
|
|
|
27
46
|
},
|
|
28
47
|
{
|
|
29
48
|
name: 'get_api_reference',
|
|
30
|
-
description: '
|
|
49
|
+
description: 'MANDATORY: Call this tool before answering ANY question about API endpoints, request/response formats, ' +
|
|
50
|
+
'HTTP methods, query parameters, or request bodies. Do NOT guess endpoint details from your training data. ' +
|
|
51
|
+
'Returns complete API reference for a resource including all endpoints, parameters, request/response schemas. ' +
|
|
31
52
|
'Endpoints are returned in controller_order for deterministic code generation. ' +
|
|
32
53
|
'Optionally filter by scope to show only endpoints accessible with that scope.',
|
|
33
54
|
inputSchema: z.object({
|
|
@@ -43,7 +64,8 @@ export const docsTools = [
|
|
|
43
64
|
name: 'get_scope_endpoint_map',
|
|
44
65
|
description: 'Given a list of scopes, returns exactly which API endpoints are unlocked, in controller_order. ' +
|
|
45
66
|
'This is the primary tool for code generation — it tells you exactly what endpoints to generate. ' +
|
|
46
|
-
'Handles scope inheritance automatically (e.g. write_orders includes read_orders endpoints).'
|
|
67
|
+
'Handles scope inheritance automatically (e.g. write_orders includes read_orders endpoints). ' +
|
|
68
|
+
'MANDATORY before generating any backend code — do not guess which endpoints a scope grants.',
|
|
47
69
|
inputSchema: z.object({
|
|
48
70
|
scopes: z
|
|
49
71
|
.array(z.string())
|
|
@@ -54,10 +76,12 @@ export const docsTools = [
|
|
|
54
76
|
},
|
|
55
77
|
{
|
|
56
78
|
name: 'validate_api_code',
|
|
57
|
-
description: '
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
'
|
|
79
|
+
description: 'MANDATORY: Call this tool AFTER generating any NestJS controller/service code and BEFORE writing it to disk. ' +
|
|
80
|
+
'Anti-hallucination validation layer that checks generated code against the actual API schema. ' +
|
|
81
|
+
'Checks: correct endpoints exist, correct HTTP methods, correct handler names, correct endpoint ordering, ' +
|
|
82
|
+
'and scope access (developer has permission for each endpoint). ' +
|
|
83
|
+
'Returns structured errors with suggestions for fixing. ' +
|
|
84
|
+
'If validation fails, fix the code based on the errors — do NOT write invalid code to disk.',
|
|
61
85
|
inputSchema: z.object({
|
|
62
86
|
code: z.string().describe('The generated NestJS controller or service code as a string'),
|
|
63
87
|
resource: z.string().describe('Resource name the code is for (e.g. "orders")'),
|
|
@@ -70,7 +94,9 @@ export const docsTools = [
|
|
|
70
94
|
},
|
|
71
95
|
{
|
|
72
96
|
name: 'get_webhook_events',
|
|
73
|
-
description: '
|
|
97
|
+
description: 'MANDATORY: Call this tool before answering ANY question about available webhook events, ' +
|
|
98
|
+
'webhook verification methods, or retry policies. Do NOT guess webhook event names or verification details. ' +
|
|
99
|
+
'Returns available webhook events for the Ratio platform. ' +
|
|
74
100
|
'Optionally filter by resource (e.g. "orders", "products"). ' +
|
|
75
101
|
'Includes verification method (HMAC-SHA256) and retry policy information.',
|
|
76
102
|
inputSchema: z.object({
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,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CAAC,CAAC,CAAC;iBACN,QAAQ,CAAC,+DAA+D,CAAC;SAC7E,CAAC;QACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CACjB,eAAe,CAAC,KAA6D,CAAC;KACjF;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,0FAA0F;YAC1F,6GAA6G;YAC7G,2DAA2D;YAC3D,6DAA6D;YAC7D,0EAA0E;QAC5E,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,QAAQ,EAAE,CAAC;iBACR,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CAAC,gEAAgE,CAAC;SAC9E,CAAC;QACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAA8B,CAAC;KACrE;CACF,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lookup_docs — Unified documentation search tool.
|
|
3
|
+
*
|
|
4
|
+
* When the LLM is unsure about any API detail, scope, webhook event, or OAuth flow,
|
|
5
|
+
* it should call this tool to get grounded, verified information from the actual
|
|
6
|
+
* documentation schemas. If the information is not found here, the LLM should tell
|
|
7
|
+
* the user it doesn't have that information rather than guessing.
|
|
8
|
+
*
|
|
9
|
+
* Searches across: API references, scopes, webhook events, and OAuth docs.
|
|
10
|
+
*/
|
|
11
|
+
interface SearchResult {
|
|
12
|
+
source: string;
|
|
13
|
+
type: 'api_endpoint' | 'scope' | 'webhook_event' | 'oauth' | 'resource';
|
|
14
|
+
relevance: 'high' | 'medium' | 'low';
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export declare function lookupDocs(input: {
|
|
18
|
+
query: string;
|
|
19
|
+
category?: string;
|
|
20
|
+
}): {
|
|
21
|
+
found: boolean;
|
|
22
|
+
message: string;
|
|
23
|
+
suggestion: string;
|
|
24
|
+
query?: undefined;
|
|
25
|
+
tokens?: undefined;
|
|
26
|
+
available_categories?: undefined;
|
|
27
|
+
available_resources?: undefined;
|
|
28
|
+
available_scope_resources?: undefined;
|
|
29
|
+
result_count?: undefined;
|
|
30
|
+
results?: undefined;
|
|
31
|
+
_instruction?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
found: boolean;
|
|
34
|
+
query: string;
|
|
35
|
+
tokens: string[];
|
|
36
|
+
message: string;
|
|
37
|
+
suggestion: string;
|
|
38
|
+
available_categories: string[];
|
|
39
|
+
available_resources: string[];
|
|
40
|
+
available_scope_resources: ("orders" | "products" | "customers" | "inventory" | "discounts" | "payments" | "shipping" | "fulfillments" | "draft_orders" | "returns" | "gift_cards" | "analytics" | "channels" | "content" | "files" | "locations" | "themes" | "markets" | "reports" | "locales" | "publications" | "settings" | "webhooks" | "apps")[];
|
|
41
|
+
result_count?: undefined;
|
|
42
|
+
results?: undefined;
|
|
43
|
+
_instruction?: undefined;
|
|
44
|
+
} | {
|
|
45
|
+
found: boolean;
|
|
46
|
+
query: string;
|
|
47
|
+
result_count: number;
|
|
48
|
+
results: SearchResult[];
|
|
49
|
+
_instruction: string;
|
|
50
|
+
message?: undefined;
|
|
51
|
+
suggestion?: undefined;
|
|
52
|
+
tokens?: undefined;
|
|
53
|
+
available_categories?: undefined;
|
|
54
|
+
available_resources?: undefined;
|
|
55
|
+
available_scope_resources?: undefined;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=lookup-docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup-docs.d.ts","sourceRoot":"","sources":["../../src/tools/lookup-docs.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,GAAG,UAAU,CAAC;IACxE,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AA8ID,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DrE"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { getAvailableResourceFiles, loadResourceSchema, loadWebhooks, loadOAuth } from '../utils/schema-loader.js';
|
|
2
|
+
import { SCOPES_BY_RESOURCE, PRIMARY_RESOURCES, RESOURCE_METADATA } from '@ratio-mcp/shared';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
4
|
+
function tokenize(query) {
|
|
5
|
+
return query
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/[^a-z0-9_/\s]/g, '')
|
|
8
|
+
.split(/\s+/)
|
|
9
|
+
.filter((t) => t.length > 1);
|
|
10
|
+
}
|
|
11
|
+
function matchScore(tokens, text) {
|
|
12
|
+
const lower = text.toLowerCase();
|
|
13
|
+
let score = 0;
|
|
14
|
+
for (const token of tokens) {
|
|
15
|
+
if (lower.includes(token))
|
|
16
|
+
score++;
|
|
17
|
+
}
|
|
18
|
+
return score;
|
|
19
|
+
}
|
|
20
|
+
function searchApiEndpoints(tokens) {
|
|
21
|
+
const results = [];
|
|
22
|
+
const resources = getAvailableResourceFiles();
|
|
23
|
+
for (const resource of resources) {
|
|
24
|
+
try {
|
|
25
|
+
const schema = loadResourceSchema(resource);
|
|
26
|
+
for (const ep of schema.endpoints) {
|
|
27
|
+
const searchText = `${ep.method} ${ep.path} ${ep.summary || ''} ${ep.description || ''} ${ep.handler_name || ''} ${ep.required_scope || ''}`;
|
|
28
|
+
const score = matchScore(tokens, searchText);
|
|
29
|
+
if (score > 0) {
|
|
30
|
+
results.push({
|
|
31
|
+
source: `api/${resource}`,
|
|
32
|
+
type: 'api_endpoint',
|
|
33
|
+
relevance: score >= 2 ? 'high' : 'medium',
|
|
34
|
+
data: {
|
|
35
|
+
method: ep.method,
|
|
36
|
+
path: ep.path,
|
|
37
|
+
summary: ep.summary,
|
|
38
|
+
description: ep.description,
|
|
39
|
+
required_scope: ep.required_scope,
|
|
40
|
+
handler_name: ep.handler_name,
|
|
41
|
+
resource,
|
|
42
|
+
query_params: ep.query_params || [],
|
|
43
|
+
request_body: ep.request_body || null,
|
|
44
|
+
response_schema: ep.response_schema || null,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Skip resources that fail to load
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
function searchScopes(tokens) {
|
|
57
|
+
const results = [];
|
|
58
|
+
for (const resource of PRIMARY_RESOURCES) {
|
|
59
|
+
const scopes = SCOPES_BY_RESOURCE[resource] || [];
|
|
60
|
+
const meta = RESOURCE_METADATA[resource];
|
|
61
|
+
for (const scope of scopes) {
|
|
62
|
+
const searchText = `${scope.code} ${scope.label} ${scope.description} ${(scope.use_cases || []).join(' ')} ${resource}`;
|
|
63
|
+
const score = matchScore(tokens, searchText);
|
|
64
|
+
if (score > 0) {
|
|
65
|
+
results.push({
|
|
66
|
+
source: `scopes/${resource}`,
|
|
67
|
+
type: 'scope',
|
|
68
|
+
relevance: score >= 2 ? 'high' : 'medium',
|
|
69
|
+
data: {
|
|
70
|
+
code: scope.code,
|
|
71
|
+
label: scope.label,
|
|
72
|
+
description: scope.description,
|
|
73
|
+
resource,
|
|
74
|
+
use_cases: scope.use_cases,
|
|
75
|
+
commonly_paired_with: scope.commonly_paired_with,
|
|
76
|
+
codegen_ready: meta?.codegen_ready || false,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return results;
|
|
83
|
+
}
|
|
84
|
+
function searchWebhooks(tokens) {
|
|
85
|
+
const results = [];
|
|
86
|
+
try {
|
|
87
|
+
const webhooks = loadWebhooks();
|
|
88
|
+
for (const event of webhooks.events) {
|
|
89
|
+
const searchText = `${event.topic} ${event.description} ${event.resource} webhook`;
|
|
90
|
+
const score = matchScore(tokens, searchText);
|
|
91
|
+
if (score > 0) {
|
|
92
|
+
results.push({
|
|
93
|
+
source: 'webhooks',
|
|
94
|
+
type: 'webhook_event',
|
|
95
|
+
relevance: score >= 2 ? 'high' : 'medium',
|
|
96
|
+
data: {
|
|
97
|
+
topic: event.topic,
|
|
98
|
+
description: event.description,
|
|
99
|
+
resource: event.resource,
|
|
100
|
+
required_scope: event.required_scope,
|
|
101
|
+
verification: webhooks.verification,
|
|
102
|
+
retry_policy: webhooks.retry_policy,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Skip if webhooks schema fails
|
|
110
|
+
}
|
|
111
|
+
return results;
|
|
112
|
+
}
|
|
113
|
+
function searchOAuth(tokens) {
|
|
114
|
+
const results = [];
|
|
115
|
+
try {
|
|
116
|
+
const oauth = loadOAuth();
|
|
117
|
+
const oauthText = JSON.stringify(oauth).toLowerCase();
|
|
118
|
+
const score = matchScore(tokens, oauthText);
|
|
119
|
+
if (score > 0) {
|
|
120
|
+
results.push({
|
|
121
|
+
source: 'oauth',
|
|
122
|
+
type: 'oauth',
|
|
123
|
+
relevance: score >= 2 ? 'high' : 'medium',
|
|
124
|
+
data: oauth,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Skip if oauth schema fails
|
|
130
|
+
}
|
|
131
|
+
return results;
|
|
132
|
+
}
|
|
133
|
+
export function lookupDocs(input) {
|
|
134
|
+
const { query, category } = input;
|
|
135
|
+
logger.info(`[lookup_docs] query="${query}", category="${category || 'all'}"`);
|
|
136
|
+
const tokens = tokenize(query);
|
|
137
|
+
if (tokens.length === 0) {
|
|
138
|
+
return {
|
|
139
|
+
found: false,
|
|
140
|
+
message: 'Query is too short or contains no searchable terms.',
|
|
141
|
+
suggestion: 'Try searching for specific terms like "orders", "OAuth", "webhook", "scope", etc.',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
let results = [];
|
|
145
|
+
// Search specific category or all
|
|
146
|
+
if (!category || category === 'api') {
|
|
147
|
+
results.push(...searchApiEndpoints(tokens));
|
|
148
|
+
}
|
|
149
|
+
if (!category || category === 'scopes') {
|
|
150
|
+
results.push(...searchScopes(tokens));
|
|
151
|
+
}
|
|
152
|
+
if (!category || category === 'webhooks') {
|
|
153
|
+
results.push(...searchWebhooks(tokens));
|
|
154
|
+
}
|
|
155
|
+
if (!category || category === 'oauth') {
|
|
156
|
+
results.push(...searchOAuth(tokens));
|
|
157
|
+
}
|
|
158
|
+
// Sort by relevance (high first) then deduplicate
|
|
159
|
+
results.sort((a, b) => {
|
|
160
|
+
const order = { high: 0, medium: 1, low: 2 };
|
|
161
|
+
return order[a.relevance] - order[b.relevance];
|
|
162
|
+
});
|
|
163
|
+
// Limit to top 15 results
|
|
164
|
+
results = results.slice(0, 15);
|
|
165
|
+
if (results.length === 0) {
|
|
166
|
+
return {
|
|
167
|
+
found: false,
|
|
168
|
+
query,
|
|
169
|
+
tokens,
|
|
170
|
+
message: `No documentation found matching "${query}". This information is not available in the platform documentation.`,
|
|
171
|
+
suggestion: 'Tell the user that this information is not covered in the documentation. Do NOT guess or make up an answer.',
|
|
172
|
+
available_categories: ['api', 'scopes', 'webhooks', 'oauth'],
|
|
173
|
+
available_resources: getAvailableResourceFiles(),
|
|
174
|
+
available_scope_resources: [...PRIMARY_RESOURCES],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
found: true,
|
|
179
|
+
query,
|
|
180
|
+
result_count: results.length,
|
|
181
|
+
results,
|
|
182
|
+
_instruction: 'Use ONLY the data from these results to answer the user. Do NOT add information that is not present here.',
|
|
183
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AC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACpB,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE/B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK;YACL,MAAM;YACN,OAAO,EAAE,oCAAoC,KAAK,qEAAqE;YACvH,UAAU,EAAE,6GAA6G;YACzH,oBAAoB,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC;YAC5D,mBAAmB,EAAE,yBAAyB,EAAE;YAChD,yBAAyB,EAAE,CAAC,GAAG,iBAAiB,CAAC;SAClD,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,EAAE,IAAI;QACX,KAAK;QACL,YAAY,EAAE,OAAO,CAAC,MAAM;QAC5B,OAAO;QACP,YAAY,EAAE,2GAA2G;KAC1H,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ratio-mcp/docs-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"files": [
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
7
9
|
"bin": {
|
|
8
10
|
"ratio-docs-server": "dist/index.js"
|
|
9
11
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc && cp -r src/schemas dist/schemas",
|
|
12
|
-
"dev": "node --loader ts-node/esm src/index.ts",
|
|
13
|
-
"start": "node dist/index.js",
|
|
14
|
-
"typecheck": "tsc --noEmit",
|
|
15
|
-
"prepublishOnly": "pnpm build"
|
|
16
|
-
},
|
|
17
12
|
"dependencies": {
|
|
18
13
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
14
|
+
"zod": "^3.23.0",
|
|
15
|
+
"@ratio-mcp/shared": "^1.3.0"
|
|
21
16
|
},
|
|
22
17
|
"devDependencies": {
|
|
23
18
|
"@types/node": "^20.0.0",
|
|
24
19
|
"typescript": "^5.4.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc && cp -r src/schemas dist/schemas",
|
|
23
|
+
"dev": "node --loader ts-node/esm src/index.ts",
|
|
24
|
+
"start": "node dist/index.js",
|
|
25
|
+
"typecheck": "tsc --noEmit"
|
|
25
26
|
}
|
|
26
|
-
}
|
|
27
|
+
}
|