Skip to content

Commit 3fb35c5

Browse files
committed
ft: add stdio and https modes
1 parent c1cb451 commit 3fb35c5

3 files changed

Lines changed: 79 additions & 1 deletion

File tree

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,26 @@ Create a `config.json` file in the project root:
126126

127127
### Starting the Server
128128

129+
The server can be started in two modes:
130+
131+
#### HTTP Server Mode (Recommended)
132+
133+
```bash
134+
# Start HTTP server on http://127.0.0.1:8080
135+
poetry start
136+
```
137+
138+
#### Stdio Mode (For MCP Client Integration)
139+
140+
```bash
141+
# Start stdio server for MCP client connections
142+
poetry stdio
143+
```
144+
145+
#### Alternative: Manual Startup
146+
129147
```bash
130-
# Using Poetry (recommended)
148+
# Using Poetry (manual method)
131149
poetry run python main.py
132150

133151
# Or activate the virtual environment first

main.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,62 @@ async def run_as_server():
576576
def run_standard_server():
577577
mcp.run()
578578

579+
def start_server():
580+
"""Entry point for 'poetry start' command - runs HTTP server"""
581+
try:
582+
config = get_config()
583+
logger.info("HyperLiquid MCP Server starting...")
584+
network = "Testnet" if config.testnet else "Mainnet"
585+
logger.info(f"Network: {network}")
586+
account_display = config.account_address or "Will be derived from private key"
587+
logger.info(f"Account: {account_display}")
588+
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'hyperliquid_mcp.log')
589+
logger.info(f"Logs will be written to: {log_path}")
590+
591+
asyncio.run(run_as_server())
592+
except Exception as e:
593+
logger.error(f"Failed to start server: {e}")
594+
print(f"Failed to start server: {e}")
595+
print("\nTo configure the server:")
596+
print("1. Set environment variables:")
597+
print(" export HYPERLIQUID_PRIVATE_KEY='your_private_key'")
598+
print(" export HYPERLIQUID_TESTNET='false' # or 'true' for testnet")
599+
print(" export HYPERLIQUID_ACCOUNT_ADDRESS='your_address' # optional")
600+
print("\n2. Or create a config.json file:")
601+
print(' {"private_key": "your_private_key", "testnet": false, "account_address": "your_address"}')
602+
print("\n3. Or create a .env file:")
603+
print(" HYPERLIQUID_PRIVATE_KEY=your_private_key")
604+
print(" HYPERLIQUID_TESTNET=false")
605+
print(" HYPERLIQUID_ACCOUNT_ADDRESS=your_address")
606+
607+
def stdio_server():
608+
"""Entry point for 'poetry stdio' command - runs stdio server"""
609+
try:
610+
config = get_config()
611+
logger.info("HyperLiquid MCP Server starting in stdio mode...")
612+
network = "Testnet" if config.testnet else "Mainnet"
613+
logger.info(f"Network: {network}")
614+
account_display = config.account_address or "Will be derived from private key"
615+
logger.info(f"Account: {account_display}")
616+
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'hyperliquid_mcp.log')
617+
logger.info(f"Logs will be written to: {log_path}")
618+
619+
run_standard_server()
620+
except Exception as e:
621+
logger.error(f"Failed to start stdio server: {e}")
622+
print(f"Failed to start stdio server: {e}")
623+
print("\nTo configure the server:")
624+
print("1. Set environment variables:")
625+
print(" export HYPERLIQUID_PRIVATE_KEY='your_private_key'")
626+
print(" export HYPERLIQUID_TESTNET='false' # or 'true' for testnet")
627+
print(" export HYPERLIQUID_ACCOUNT_ADDRESS='your_address' # optional")
628+
print("\n2. Or create a config.json file:")
629+
print(' {"private_key": "your_private_key", "testnet": false, "account_address": "your_address"}')
630+
print("\n3. Or create a .env file:")
631+
print(" HYPERLIQUID_PRIVATE_KEY=your_private_key")
632+
print(" HYPERLIQUID_TESTNET=false")
633+
print(" HYPERLIQUID_ACCOUNT_ADDRESS=your_address")
634+
579635
if __name__ == "__main__":
580636
try:
581637
config = get_config()

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ authors = ["Gigabrain <chetan@gigabrain.gg>"]
66
readme = "README.md"
77
packages = [{ include = "services" }]
88

9+
[tool.poetry.scripts]
10+
start = "main:start_server"
11+
stdio = "main:stdio_server"
12+
913
[tool.poetry.dependencies]
1014
python = "^3.11"
1115
fastmcp = "^2.9.2"

0 commit comments

Comments
 (0)