@etsquare/mcp-server-sec 0.2.1 → 0.5.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.
@@ -2,7 +2,64 @@
2
2
  * ETSquare SEC Intelligence API client.
3
3
  * Wraps /api/v1/* endpoints with X-API-Key authentication.
4
4
  */
5
- import type { SearchInput, LookupCompanyInput, ExecuteMetricsInput, DiscoverMetricsInput, GetChunkInput, GetChunkContextInput } from './types.js';
5
+ import type { LookupCompanyInput, GetChunkInput, GetChunkContextInput } from './types.js';
6
+ /** Subset of SearchInput that the API v1 backend accepts (no MCP-layer fields). */
7
+ interface SearchApiInput {
8
+ query: string;
9
+ mode_lock: 'NARRATIVE' | 'HYBRID';
10
+ scope_lock: 'COMPANY' | 'INDUSTRY' | 'MACRO';
11
+ top_k?: number;
12
+ tickers?: string[];
13
+ sic_codes?: string[];
14
+ sector?: string;
15
+ doc_types?: string[];
16
+ }
17
+ /** Subset of ExecuteMetricsInput that the API v1 backend accepts. */
18
+ interface ExecuteMetricsApiInput {
19
+ template_id: string;
20
+ bind_params?: Record<string, unknown>;
21
+ row_limit?: number;
22
+ }
23
+ /** Financial statement request. */
24
+ interface FinancialStatementApiInput {
25
+ ticker: string;
26
+ statement_type: 'income_statement' | 'balance_sheet' | 'cash_flow';
27
+ period_mode?: 'latest_annual' | 'latest_quarterly' | 'last_n_annual' | 'last_n_quarterly';
28
+ n_periods?: number;
29
+ }
30
+ /** Institutional holdings request. */
31
+ interface InstitutionalHoldingsApiInput {
32
+ ticker: string;
33
+ quarters?: number;
34
+ }
35
+ /** Insider transactions request. */
36
+ interface InsiderTransactionsApiInput {
37
+ ticker: string;
38
+ days_back?: number;
39
+ transaction_types?: string[];
40
+ include_derivatives?: boolean;
41
+ }
42
+ /** Earnings actuals & guidance request. */
43
+ interface EarningsActualsApiInput {
44
+ ticker: string;
45
+ quarters?: number;
46
+ metrics?: string[];
47
+ }
48
+ /** Stored KPI extractions request. */
49
+ interface KpiExtractionsApiInput {
50
+ ticker?: string;
51
+ sector?: string;
52
+ sic_code?: string;
53
+ fiscal_year?: number;
54
+ limit?: number;
55
+ }
56
+ /** Subset of DiscoverMetricsInput that the API v1 backend accepts. */
57
+ interface DiscoverMetricsApiInput {
58
+ question: string;
59
+ scenario?: 'snapshot' | 'trends' | 'peer_benchmark';
60
+ metric_family?: string;
61
+ max_results?: number;
62
+ }
6
63
  export interface ETSquareClientOptions {
7
64
  baseUrl: string;
8
65
  apiKey: string;
@@ -13,10 +70,18 @@ export declare class ETSquareClient {
13
70
  constructor(options: ETSquareClientOptions);
14
71
  private get headers();
15
72
  private handleResponse;
16
- search(input: SearchInput): Promise<Record<string, unknown>>;
73
+ private request;
74
+ search(input: SearchApiInput): Promise<Record<string, unknown>>;
17
75
  lookupCompany(input: LookupCompanyInput): Promise<Record<string, unknown>>;
18
- executeMetrics(input: ExecuteMetricsInput): Promise<Record<string, unknown>>;
19
- discoverMetrics(input: DiscoverMetricsInput): Promise<Record<string, unknown>>;
76
+ executeMetrics(input: ExecuteMetricsApiInput): Promise<Record<string, unknown>>;
77
+ getFinancialStatement(input: FinancialStatementApiInput): Promise<Record<string, unknown>>;
78
+ getInstitutionalHoldings(input: InstitutionalHoldingsApiInput): Promise<Record<string, unknown>>;
79
+ getInsiderTransactions(input: InsiderTransactionsApiInput): Promise<Record<string, unknown>>;
80
+ getEarningsActuals(input: EarningsActualsApiInput): Promise<Record<string, unknown>>;
81
+ getKpiExtractions(input: KpiExtractionsApiInput): Promise<Record<string, unknown>>;
82
+ discoverMetrics(input: DiscoverMetricsApiInput): Promise<Record<string, unknown>>;
20
83
  getChunk(input: GetChunkInput): Promise<Record<string, unknown>>;
21
84
  getChunkContext(input: GetChunkContextInput): Promise<Record<string, unknown>>;
85
+ weeklyBrief(): Promise<Record<string, unknown>>;
22
86
  }
87
+ export {};
@@ -29,6 +29,17 @@ export class ETSquareClient {
29
29
  }
30
30
  return (await res.json());
31
31
  }
32
+ async request(path, init) {
33
+ const url = `${this.baseUrl}${path}`;
34
+ try {
35
+ const res = await fetch(url, init);
36
+ return this.handleResponse(res);
37
+ }
38
+ catch (error) {
39
+ const message = error instanceof Error ? error.message : 'Unknown error';
40
+ throw new Error(`ETSquare API fetch failed (${url}): ${message}`);
41
+ }
42
+ }
32
43
  async search(input) {
33
44
  const body = {
34
45
  query: input.query,
@@ -42,23 +53,23 @@ export class ETSquareClient {
42
53
  body.tickers = input.tickers;
43
54
  if (input.sic_codes)
44
55
  body.sic_codes = input.sic_codes;
56
+ if (input.sector)
57
+ body.sector = input.sector;
45
58
  if (input.doc_types)
46
59
  body.doc_types = input.doc_types;
47
- const res = await fetch(`${this.baseUrl}/api/v1/search`, {
60
+ return this.request('/api/v1/search', {
48
61
  method: 'POST',
49
62
  headers: this.headers,
50
63
  body: JSON.stringify(body),
51
64
  });
52
- return this.handleResponse(res);
53
65
  }
54
66
  async lookupCompany(input) {
55
67
  const params = new URLSearchParams({ query: input.query });
56
68
  if (input.limit)
57
69
  params.set('limit', String(input.limit));
58
- const res = await fetch(`${this.baseUrl}/api/v1/companies/lookup?${params}`, {
70
+ return this.request(`/api/v1/companies/lookup?${params}`, {
59
71
  headers: this.headers,
60
72
  });
61
- return this.handleResponse(res);
62
73
  }
63
74
  async executeMetrics(input) {
64
75
  const body = {
@@ -67,12 +78,81 @@ export class ETSquareClient {
67
78
  };
68
79
  if (input.row_limit)
69
80
  body.row_limit = input.row_limit;
70
- const res = await fetch(`${this.baseUrl}/api/v1/metrics/execute`, {
81
+ return this.request('/api/v1/metrics/execute', {
82
+ method: 'POST',
83
+ headers: this.headers,
84
+ body: JSON.stringify(body),
85
+ });
86
+ }
87
+ async getFinancialStatement(input) {
88
+ const body = {
89
+ ticker: input.ticker,
90
+ statement_type: input.statement_type,
91
+ period_mode: input.period_mode || 'last_n_annual',
92
+ n_periods: input.n_periods || 5,
93
+ };
94
+ return this.request('/api/v1/financials', {
95
+ method: 'POST',
96
+ headers: this.headers,
97
+ body: JSON.stringify(body),
98
+ });
99
+ }
100
+ async getInstitutionalHoldings(input) {
101
+ const body = {
102
+ ticker: input.ticker,
103
+ quarters: input.quarters || 2,
104
+ };
105
+ return this.request('/api/v1/institutional/holdings', {
106
+ method: 'POST',
107
+ headers: this.headers,
108
+ body: JSON.stringify(body),
109
+ });
110
+ }
111
+ async getInsiderTransactions(input) {
112
+ const body = {
113
+ ticker: input.ticker,
114
+ days_back: input.days_back || 90,
115
+ };
116
+ if (input.transaction_types)
117
+ body.transaction_types = input.transaction_types;
118
+ if (input.include_derivatives !== undefined)
119
+ body.include_derivatives = input.include_derivatives;
120
+ return this.request('/api/v1/insider/transactions', {
121
+ method: 'POST',
122
+ headers: this.headers,
123
+ body: JSON.stringify(body),
124
+ });
125
+ }
126
+ async getEarningsActuals(input) {
127
+ const body = {
128
+ ticker: input.ticker,
129
+ quarters: input.quarters || 4,
130
+ };
131
+ if (input.metrics)
132
+ body.metrics = input.metrics;
133
+ return this.request('/api/v1/earnings/actuals', {
134
+ method: 'POST',
135
+ headers: this.headers,
136
+ body: JSON.stringify(body),
137
+ });
138
+ }
139
+ async getKpiExtractions(input) {
140
+ const body = {
141
+ limit: input.limit || 50,
142
+ };
143
+ if (input.ticker)
144
+ body.ticker = input.ticker;
145
+ if (input.sector)
146
+ body.sector = input.sector;
147
+ if (input.sic_code)
148
+ body.sic_code = input.sic_code;
149
+ if (input.fiscal_year !== undefined)
150
+ body.fiscal_year = input.fiscal_year;
151
+ return this.request('/api/v1/kpis', {
71
152
  method: 'POST',
72
153
  headers: this.headers,
73
154
  body: JSON.stringify(body),
74
155
  });
75
- return this.handleResponse(res);
76
156
  }
77
157
  async discoverMetrics(input) {
78
158
  const body = {
@@ -84,19 +164,17 @@ export class ETSquareClient {
84
164
  body.metric_family = input.metric_family;
85
165
  if (input.max_results)
86
166
  body.max_results = input.max_results;
87
- const res = await fetch(`${this.baseUrl}/api/v1/metrics/discover`, {
167
+ return this.request('/api/v1/metrics/discover', {
88
168
  method: 'POST',
89
169
  headers: this.headers,
90
170
  body: JSON.stringify(body),
91
171
  });
92
- return this.handleResponse(res);
93
172
  }
94
173
  async getChunk(input) {
95
174
  const params = new URLSearchParams({ execution_id: input.execution_id });
96
- const res = await fetch(`${this.baseUrl}/api/v1/chunk/${input.chunk_id}?${params}`, {
175
+ return this.request(`/api/v1/chunk/${input.chunk_id}?${params}`, {
97
176
  headers: this.headers,
98
177
  });
99
- return this.handleResponse(res);
100
178
  }
101
179
  async getChunkContext(input) {
102
180
  const params = new URLSearchParams();
@@ -106,9 +184,13 @@ export class ETSquareClient {
106
184
  params.set('window', String(input.window));
107
185
  const query = params.toString();
108
186
  const suffix = query ? `?${query}` : '';
109
- const res = await fetch(`${this.baseUrl}/api/v1/chunks/${input.chunk_id}/context${suffix}`, {
187
+ return this.request(`/api/v1/chunks/${input.chunk_id}/context${suffix}`, {
188
+ headers: this.headers,
189
+ });
190
+ }
191
+ async weeklyBrief() {
192
+ return this.request('/api/sec-intelligence/weekly-brief', {
110
193
  headers: this.headers,
111
194
  });
112
- return this.handleResponse(res);
113
195
  }
114
196
  }