-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__main__.py
More file actions
128 lines (104 loc) · 5.22 KB
/
Copy path__main__.py
File metadata and controls
128 lines (104 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
IMAS Codex Server - Model Context Protocol Server for IMAS Data Dictionary
This server provides access to the IMAS (ITER Integrated Modelling & Analysis Suite)
Data Dictionary through the Model Context Protocol (MCP). It enables AI assistants
and other MCP clients to search, explore, and query IMAS data structures.
Command Line Interface:
The server exposes a full CLI with options for transport, host, port, and logging. Usage:
python -m imas_codex [OPTIONS] # Module execution (recommended)
imas-codex [OPTIONS] # Console script (after pip install)
Options:
--transport [stdio|sse|streamable-http]
Transport protocol to use (stdio, sse, or
streamable-http) [default: streamable-http]
--host TEXT Host to bind to (for sse and streamable-http
transports) [default: 127.0.0.1]
--port INTEGER Port to bind to (for sse and streamable-http
transports) [default: 8000]
--log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
Set the logging level [default: INFO]
--help Show this message and exit.
Usage Examples:
# Module execution (recommended)
python -m imas_codex # Default streamable-http transport
python -m imas_codex --help # Show help
python -m imas_codex --log-level DEBUG # Debug logging
# After installation with pip, use console scripts
imas-codex # Default streamable-http transport
imas-codex --transport stdio # Use stdio for MCP clients
# Different transport protocols
python -m imas_codex --transport streamable-http # Default: HTTP streaming
python -m imas_codex --transport stdio # stdio for MCP clients
python -m imas_codex --transport sse --port 8080 # Server-Sent Events
# Different log levels
python -m imas_codex --log-level DEBUG # Verbose debugging output
python -m imas_codex --log-level WARNING # Only warnings and errors
# Custom host/port
python -m imas_codex --host 0.0.0.0 --port 8080
# Multiple options
python -m imas_codex --host 0.0.0.0 --port 8080 --log-level DEBUG
Available Tools:
The server provides the following MCP tools for querying IMAS data:
- ids_names(): List all available IDS names
- ids_info(): Get Data Dictionary metadata and version info
- search_by_keywords(): Full-text search across documentation and paths
- search_by_exact_path(): Look up specific IDS paths
- search_by_path_prefix(): Find all paths under a given prefix
- filter_search_results(): Filter search results by field criteria
- get_ids_structure(): Explore hierarchical structure of an IDS
- get_index_stats(): Get search index statistics
- get_common_units(): Get unit usage statistics
Transport Protocols:
- streamable-http: HTTP streaming protocol (default)
* Use for direct HTTP API access and development
* Supports POST requests with JSON payloads
* Supports MCP sampling for enhanced AI interactions
* Includes /health endpoint for monitoring
- stdio: Standard input/output
* Use for VS Code extensions and MCP clients
* Communication via stdin/stdout
* No network configuration required
- sse: Server-Sent Events over HTTP
* Use for web applications requiring real-time updates
* Accessible via HTTP GET requests
* Supports browser-based clients
Installation & CLI:
# Install from source
pip install -e . # Install from Git repository
pip install git+https://github.com/iterorganization/imas-codex.git # After installation, console scripts are available:
imas-codex --help
# Module execution works without installation:
python -m imas_codex --help
The CLI is built with Click and supports:
- Full argument validation and type checking
- Help documentation (--help)
- Environment variable support
- Shell completion (if configured)
Environment:
The server loads IMAS Data Dictionary data from the local environment.
Ensure IMAS is properly installed and configured before running.
Environment variables (optional):
- IMAS_CODEX_HOST: Default host (overridden by --host)
- IMAS_CODEX_PORT: Default port (overridden by --port)
- IMAS_CODEX_LOG_LEVEL: Default log level (overridden by --log-level)
More Information:
- IMAS Documentation: https://imas.iter.org/
- MCP Protocol: https://modelcontextprotocol.io/
- GitHub Repository: https://github.com/iterorganization/imas-codex
"""
if __name__ == "__main__":
# Filter deprecation warnings BEFORE any imports that might trigger them
import warnings
warnings.filterwarnings(
"ignore",
message=".*enable_cleanup_closed.*",
category=DeprecationWarning,
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
module=r"aiohttp\..*",
)
from imas_codex.cli import main
# Expose the Click CLI interface directly
main()