json_skeleton
Generate compact JSON skeletons by preserving structure, truncating string values, and deduplicating arrays to analyze large JSON files without exceeding size limits.
Instructions
Create a lightweight JSON skeleton that preserves structure with truncated values and deduplicated arrays. Useful when encountering 'File content exceeds maximum allowed size' errors with large JSON files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the JSON file to process | |
| max_length | No | Maximum length for string values (default: 200) | |
| type_only | No | Return only value types instead of values. Most compact output. (default: false) |
Implementation Reference
- Core handler function that reads the JSON file, applies skeleton generation logic (truncation, deduplication, type-only mode), and returns the processed skeleton.def process_file(self, file_path: str, max_length: int = None, type_only: bool = False) -> Dict[str, Any]: """Process a JSON file and return skeleton.""" # Update max_length if provided if max_length is not None: self.max_value_length = max_length # Set type_only mode self.type_only_mode = type_only path = Path(file_path) if not path.exists(): raise FileNotFoundError(f"File not found: {file_path}") if not path.is_file(): raise ValueError(f"Path is not a file: {file_path}") try: with open(path, 'r', encoding='utf-8') as f: data = json.load(f) except json.JSONDecodeError as e: raise ValueError(f"Invalid JSON file: {e}") except Exception as e: raise Exception(f"Error reading file: {e}") skeleton = self.create_skeleton(data) return { "file_path": str(path.absolute()), "file_size": path.stat().st_size, "skeleton": skeleton }
- src/json_skeleton/server.py:30-49 (schema)Input schema defining parameters for the json_skeleton tool: file_path (required), optional max_length and type_only.inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the JSON file to process" }, "max_length": { "type": "integer", "description": "Maximum length for string values (default: 200)", "default": 200 }, "type_only": { "type": "boolean", "description": "Return only value types instead of values. Most compact output. (default: false)", "default": False } }, "required": ["file_path"] }
- src/json_skeleton/server.py:24-51 (registration)Registration of the json_skeleton tool in the MCP server's list_tools method, including name, description, and schema.async def list_tools() -> list[Tool]: """List available tools.""" return [ Tool( name="json_skeleton", description="Create a lightweight JSON skeleton that preserves structure with truncated values and deduplicated arrays. Useful when encountering 'File content exceeds maximum allowed size' errors with large JSON files.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the JSON file to process" }, "max_length": { "type": "integer", "description": "Maximum length for string values (default: 200)", "default": 200 }, "type_only": { "type": "boolean", "description": "Return only value types instead of values. Most compact output. (default: false)", "default": False } }, "required": ["file_path"] } ) ]
- src/json_skeleton/server.py:58-71 (handler)MCP server call_tool dispatch for json_skeleton: extracts arguments, calls SkeletonGenerator.process_file, formats and returns the skeleton as TextContent.if name == "json_skeleton": file_path = arguments.get("file_path") if not file_path: return [TextContent(type="text", text="Error: file_path is required")] max_length = arguments.get("max_length", 200) type_only = arguments.get("type_only", False) result = skeleton_generator.process_file(file_path, max_length=max_length, type_only=type_only) # Format the output - just the skeleton output = json.dumps(result['skeleton'], indent=2, ensure_ascii=False) return [TextContent(type="text", text=output)]