|
6 | 6 | from zoo_mcp import ZooMCPException, logger |
7 | 7 | from zoo_mcp.ai_tools import edit_kcl_project as _edit_kcl_project |
8 | 8 | from zoo_mcp.ai_tools import text_to_cad as _text_to_cad |
9 | | -from zoo_mcp.kcl_docs import ( |
10 | | - get_doc_content, |
11 | | - list_available_docs, |
12 | | - search_docs, |
13 | | -) |
14 | | -from zoo_mcp.kcl_samples import ( |
15 | | - SampleData, |
16 | | - get_sample_content, |
17 | | - list_available_samples, |
18 | | - search_samples, |
19 | | -) |
20 | 9 | from zoo_mcp.utils.image_utils import encode_image, save_image_to_disk |
21 | 10 | from zoo_mcp.zoo_tools import ( |
22 | 11 | CameraView, |
@@ -377,7 +366,7 @@ async def export_kcl( |
377 | 366 |
|
378 | 367 |
|
379 | 368 | @mcp.tool() |
380 | | -async def format_kcl( |
| 369 | +def format_kcl( |
381 | 370 | kcl_code: str | None = None, |
382 | 371 | kcl_path: str | None = None, |
383 | 372 | ) -> str: |
@@ -800,173 +789,6 @@ async def save_image( |
800 | 789 | return f"There was an error saving the image: {e}" |
801 | 790 |
|
802 | 791 |
|
803 | | -@mcp.tool() |
804 | | -async def list_kcl_docs() -> dict | str: |
805 | | - """List all available KCL documentation topics organized by category. |
806 | | -
|
807 | | - Returns a dictionary with the following categories: |
808 | | - - kcl-lang: KCL language documentation (syntax, types, functions, etc.) |
809 | | - - kcl-std-functions: Standard library function documentation |
810 | | - - kcl-std-types: Standard library type documentation |
811 | | - - kcl-std-consts: Standard library constants documentation |
812 | | - - kcl-std-modules: Standard library module documentation |
813 | | -
|
814 | | - Each category contains a list of documentation file paths that can be |
815 | | - retrieved using get_kcl_doc(). |
816 | | -
|
817 | | - Returns: |
818 | | - dict | str: Categories mapped to lists of available documentation paths. |
819 | | - If there was an error, returns an error message string. |
820 | | - """ |
821 | | - logger.info("list_kcl_docs tool called") |
822 | | - try: |
823 | | - return list_available_docs() |
824 | | - except Exception as e: |
825 | | - logger.error("list_kcl_docs tool called with error: %s", e) |
826 | | - return f"There was an error listing KCL documentation: {e}" |
827 | | - |
828 | | - |
829 | | -@mcp.tool() |
830 | | -async def search_kcl_docs(query: str, max_results: int = 5) -> list[dict] | str: |
831 | | - """Search KCL documentation by keyword. |
832 | | -
|
833 | | - Searches across all KCL language and standard library documentation |
834 | | - for the given query. Returns relevant excerpts with surrounding context. |
835 | | -
|
836 | | - Args: |
837 | | - query (str): The search query (case-insensitive). |
838 | | - max_results (int): Maximum number of results to return (default: 5). |
839 | | -
|
840 | | - Returns: |
841 | | - list[dict] | str: List of search results, each containing: |
842 | | - - path: The documentation file path |
843 | | - - title: The document title (from first heading) |
844 | | - - excerpt: A relevant excerpt with the match highlighted in context |
845 | | - - match_count: Number of times the query appears in the document |
846 | | - If there was an error, returns an error message string. |
847 | | - """ |
848 | | - logger.info("search_kcl_docs tool called with query: %s", query) |
849 | | - try: |
850 | | - return search_docs(query, max_results) |
851 | | - except Exception as e: |
852 | | - logger.error("search_kcl_docs tool called with error: %s", e) |
853 | | - return f"There was an error searching KCL documentation: {e}" |
854 | | - |
855 | | - |
856 | | -@mcp.tool() |
857 | | -async def get_kcl_doc(doc_path: str) -> str: |
858 | | - """Get the full content of a specific KCL documentation file. |
859 | | -
|
860 | | - Use list_kcl_docs() to see available documentation paths, or |
861 | | - search_kcl_docs() to find relevant documentation by keyword. |
862 | | -
|
863 | | - Args: |
864 | | - doc_path (str): The path to the documentation file |
865 | | - (e.g., "docs/kcl-lang/functions.md" or "docs/kcl-std/functions/extrude.md") |
866 | | -
|
867 | | - Returns: |
868 | | - str: The full Markdown content of the documentation file, |
869 | | - or an error message if not found. If there was an error, returns an error message string. |
870 | | - """ |
871 | | - logger.info("get_kcl_doc tool called for path: %s", doc_path) |
872 | | - try: |
873 | | - content = get_doc_content(doc_path) |
874 | | - if content is None: |
875 | | - return f"Documentation not found: {doc_path}. Use list_kcl_docs() to see available paths." |
876 | | - return content |
877 | | - except Exception as e: |
878 | | - logger.error("get_kcl_doc tool called with error: %s", e) |
879 | | - return f"There was an error retrieving KCL documentation: {e}" |
880 | | - |
881 | | - |
882 | | -@mcp.tool() |
883 | | -async def list_kcl_samples() -> list[dict] | str: |
884 | | - """List all available KCL sample projects. |
885 | | -
|
886 | | - Returns a list of all available KCL code samples from the Zoo samples |
887 | | - repository. Each sample demonstrates a specific CAD modeling technique |
888 | | - or creates a particular 3D model. |
889 | | -
|
890 | | - Returns: |
891 | | - list[dict] | str: List of sample information, each containing: |
892 | | - - name: The sample directory name (use with get_kcl_sample) |
893 | | - - title: Human-readable title |
894 | | - - description: Brief description of what the sample creates |
895 | | - - multipleFiles: Whether the sample contains multiple KCL files |
896 | | - If there was an error, returns an error message string. |
897 | | - """ |
898 | | - logger.info("list_kcl_samples tool called") |
899 | | - try: |
900 | | - return list_available_samples() |
901 | | - except Exception as e: |
902 | | - logger.error("list_kcl_samples tool called with error: %s", e) |
903 | | - return f"There was an error listing KCL samples: {e}" |
904 | | - |
905 | | - |
906 | | -@mcp.tool() |
907 | | -async def search_kcl_samples(query: str, max_results: int = 5) -> list[dict] | str: |
908 | | - """Search KCL samples by keyword. |
909 | | -
|
910 | | - Searches across all KCL sample titles and descriptions |
911 | | - for the given query. Returns matching samples ranked by relevance. |
912 | | -
|
913 | | - Args: |
914 | | - query (str): The search query (case-insensitive). |
915 | | - max_results (int): Maximum number of results to return (default: 5). |
916 | | -
|
917 | | - Returns: |
918 | | - list[dict] | str: List of search results, each containing: |
919 | | - - name: The sample directory name (use with get_kcl_sample) |
920 | | - - title: Human-readable title |
921 | | - - description: Brief description of the sample |
922 | | - - multipleFiles: Whether the sample contains multiple KCL files |
923 | | - - match_count: Number of times the query appears in title/description |
924 | | - - excerpt: A relevant excerpt with the match in context |
925 | | - If there was an error, returns an error message string. |
926 | | - """ |
927 | | - logger.info("search_kcl_samples tool called with query: %s", query) |
928 | | - try: |
929 | | - return search_samples(query, max_results) |
930 | | - except Exception as e: |
931 | | - logger.error("search_kcl_samples tool called with error: %s", e) |
932 | | - return f"There was an error searching KCL samples: {e}" |
933 | | - |
934 | | - |
935 | | -@mcp.tool() |
936 | | -async def get_kcl_sample(sample_name: str) -> SampleData | str: |
937 | | - """Get the full content of a specific KCL sample including all files. |
938 | | -
|
939 | | - Retrieves all KCL files that make up a sample project. Some samples |
940 | | - consist of a single main.kcl file, while others have multiple files |
941 | | - (e.g., parameters.kcl, components, etc.). |
942 | | -
|
943 | | - Use list_kcl_samples() to see available sample names, or |
944 | | - search_kcl_samples() to find samples by keyword. |
945 | | -
|
946 | | - Args: |
947 | | - sample_name (str): The sample directory name |
948 | | - (e.g., "ball-bearing", "axial-fan", "gear") |
949 | | -
|
950 | | - Returns: |
951 | | - SampleData | str: A SampleData dictionary containing: |
952 | | - - name: The sample directory name |
953 | | - - title: Human-readable title |
954 | | - - description: Brief description |
955 | | - - multipleFiles: Whether the sample contains multiple files |
956 | | - - files: List of SampleFile dictionaries, each with 'filename' and 'content' |
957 | | - Returns an error message string if the sample is not found. If there was an error, returns an error message string. |
958 | | - """ |
959 | | - logger.info("get_kcl_sample tool called for sample: %s", sample_name) |
960 | | - try: |
961 | | - sample = await get_sample_content(sample_name) |
962 | | - if sample is None: |
963 | | - return f"Sample not found: {sample_name}. Use list_kcl_samples() to see available samples." |
964 | | - return sample |
965 | | - except Exception as e: |
966 | | - logger.error("get_kcl_sample tool called with error: %s", e) |
967 | | - return f"There was an error retrieving KCL sample: {e}" |
968 | | - |
969 | | - |
970 | 792 | def main(): |
971 | 793 | logger.info("Starting MCP server...") |
972 | 794 | mcp.run(transport="stdio") |
|
0 commit comments