@etsquare/mcp-server-sec 0.2.0 → 0.4.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,56 @@
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 } 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
+ /** Subset of DiscoverMetricsInput that the API v1 backend accepts. */
49
+ interface DiscoverMetricsApiInput {
50
+ question: string;
51
+ scenario?: 'snapshot' | 'trends' | 'peer_benchmark';
52
+ metric_family?: string;
53
+ max_results?: number;
54
+ }
6
55
  export interface ETSquareClientOptions {
7
56
  baseUrl: string;
8
57
  apiKey: string;
@@ -13,8 +62,17 @@ export declare class ETSquareClient {
13
62
  constructor(options: ETSquareClientOptions);
14
63
  private get headers();
15
64
  private handleResponse;
16
- search(input: SearchInput): Promise<Record<string, unknown>>;
65
+ private request;
66
+ search(input: SearchApiInput): Promise<Record<string, unknown>>;
17
67
  lookupCompany(input: LookupCompanyInput): Promise<Record<string, unknown>>;
18
- executeMetrics(input: ExecuteMetricsInput): Promise<Record<string, unknown>>;
19
- discoverMetrics(input: DiscoverMetricsInput): Promise<Record<string, unknown>>;
68
+ executeMetrics(input: ExecuteMetricsApiInput): Promise<Record<string, unknown>>;
69
+ getFinancialStatement(input: FinancialStatementApiInput): Promise<Record<string, unknown>>;
70
+ getInstitutionalHoldings(input: InstitutionalHoldingsApiInput): Promise<Record<string, unknown>>;
71
+ getInsiderTransactions(input: InsiderTransactionsApiInput): Promise<Record<string, unknown>>;
72
+ getEarningsActuals(input: EarningsActualsApiInput): Promise<Record<string, unknown>>;
73
+ discoverMetrics(input: DiscoverMetricsApiInput): Promise<Record<string, unknown>>;
74
+ getChunk(input: GetChunkInput): Promise<Record<string, unknown>>;
75
+ getChunkContext(input: GetChunkContextInput): Promise<Record<string, unknown>>;
76
+ weeklyBrief(): Promise<Record<string, unknown>>;
20
77
  }
78
+ export {};
@@ -7,6 +7,7 @@ export class ETSquareClient {
7
7
  return {
8
8
  'Content-Type': 'application/json',
9
9
  'X-API-Key': this.apiKey,
10
+ 'X-Entry-Point': 'mcp',
10
11
  };
11
12
  }
12
13
  async handleResponse(res) {
@@ -28,6 +29,17 @@ export class ETSquareClient {
28
29
  }
29
30
  return (await res.json());
30
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
+ }
31
43
  async search(input) {
32
44
  const body = {
33
45
  query: input.query,
@@ -41,23 +53,23 @@ export class ETSquareClient {
41
53
  body.tickers = input.tickers;
42
54
  if (input.sic_codes)
43
55
  body.sic_codes = input.sic_codes;
56
+ if (input.sector)
57
+ body.sector = input.sector;
44
58
  if (input.doc_types)
45
59
  body.doc_types = input.doc_types;
46
- const res = await fetch(`${this.baseUrl}/api/v1/search`, {
60
+ return this.request('/api/v1/search', {
47
61
  method: 'POST',
48
62
  headers: this.headers,
49
63
  body: JSON.stringify(body),
50
64
  });
51
- return this.handleResponse(res);
52
65
  }
53
66
  async lookupCompany(input) {
54
67
  const params = new URLSearchParams({ query: input.query });
55
68
  if (input.limit)
56
69
  params.set('limit', String(input.limit));
57
- const res = await fetch(`${this.baseUrl}/api/v1/companies/lookup?${params}`, {
70
+ return this.request(`/api/v1/companies/lookup?${params}`, {
58
71
  headers: this.headers,
59
72
  });
60
- return this.handleResponse(res);
61
73
  }
62
74
  async executeMetrics(input) {
63
75
  const body = {
@@ -66,12 +78,63 @@ export class ETSquareClient {
66
78
  };
67
79
  if (input.row_limit)
68
80
  body.row_limit = input.row_limit;
69
- 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', {
70
134
  method: 'POST',
71
135
  headers: this.headers,
72
136
  body: JSON.stringify(body),
73
137
  });
74
- return this.handleResponse(res);
75
138
  }
76
139
  async discoverMetrics(input) {
77
140
  const body = {
@@ -83,11 +146,33 @@ export class ETSquareClient {
83
146
  body.metric_family = input.metric_family;
84
147
  if (input.max_results)
85
148
  body.max_results = input.max_results;
86
- const res = await fetch(`${this.baseUrl}/api/v1/metrics/discover`, {
149
+ return this.request('/api/v1/metrics/discover', {
87
150
  method: 'POST',
88
151
  headers: this.headers,
89
152
  body: JSON.stringify(body),
90
153
  });
91
- return this.handleResponse(res);
154
+ }
155
+ async getChunk(input) {
156
+ const params = new URLSearchParams({ execution_id: input.execution_id });
157
+ return this.request(`/api/v1/chunk/${input.chunk_id}?${params}`, {
158
+ headers: this.headers,
159
+ });
160
+ }
161
+ async getChunkContext(input) {
162
+ const params = new URLSearchParams();
163
+ if (input.neighbor_span !== undefined)
164
+ params.set('neighbor_span', String(input.neighbor_span));
165
+ if (input.window !== undefined)
166
+ params.set('window', String(input.window));
167
+ const query = params.toString();
168
+ const suffix = query ? `?${query}` : '';
169
+ return this.request(`/api/v1/chunks/${input.chunk_id}/context${suffix}`, {
170
+ headers: this.headers,
171
+ });
172
+ }
173
+ async weeklyBrief() {
174
+ return this.request('/api/sec-intelligence/weekly-brief', {
175
+ headers: this.headers,
176
+ });
92
177
  }
93
178
  }