fetch_railway_docs_optimized
Retrieve the latest Railway CLI documentation directly within Cursor IDE. Optionally, specify a custom URL for tailored content access.
Instructions
Fetches the most recent Railway CLI documentation. Optionally, provide a custom URL.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Optional custom URL for fetching Railway CLI docs. |
Implementation Reference
- mcp_hitchcode/server.py:108-184 (handler)The core handler function that executes the tool: fetches the Railway CLI documentation page, parses it with BeautifulSoup to intelligently extract CLI command sections (under headings like 'command', 'cli', 'usage') and relevant code blocks, and returns an optimized text summary.async def fetch_railway_docs_optimized( url: str = "https://docs.railway.app/guides/cli", ) -> list[types.TextContent]: headers = { "User-Agent": "MCP Railway Docs Fetcher (github.com/modelcontextprotocol/python-sdk)" } try: timeout = httpx.Timeout(10.0, connect=5.0) async with httpx.AsyncClient( follow_redirects=True, headers=headers, timeout=timeout ) as client: response = await client.get(url) response.raise_for_status() # Parse HTML content soup = BeautifulSoup(response.text, "html.parser") content = [] # Try to find any command sections for heading in soup.find_all(["h1", "h2", "h3", "h4"]): heading_text = heading.get_text(strip=True).lower() if any( keyword in heading_text for keyword in ["command", "cli", "usage"] ): # Look for the next element that might contain commands next_elem = heading.find_next_sibling() while next_elem and next_elem.name not in [ "ul", "ol", "h1", "h2", "h3", "h4", ]: next_elem = next_elem.find_next_sibling() if next_elem and next_elem.name in ["ul", "ol"]: commands = [] for li in next_elem.find_all("li"): cmd_text = li.get_text(strip=True) if cmd_text: # Only add non-empty commands commands.append(cmd_text) if commands: # Only add sections that have commands content.append(f"\n{heading.get_text(strip=True)}:") content.extend(f"- {cmd}" for cmd in commands) if content: return [types.TextContent(type="text", text="\n".join(content))] # If we couldn't find any command sections, try to extract any code blocks code_blocks = soup.find_all(["pre", "code"]) if code_blocks: content = ["Railway CLI Commands:"] for block in code_blocks: code_text = block.get_text(strip=True) if code_text and any( keyword in code_text.lower() for keyword in ["railway", "cli"] ): content.append(code_text) return [types.TextContent(type="text", text="\n".join(content))] # If still nothing found, return a more helpful message return [ types.TextContent( type="text", text="Could not find any CLI commands in the documentation. The page structure might have changed.", ) ] except Exception as e: return [ types.TextContent( type="text", text=f"Error: Failed to fetch or parse Railway CLI docs: {str(e)}", ) ]
- mcp_hitchcode/server.py:602-614 (registration)Tool registration in the server's list_tools() method, defining the tool's name, description, and input schema.types.Tool( name="fetch_railway_docs_optimized", description="Fetches the most recent Railway CLI documentation. Optionally, provide a custom URL.", inputSchema={ "type": "object", "properties": { "url": { "type": "string", "description": "Optional custom URL for fetching Railway CLI docs.", }, }, }, ),
- mcp_hitchcode/server.py:605-613 (schema)Input schema definition for the tool, specifying an optional 'url' parameter of type string.inputSchema={ "type": "object", "properties": { "url": { "type": "string", "description": "Optional custom URL for fetching Railway CLI docs.", }, }, },
- mcp_hitchcode/server.py:436-438 (helper)Routing logic in the generic fetch_tool handler that dispatches calls to the specific fetch_railway_docs_optimized implementation.if name == "fetch_railway_docs_optimized": url = arguments.get("url", "https://docs.railway.app/guides/cli") return await fetch_railway_docs_optimized(url)