File Export
Relevant source files
The following files were used as context for generating this wiki page:
File Export is a core capability within the Sequential Thinking MCP v2 server that allows users to persist and share structured reasoning data. It enables the extraction of session details, thoughts, and memories into portable formats for documentation, auditing, or further analysis.
The system specifically saves these files exclusively within the memory-bank directory to maintain project context and ensure that all framework-generated artifacts remain localized.
Sources: memory-bank/sessions/b52d69d0-cd30-46a8-8420-543c492b46f9.md, mcp_tools.py:164-165
Export Architecture and Workflow
The export functionality operates through the MCPToolsHandler, which acts as the interface layer. It validates user input and coordinates with the UnifiedSessionManager to retrieve the necessary data before writing to the filesystem.
Data Flow
The following diagram illustrates the sequence of events when a user invokes the export tool.
This sequence ensures that data is consistently formatted and stored within the designated repository boundaries.
Sources: mcp_tools.py:149-183, tests/test_integration.py:126-150
Export Configuration and Parameters
The export_session tool accepts several parameters to control the scope and format of the output.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
filename | string | (Required) | The name of the file to be created within the memory-bank directory. |
format | string | "markdown" | The output file format. Supported values: markdown, json. |
export_type | string | "session" | The scope of the export. Supported values: session (full session history) or memories (filtered memory list). |
tags | string | "" | Comma-separated tags used to filter content when export_type is set to "memories". |
Sources: mcp_tools.py:149-155, tests/test_mcp_tools.py:192-197
Implementation Details
Format Handling
The system supports two primary formats:
- Markdown: Generates a human-readable document featuring H1 titles, H2 sections for thoughts and memories, and code blocks for snippets.
- JSON: Provides a structured data representation suitable for programmatic ingestion, containing serialized IDs, timestamps, and raw content.
Content Generation
The MCPToolsHandler uses private methods to assemble the export content based on the selected format.
# From mcp_tools.py:207-227
def _export_session_content(self, format: str) -> str:
session = self.session_manager.current_session
if not session:
return "No active session"
if format == "json":
return json.dumps({
"session_id": session.id,
"problem": session.problem,
"thoughts": [{"id": t.id, "content": t.content} for t in session.thoughts],
# ... additional fields
}, indent=2)
else:
return f"# {session.problem}\n\n**Session ID:** {session.id}\n..."
Sources: mcp_tools.py:207-248, tests/test_integration.py:276-302
Constraints and Security
The export system enforces specific constraints to maintain data integrity:
- Active Session Requirement: Exporting is only permitted when an active session is loaded in the
UnifiedSessionManager. - Directory Isolation: All exports are prefixed with the
memory_bank_path(typicallymemory-bank/) to prevent unauthorized file writes outside the project structure. - Validation: Filenames cannot be empty, and formats must be explicitly supported.
Sources: mcp_tools.py:157-165, session_manager.py:29-33
Conclusion
The File Export feature provides a robust mechanism for extracting reasoning artifacts from the MCP server. By strictly adhering to the memory-bank directory structure and supporting both Markdown and JSON, it ensures that project documentation is both portable and consistent with the framework's architecture.
Sources: memory-bank/sessions/b52d69d0-cd30-46a8-8420-543c492b46f9.md, mcp_tools.py:179-183