-
Notifications
You must be signed in to change notification settings - Fork 4
Gopher Protocol
Understanding the Gopher protocol and how it's implemented in the MCP server.
The Gopher protocol is a TCP-based document retrieval protocol designed in 1991 at the University of Minnesota. It predates the World Wide Web and provides a simple, hierarchical menu-based interface for accessing documents and services.
- Protocol: TCP
- Default Port: 70
- Encryption: None (standard Gopher)
<selector><TAB><search><CR><LF>
- Selector: Path to the resource
- Search: Optional search query (for type 7)
- CR LF: Carriage return and line feed
Gopher servers return raw data without headers. The format depends on the item type.
| Type | Description | Example |
|---|---|---|
| 0 | Text file | Plain text documents |
| 1 | Directory/Menu | Hierarchical menus |
| 2 | CSO phone book | Name server |
| 3 | Error | Error message |
| 4 | BinHex file | Macintosh file |
| 5 | DOS binary | PC binary file |
| 6 | UUEncoded file | Unix file |
| 7 | Search server | Full-text search |
| 8 | Telnet session | Telnet link |
| 9 | Binary file | Generic binary |
| g | GIF image | GIF file |
| I | Image file | Other image |
| h | HTML file | HTML document |
| i | Info line | Non-selectable text |
| s | Sound file | Audio file |
Gopher menus (type 1) use a specific line format:
<type><display text><TAB><selector><TAB><host><TAB><port><CR><LF>
Example:
0Welcome Text /welcome.txt gopher.example.com 70
1Subdirectory /subdir gopher.example.com 70
iInformation line fake null 0
Gopher URLs follow this format:
gopher://<host>[:<port>]/<type><selector>[?<search>]
Examples:
gopher://gopher.floodgap.com/1/
gopher://gopher.floodgap.com:70/0/gopher/welcome
gopher://gopher.floodgap.com/7/v2/vs?python
- Menu Browsing (type 1): Full menu parsing and navigation
- Text Files (type 0): Complete text file retrieval
- Search (type 7): Search server support with queries
- Binary Metadata (types 4, 5, 6, 9, g, I): Metadata without download
The server parses Gopher URLs into components:
{
"host": "gopher.floodgap.com",
"port": 70,
"gopher_type": "1",
"selector": "/",
"search": None
}Returns structured menu items:
{
"kind": "menu",
"items": [
{
"type": "1",
"title": "Directory Name",
"selector": "/path",
"host": "gopher.example.com",
"port": 70,
"nextUrl": "gopher://gopher.example.com:70/1/path"
}
]
}Returns text content:
{
"kind": "text",
"content": "File content here...",
"metadata": {
"size": 1234,
"encoding": "utf-8"
}
}Returns metadata only:
{
"kind": "binary",
"metadata": {
"type": "9",
"size": 5678,
"description": "Binary file"
}
}- URL format validation
- Selector length limits (max 1024 characters)
- Search query length limits (max 256 characters)
- Host allowlist support
- Maximum response size (default 1MB)
- Connection timeout (default 30 seconds)
- Read timeout enforcement
Binary files return metadata only to prevent:
- Memory exhaustion
- Malicious file downloads
- Unnecessary bandwidth usage
gopher://gopher.floodgap.com/1/
The most well-known Gopher server, maintained by Cameron Kaiser. Contains extensive Gopher resources and information.
gopher://quux.org/1/
Long-running Gopher server with various content.
gopher://gopherlawn.net/1/
Community Gopher server with user-contributed content.
- Start with main menus (type 1)
- Follow menu structure hierarchically
- Use search (type 7) for finding content
- Be patient with slow servers
- Always validate URLs before requests
- Implement proper timeout handling
- Parse menu items carefully
- Handle errors gracefully
- Respect server resources
Some servers return empty menus for certain paths. This is normal behavior.
Gopher servers may be slow or intermittent. Use appropriate timeouts.
Gopher predates Unicode. Most content is ASCII or ISO-8859-1.
- RFC 1436 - The Gopher Protocol
- Gopher Wikipedia
- Floodgap Gopher
Made with ❤️ by Cameron Rye