88
99mcp = FastMCP ("Parse Patrol - Unified Chemistry Parser" )
1010
11- # Import subserver functions directly instead of using importlib
12- from .parsers .cclib .__main__ import cclib_parse_file_to_model , cclib_test_prompt
13- from .parsers .gaussian .__main__ import gauss_parse_file_to_model , custom_gaussian_test_prompt
14- from .parsers .iodata .__main__ import iodata_parse_file_to_model , iodata_test_prompt
15- from .databases .nomad .__main__ import search_nomad_entries , get_nomad_raw_files , get_nomad_archive , nomad_materials_prompt
16-
17- # Register all imported functions
18- mcp .tool ()(cclib_parse_file_to_model )
19- mcp .tool ()(gauss_parse_file_to_model )
20- mcp .tool ()(iodata_parse_file_to_model )
21- mcp .tool ()(search_nomad_entries )
22- mcp .tool ()(get_nomad_raw_files )
23- mcp .tool ()(get_nomad_archive )
24-
25- mcp .prompt ()(cclib_test_prompt )
26- mcp .prompt ()(custom_gaussian_test_prompt )
27- mcp .prompt ()(iodata_test_prompt )
28- mcp .prompt ()(nomad_materials_prompt )
11+ # Configuration for all parsers and databases
12+ parser_configs = [
13+ {
14+ "name" : "cclib parser" ,
15+ "module" : ".parsers.cclib.__main__" ,
16+ "imports" : ["cclib_parse_file_to_model" , "cclib_test_prompt" ],
17+ "tools" : ["cclib_parse_file_to_model" ],
18+ "prompts" : ["cclib_test_prompt" ]
19+ },
20+ {
21+ "name" : "gaussian parser" ,
22+ "module" : ".parsers.gaussian.__main__" ,
23+ "imports" : ["gauss_parse_file_to_model" , "custom_gaussian_test_prompt" ],
24+ "tools" : ["gauss_parse_file_to_model" ],
25+ "prompts" : ["custom_gaussian_test_prompt" ]
26+ },
27+ {
28+ "name" : "iodata parser" ,
29+ "module" : ".parsers.iodata.__main__" ,
30+ "imports" : ["iodata_parse_file_to_model" , "iodata_test_prompt" ],
31+ "tools" : ["iodata_parse_file_to_model" ],
32+ "prompts" : ["iodata_test_prompt" ]
33+ },
34+ {
35+ "name" : "NOMAD database" ,
36+ "module" : ".databases.nomad.__main__" ,
37+ "imports" : ["search_nomad_entries" , "get_nomad_raw_files" , "get_nomad_archive" , "nomad_materials_prompt" ],
38+ "tools" : ["search_nomad_entries" , "get_nomad_raw_files" , "get_nomad_archive" ],
39+ "prompts" : ["nomad_materials_prompt" ]
40+ }
41+ ]
42+
43+ # Dynamically import and register available parsers
44+ def register_parsers ():
45+ """Register all available parser tools and prompts."""
46+
47+ for config in parser_configs :
48+ try :
49+ # Dynamic import from module
50+ from importlib import import_module
51+ module = import_module (config ["module" ], package = __package__ )
52+
53+ # Register tools
54+ for tool_name in config ["tools" ]:
55+ tool_func = getattr (module , tool_name )
56+ mcp .tool ()(tool_func )
57+
58+ # Register prompts
59+ for prompt_name in config ["prompts" ]:
60+ prompt_func = getattr (module , prompt_name )
61+ mcp .prompt ()(prompt_func )
62+
63+ print (f"✓ Registered { config ['name' ]} " )
64+
65+ except ImportError as e :
66+ print (f"⚠ { config ['name' ]} not available: { e } " )
67+ except AttributeError as e :
68+ print (f"⚠ { config ['name' ]} missing expected functions: { e } " )
2969
3070
3171@mcp .prompt ()
@@ -66,7 +106,7 @@ async def cleanup_corrupted_files_prompt() -> str:
66106 Formatted prompt string for file cleanup
67107 """
68108
69- return f """
109+ return """
70110 You are helping me clean up corrupted computational chemistry files.
71111
72112 1. Check the folders in `.data` with the various parsing tools.
@@ -120,5 +160,6 @@ async def parse_patrol_parser_pipeline_prompt(
120160 )
121161
122162
163+ register_parsers ()
123164if __name__ == "__main__" :
124165 mcp .run ()
0 commit comments