canli-validation-mcp 0.1.2 → 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/README.md +10 -0
- package/package.json +1 -1
- package/src/schemas.mjs +14 -0
- package/src/server.mjs +77 -0
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ repository for the full design.
|
|
|
36
36
|
| `validate_breadth` | `POST /api/v1/validate/breadth` | yes |
|
|
37
37
|
| `get_receipt` | `GET /api/v1/receipts/{id}` | no |
|
|
38
38
|
| `service_status` | `GET /api/v1/validate/status` | no |
|
|
39
|
+
| `company_financial_history` | `GET /company-data/{cik}.json` | no |
|
|
39
40
|
|
|
40
41
|
`validate_deflated_sharpe` accepts exactly one of two input shapes, never a mix of both:
|
|
41
42
|
|
|
@@ -48,6 +49,15 @@ repository for the full design.
|
|
|
48
49
|
Sending fields from both shapes, or from neither, is rejected before any request leaves the
|
|
49
50
|
process; see `src/schemas.mjs`.
|
|
50
51
|
|
|
52
|
+
`company_financial_history` is different from the other tools: it reads the public company
|
|
53
|
+
reference at canlicapital.com, not the validation API. Give it a CIK (1 to 10 digits) to list a
|
|
54
|
+
company's available financial histories, or a CIK and a us-gaap concept such as `Revenues` to
|
|
55
|
+
get the observations, newest first (`limit` defaults to 40, maximum 200). Every observation
|
|
56
|
+
keeps its filing accession, form, filed date and unit, and the result carries the SHA-256 of the
|
|
57
|
+
original SEC response and the record's own boundary sentence: these are accounting values as
|
|
58
|
+
reported to the SEC, not market prices, returns or a recommendation. Companies and concepts
|
|
59
|
+
outside the current release return an error with the available concepts listed.
|
|
60
|
+
|
|
51
61
|
## Configuration
|
|
52
62
|
|
|
53
63
|
| Variable | Default | Meaning |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canli-validation-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for canlicapital.com's free validation API: deflated Sharpe, CSCV overfitting, paper-evidence conformance, and breadth ceiling, each returned as the full API envelope so the boundary language cannot be dropped.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
package/src/schemas.mjs
CHANGED
|
@@ -110,6 +110,19 @@ export const getReceiptInput = z
|
|
|
110
110
|
|
|
111
111
|
export const emptyInput = z.object({}).strict();
|
|
112
112
|
|
|
113
|
+
// company_financial_history reads the public company reference, not the validation API.
|
|
114
|
+
export const companyHistoryInput = z
|
|
115
|
+
.object({
|
|
116
|
+
cik: z.string().regex(/^\d{1,10}$/, "A CIK is 1 to 10 digits"),
|
|
117
|
+
concept: z.string().regex(/^[A-Za-z][A-Za-z0-9]{0,99}$/, "A concept is a us-gaap tag such as Revenues or Assets").optional(),
|
|
118
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
119
|
+
})
|
|
120
|
+
.strict();
|
|
121
|
+
|
|
122
|
+
// The company reference carries its own boundary sentence in every record (claim_boundary),
|
|
123
|
+
// written by scripts/lib/company-reference.mjs. A test pins this copy to that source verbatim.
|
|
124
|
+
export const COMPANY_REFERENCE_BOUNDARY = "Public company accounting reference, not market prices, returns, an investment recommendation, or ALPHAC performance. Validate a separately constructed return series with the validation API; accounting values are not returns.";
|
|
125
|
+
|
|
113
126
|
// ---------------------------------------------------------------------------------------------
|
|
114
127
|
// Boundary language: verbatim sentences from api/_lib/limits.js LIMITS_TEXT. A test asserts each
|
|
115
128
|
// of these strings is still present, byte for byte, in that source array, so this module cannot
|
|
@@ -141,4 +154,5 @@ export const TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
141
154
|
validate_breadth: `Book Sharpe ceiling from per-sleeve quality and average pairwise correlation, and the sleeves a target needs. ${LIMITS_SENTENCES.scope}`,
|
|
142
155
|
get_receipt: `Fetch a stored verdict by its content-hash id (GET /api/v1/receipts/{id}), immutable and cacheable. ${LIMITS_SENTENCES.unsigned}`,
|
|
143
156
|
service_status: `Service, store and quota constants for the validation API (GET /api/v1/validate/status); no key required. ${LIMITS_SENTENCES.scope}`,
|
|
157
|
+
company_financial_history: `SEC-reported financial history for one company from the canlicapital.com company reference (GET /company-data/{cik}.json). Without a concept it lists the available histories; with one it returns observations, newest first, each with its filing accession, form, filed date and unit, plus the SHA-256 of the original SEC response. No key required. ${COMPANY_REFERENCE_BOUNDARY}`,
|
|
144
158
|
});
|
package/src/server.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
12
12
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
13
|
import {
|
|
14
14
|
breadthInput,
|
|
15
|
+
companyHistoryInput,
|
|
15
16
|
deflatedSharpeInput,
|
|
16
17
|
deflatedSharpeToolShape,
|
|
17
18
|
emptyInput,
|
|
@@ -132,6 +133,77 @@ export async function toolServiceStatus(session) {
|
|
|
132
133
|
return asText(response.envelope, response.failed);
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
// The company reference is a public data file, not an API envelope. The result keeps every
|
|
137
|
+
// field that says where a value came from (accession, form, filed date, unit, source hash) and
|
|
138
|
+
// the record's own claim_boundary and policy sentences, so an agent cannot quote a number
|
|
139
|
+
// without its provenance or boundary.
|
|
140
|
+
export async function toolCompanyFinancialHistory(session, args) {
|
|
141
|
+
const { cik, concept, limit = 40 } = parseOrThrow(companyHistoryInput, args, "company_financial_history");
|
|
142
|
+
const id = cik.padStart(10, "0");
|
|
143
|
+
const path = `/company-data/${id}.json`;
|
|
144
|
+
const signal = AbortSignal.timeout(session.timeoutMs);
|
|
145
|
+
let res, text;
|
|
146
|
+
try {
|
|
147
|
+
res = await session.fetchImpl(`${session.base}${path}`, { headers: { Accept: "application/json" }, signal, redirect: "error" });
|
|
148
|
+
text = await res.text();
|
|
149
|
+
} catch {
|
|
150
|
+
throw new Error(signal.aborted
|
|
151
|
+
? `${path} exceeded the request deadline; no automatic retry was sent.`
|
|
152
|
+
: `${path} could not be reached or read. Check the API base and service status; no automatic retry was sent.`);
|
|
153
|
+
}
|
|
154
|
+
if (res.status === 404) return asText({ error: { code: "not_found", message: `No company record for CIK ${id} in the current company reference release.` }, page: `${session.base}/companies` }, true);
|
|
155
|
+
if (res.status >= 400) return asText({ error: { code: "unavailable", message: `${path} returned status ${res.status}.` } }, true);
|
|
156
|
+
let record;
|
|
157
|
+
try {
|
|
158
|
+
record = JSON.parse(text);
|
|
159
|
+
} catch {
|
|
160
|
+
throw new Error(`${path} returned a non-JSON body (status ${res.status}). Response body omitted.`);
|
|
161
|
+
}
|
|
162
|
+
if (record?.schema !== "canli.company-reference.v1" || record.cik !== id || !Array.isArray(record.concepts) || typeof record.claim_boundary !== "string") {
|
|
163
|
+
return asText({ error: { code: "unexpected_record", message: `${path} did not return a canli.company-reference.v1 record for CIK ${id}.` } }, true);
|
|
164
|
+
}
|
|
165
|
+
const base = {
|
|
166
|
+
schema: "canli.mcp.company-history.v1",
|
|
167
|
+
company: { cik: record.cik, name: record.name },
|
|
168
|
+
claim_boundary: record.claim_boundary,
|
|
169
|
+
policy: record.policy,
|
|
170
|
+
source: {
|
|
171
|
+
sec_response_url: record.source_url,
|
|
172
|
+
sec_response_sha256: record.source_sha256,
|
|
173
|
+
snapshot: record.source_snapshot ? `${session.base}${record.source_snapshot}` : null,
|
|
174
|
+
fetched_at: record.fetched_at,
|
|
175
|
+
record: `${session.base}${path}`,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
if (concept === undefined) {
|
|
179
|
+
return asText({
|
|
180
|
+
...base,
|
|
181
|
+
page: `${session.base}/companies/${id}`,
|
|
182
|
+
histories: record.concepts.map((c) => ({ concept: c.tag, label: c.label, kind: c.kind, observations: c.observations?.length ?? 0, page: `${session.base}/companies/${id}/${c.tag}` })),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const history = record.concepts.find((c) => c.tag === concept);
|
|
186
|
+
if (!history) {
|
|
187
|
+
return asText({ ...base, error: { code: "concept_not_found", message: `${record.name} has no ${concept} history in this release.`, available: record.concepts.map((c) => c.tag) } }, true);
|
|
188
|
+
}
|
|
189
|
+
const observations = [...(history.observations ?? [])].sort((a, b) => String(b.end).localeCompare(String(a.end))).slice(0, limit);
|
|
190
|
+
return asText({
|
|
191
|
+
...base,
|
|
192
|
+
page: `${session.base}/companies/${id}/${history.tag}`,
|
|
193
|
+
history: {
|
|
194
|
+
concept: history.tag,
|
|
195
|
+
taxonomy: history.taxonomy,
|
|
196
|
+
label: history.label,
|
|
197
|
+
kind: history.kind,
|
|
198
|
+
meaning: history.meaning,
|
|
199
|
+
units: [...new Set((history.observations ?? []).map((o) => o.unit))],
|
|
200
|
+
total_observations: history.observations?.length ?? 0,
|
|
201
|
+
returned: observations.length,
|
|
202
|
+
observations,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
135
207
|
export function registerTools(server, session) {
|
|
136
208
|
server.registerTool(
|
|
137
209
|
"get_key",
|
|
@@ -168,6 +240,11 @@ export function registerTools(server, session) {
|
|
|
168
240
|
{ title: "Service status", description: TOOL_DESCRIPTIONS.service_status, inputSchema: emptyInput },
|
|
169
241
|
() => toolServiceStatus(session),
|
|
170
242
|
);
|
|
243
|
+
server.registerTool(
|
|
244
|
+
"company_financial_history",
|
|
245
|
+
{ title: "Company financial history (SEC)", description: TOOL_DESCRIPTIONS.company_financial_history, inputSchema: companyHistoryInput },
|
|
246
|
+
(args) => toolCompanyFinancialHistory(session, args),
|
|
247
|
+
);
|
|
171
248
|
}
|
|
172
249
|
|
|
173
250
|
export function createServer(session = createSession()) {
|