MCP Telnet Client
Project description
MCP Telnet Client
Overview
The MCP Telnet Client is a Python-based microservice that provides a robust interface for interacting with Telnet servers. It enables applications to establish Telnet connections, execute commands, and maintain persistent sessions across multiple requests.
Project Details
- Version: 0.1.0
- Python Compatibility: Python 3.9+
Features
- Telnet Server Connectivity: Connect to any Telnet server with host and port specification
- Command Execution: Send commands and collect responses in a structured format
- Session Management: Maintain persistent connections with unique session IDs
- Minimal Telnet Negotiation: Handles IAC negotiation with sensible defaults
- Async Server Architecture: Built with asyncio for efficient performance
- Flexible Configuration: Configurable through environment variables and config files
- Comprehensive Validation: Robust input validation using Pydantic models
Dependencies
Core dependencies:
- mcp (>=1.6.0)
- pydantic
- telnetlib (standard library)
- typing (standard library)
Development dependencies:
- pytest
Installation
Prerequisites
- Python 3.9 or higher
- pip
- (Optional) Virtual environment recommended
Install from PyPI
pip install chuk-mcp-telnet-client
Install from Source
- Clone the repository:
git clone <repository-url>
cd chuk-mcp-telnet-client
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install the package:
pip install .
Development Installation
To set up for development:
pip install .[dev] # Installs package with development dependencies
Running the Server
Command-Line Interface
chuk-mcp-telnet-client
Programmatic Usage
from chuk_mcp_telnet_client.main import main
if __name__ == "__main__":
main()
Environment Variables
NO_BOOTSTRAP: Set to disable component bootstrapping- Other configuration options can be set in the configuration files
Available Tools
1. Telnet Client
Establishes a connection to a Telnet server and executes commands.
Input:
host: Host/IP of the Telnet serverport: Port number (e.g., 8023)commands: List of commands to send to the serversession_id(optional): ID to maintain connection between callsclose_session(optional): If True, close the session after processing commands
Example:
telnet_client_tool(
host="example.com",
port=23,
commands=["show version", "show interfaces"],
session_id=None, # Auto-generated if not provided
close_session=False
)
Returns:
- Initial banner from the server
- List of command responses
- Session information for maintaining connection
2. Close Telnet Session
Closes a specific Telnet session by ID.
Input:
session_id: The session ID to close
Example:
telnet_close_session("telnet_example.com_23_1649876543")
Returns:
- Status of the operation (success or failure)
- Descriptive message
3. List Telnet Sessions
Lists all active Telnet sessions.
Input: None
Example:
telnet_list_sessions()
Returns:
- Count of active sessions
- Details for each session (host, port, creation time, age)
Technical Details
Session Management
Sessions are maintained in a global dictionary (TELNET_SESSIONS) with the following structure:
- Key: Unique session ID
- Value: Dictionary containing:
telnet: Telnet connection objecthost: Server hostname/IPport: Server port numbercreated_at: Session creation timestamp
Telnet Option Negotiation
The client implements minimal Telnet option negotiation that:
- Responds with WONT to DO requests
- Responds with DONT to WILL requests
This approach ensures compatibility with most Telnet servers while avoiding complex negotiation.
Development
Code Structure
main.py: Application entry pointmodels.py: Pydantic models for input/output validationserver/: Server implementation components
Running Tests
pytest
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chuk_mcp_telnet_client-0.2-py3-none-any.whl.
File metadata
- Download URL: chuk_mcp_telnet_client-0.2-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0cdbf9be980390d23561661e180fb63c78c49ac3f1d222914c5bd2e06969426
|
|
| MD5 |
f92f1e2f44f05401f4e7f6713c7557ea
|
|
| BLAKE2b-256 |
e9585c2159e90506dbba1c0fd8e26a86b28eca6e58cebb68c7a5a69f02c63b1e
|