Skip to content

Commit c89774b

Browse files
committed
feat(tools): change truncation logic in get_filing_content
1 parent e137595 commit c89774b

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

sec_edgar_mcp/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,20 @@ def get_recent_filings(identifier: str = None, form_type: str = None, days: int
122122
return filings_tools.get_recent_filings(identifier, form_type, days, limit)
123123

124124

125-
def get_filing_content(identifier: str, accession_number: str):
125+
def get_filing_content(identifier: str, accession_number: str, offset: int = 0, max_chars: int = 50000):
126126
"""
127-
Get the content of a specific SEC filing.
127+
Get the content of a specific SEC filing with paging support.
128128
129129
Args:
130130
identifier: Company ticker symbol or CIK number
131131
accession_number: The accession number of the filing
132+
offset: Character offset into the filing content (default: 0)
133+
max_chars: Maximum number of characters to return (default: 50000)
132134
133135
Returns:
134-
Dictionary containing filing content and metadata
136+
Dictionary containing filing content page and pagination metadata
135137
"""
136-
return filings_tools.get_filing_content(identifier, accession_number)
138+
return filings_tools.get_filing_content(identifier, accession_number, offset, max_chars)
137139

138140

139141
def analyze_8k(identifier: str, accession_number: str):

sec_edgar_mcp/tools/filings.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ def get_recent_filings(
6565
except Exception as e:
6666
return {"success": False, "error": f"Failed to get recent filings: {str(e)}"}
6767

68-
def get_filing_content(self, identifier: str, accession_number: str) -> ToolResponse:
69-
"""Get the content of a specific filing."""
68+
def get_filing_content(
69+
self,
70+
identifier: str,
71+
accession_number: str,
72+
offset: int = 0,
73+
max_chars: int = 50000,
74+
) -> ToolResponse:
75+
"""Get filing content with paging support."""
7076
try:
7177
company = self.client.get_company(identifier)
7278

@@ -80,34 +86,32 @@ def get_filing_content(self, identifier: str, accession_number: str) -> ToolResp
8086
if not filing:
8187
raise FilingNotFoundError(f"Filing {accession_number} not found")
8288

83-
# Get filing content
8489
content = filing.text()
90+
total_chars = len(content)
91+
92+
safe_offset = max(0, int(offset))
93+
safe_max_chars = int(max_chars) if max_chars and int(max_chars) > 0 else 50000
94+
95+
page_end = min(safe_offset + safe_max_chars, total_chars)
96+
if safe_offset >= total_chars:
97+
page_content = ""
98+
page_end = total_chars
99+
else:
100+
page_content = content[safe_offset:page_end]
85101

86-
# For structured filings, get the data object
87-
filing_data = {}
88-
try:
89-
obj = filing.obj()
90-
if obj:
91-
# Extract key information based on filing type
92-
if filing.form == "8-K" and hasattr(obj, "items"):
93-
filing_data["items"] = obj.items
94-
filing_data["has_press_release"] = getattr(obj, "has_press_release", False)
95-
elif filing.form in ["10-K", "10-Q"]:
96-
filing_data["has_financials"] = True
97-
elif filing.form in ["3", "4", "5"]:
98-
filing_data["is_ownership"] = True
99-
except Exception:
100-
pass
102+
next_offset = page_end if page_end < total_chars else None
101103

102104
return {
103105
"success": True,
104106
"accession_number": filing.accession_number,
105107
"form_type": filing.form,
106108
"filing_date": filing.filing_date.isoformat(),
107-
"content": content[:50000] if len(content) > 50000 else content, # Limit size
108-
"content_truncated": len(content) > 50000,
109-
"filing_data": filing_data,
109+
"content": page_content,
110110
"url": filing.url,
111+
"offset": safe_offset,
112+
"returned_chars": len(page_content),
113+
"total_chars": total_chars,
114+
"next_offset": next_offset,
111115
}
112116
except FilingNotFoundError as e:
113117
return {"success": False, "error": str(e)}

0 commit comments

Comments
 (0)