argo-search 1.0.1 → 2.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.en.md +735 -0
- package/README.es.md +777 -0
- package/README.ja.md +777 -0
- package/README.ko.md +777 -0
- package/README.md +778 -320
- package/SKILL.md +135 -0
- package/assets/readme/hero.svg +121 -0
- package/assets/readme/made-with-beautify.svg +10 -0
- package/assets/readme/proof-routes.svg +73 -0
- package/assets/readme/why-better.svg +104 -0
- package/assets/readme/workflow.svg +83 -0
- package/backends/domain_profiles.json +2356 -96
- package/backends/engine_registry.yaml +3428 -503
- package/backends/query_synonyms_cn.json +35 -0
- package/backends/quota_profiles.json +2488 -160
- package/backends/source_types_cn.json +109 -0
- package/backends/text_lexicon.json +44 -0
- package/bin/argo +772 -0
- package/bin/argo.js +102 -39
- package/config.yaml +5139 -367
- package/cordis.patch.yml +21 -0
- package/data/countries.json +40 -0
- package/data/lang_matrix/lang_capability.json +842 -0
- package/data/lang_matrix/matrix_2026-09-10.json +11921 -0
- package/data/regions_cn.json +1 -0
- package/docs/ADDING_NEW_ENGINE.md +184 -0
- package/docs/ARGO_INTRO.md +124 -0
- package/docs/DATA_SOURCE_GAPS.md +81 -0
- package/docs/DESIGN_LOCAL_DATA_FUSION.md +90 -0
- package/docs/ENGINE_CATALOG.md +575 -0
- package/docs/MCP_SETUP.md +108 -0
- package/docs/PLATFORM_PATHS.md +111 -0
- package/docs/RELEASE_NOTES_v2.8.0.md +71 -0
- package/docs/RELEASE_NOTES_v2.8.2.md +63 -0
- package/docs/RELEASE_NOTES_v2.8.3.md +55 -0
- package/docs/RELEASE_NOTES_v2.8.4.md +79 -0
- package/docs/RELEASE_NOTES_v2.8.5.md +102 -0
- package/docs/RELEASE_NOTES_v2.8.6.md +66 -0
- package/docs/RELEASE_NOTES_v2.8.7.md +65 -0
- package/docs/RELEASE_NOTES_v2.8.8.md +67 -0
- package/docs/RELEASE_NOTES_v2.8.9.md +67 -0
- package/docs/RELEASE_NOTES_v2.9.0.md +64 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +73 -0
- package/docs/SEARCH_ARCHIVE.md +115 -0
- package/docs/assets/architecture.svg +104 -0
- package/docs/assets/hero.svg +98 -0
- package/docs/engines/bangumi.md +27 -0
- package/docs/engines/biorxiv.md +27 -0
- package/docs/engines/clawhub.md +27 -0
- package/docs/engines/crt_sh.md +27 -0
- package/docs/engines/datacite.md +27 -0
- package/docs/engines/deps_dev.md +27 -0
- package/docs/engines/douban_movie.md +27 -0
- package/docs/engines/endoflife.md +27 -0
- package/docs/engines/flk_law.md +27 -0
- package/docs/engines/fxtwitter.md +27 -0
- package/docs/engines/google_news.md +27 -0
- package/docs/engines/gov_regulations.md +27 -0
- package/docs/engines/guqian.md +27 -0
- package/docs/engines/hackernews.md +27 -0
- package/docs/engines/iplant.md +27 -0
- package/docs/engines/keenable.md +27 -0
- package/docs/engines/met_museum.md +27 -0
- package/docs/engines/nasa_images.md +27 -0
- package/docs/engines/netease_music.md +27 -0
- package/docs/engines/npm.md +27 -0
- package/docs/engines/nvd.md +27 -0
- package/docs/engines/openreview.md +27 -0
- package/docs/engines/openstd.md +27 -0
- package/docs/engines/parallel_free.md +27 -0
- package/docs/engines/people_daily.md +27 -0
- package/docs/engines/realtime_index.md +27 -0
- package/docs/engines/sec_edgar.md +27 -0
- package/docs/engines/seltz.md +27 -0
- package/docs/engines/skillsmp.md +27 -0
- package/docs/engines/sspai.md +27 -0
- package/docs/engines/std_samr.md +27 -0
- package/docs/engines/train.md +27 -0
- package/docs/engines/un_comtrade.md +27 -0
- package/docs/engines/wikisource.md +27 -0
- package/docs/engines/zdic.md +27 -0
- package/docs/engines/zenodo.md +27 -0
- package/docs/engines/zhihu_hot_app.md +27 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +176 -0
- package/engines/README.md +10 -0
- package/engines/_template_cli.yaml +39 -0
- package/engines/_template_http.yaml +37 -0
- package/engines/plugins/_template_plugin.py +50 -0
- package/engines/specs/_cisa_kev.yaml +54 -0
- package/engines/specs/_osv.yaml +63 -0
- package/engines/specs/aljazeera.yaml +43 -0
- package/engines/specs/antara.yaml +43 -0
- package/engines/specs/artic.yaml +20 -0
- package/engines/specs/aviation_weather.yaml +39 -0
- package/engines/specs/bangumi.yaml +21 -0
- package/engines/specs/biorxiv.yaml +24 -0
- package/engines/specs/carbon_intensity.yaml +32 -0
- package/engines/specs/cfets.yaml +41 -0
- package/engines/specs/cinii.yaml +44 -0
- package/engines/specs/clawhub.yaml +49 -0
- package/engines/specs/cleveland.yaml +19 -0
- package/engines/specs/cn_ai_news.yaml +43 -0
- package/engines/specs/core.yaml +35 -0
- package/engines/specs/crt_sh.yaml +38 -0
- package/engines/specs/ct24.yaml +43 -0
- package/engines/specs/datacite.yaml +27 -0
- package/engines/specs/datagov_uk.yaml +41 -0
- package/engines/specs/ddgs_images.yaml +45 -0
- package/engines/specs/deepseek_search.yaml +74 -0
- package/engines/specs/deezer.yaml +20 -0
- package/engines/specs/defillama.yaml +38 -0
- package/engines/specs/deps_dev.yaml +21 -0
- package/engines/specs/digup.yaml +36 -0
- package/engines/specs/doi.yaml +39 -0
- package/engines/specs/douban_movie.yaml +22 -0
- package/engines/specs/dw_news.yaml +47 -0
- package/engines/specs/egov_law.yaml +21 -0
- package/engines/specs/elpais.yaml +43 -0
- package/engines/specs/endoflife.yaml +21 -0
- package/engines/specs/energy_charts.yaml +21 -0
- package/engines/specs/factcheck_org.yaml +52 -0
- package/engines/specs/faz.yaml +43 -0
- package/engines/specs/federal_register.yaml +57 -0
- package/engines/specs/firecrawl.yaml +53 -0
- package/engines/specs/flk_law.yaml +24 -0
- package/engines/specs/folha.yaml +43 -0
- package/engines/specs/france24.yaml +44 -0
- package/engines/specs/full_fact.yaml +47 -0
- package/engines/specs/fxtwitter.yaml +36 -0
- package/engines/specs/gbfs_nyc.yaml +32 -0
- package/engines/specs/gdacs.yaml +21 -0
- package/engines/specs/gdelt.yaml +64 -0
- package/engines/specs/gleif.yaml +55 -0
- package/engines/specs/google_news.yaml +22 -0
- package/engines/specs/gov_regulations.yaml +38 -0
- package/engines/specs/guardian_rss.yaml +59 -0
- package/engines/specs/hkex.yaml +40 -0
- package/engines/specs/hurriyet.yaml +43 -0
- package/engines/specs/iplant.yaml +25 -0
- package/engines/specs/jikan.yaml +24 -0
- package/engines/specs/jolpica.yaml +20 -0
- package/engines/specs/k10plus.yaml +20 -0
- package/engines/specs/keenable.yaml +44 -0
- package/engines/specs/keenable_free.yaml +36 -0
- package/engines/specs/lefigaro.yaml +43 -0
- package/engines/specs/listenbrainz.yaml +19 -0
- package/engines/specs/matichon.yaml +43 -0
- package/engines/specs/met_museum.yaml +21 -0
- package/engines/specs/nasa_images.yaml +45 -0
- package/engines/specs/netease_music.yaml +38 -0
- package/engines/specs/nhk.yaml +43 -0
- package/engines/specs/nhtsa_vpic.yaml +20 -0
- package/engines/specs/noaa_swpc.yaml +20 -0
- package/engines/specs/nvd.yaml +38 -0
- package/engines/specs/obis.yaml +20 -0
- package/engines/specs/opencitations.yaml +52 -0
- package/engines/specs/openf1.yaml +21 -0
- package/engines/specs/openfoodfacts.yaml +45 -0
- package/engines/specs/openligadb.yaml +20 -0
- package/engines/specs/openreview.yaml +37 -0
- package/engines/specs/openstd.yaml +21 -0
- package/engines/specs/people_daily.yaml +22 -0
- package/engines/specs/realtime_index.yaml +34 -0
- package/engines/specs/ror.yaml +20 -0
- package/engines/specs/satnogs.yaml +20 -0
- package/engines/specs/sec_edgar.yaml +46 -0
- package/engines/specs/shfe.yaml +39 -0
- package/engines/specs/skillsmp.yaml +50 -0
- package/engines/specs/sogou_weixin_browser.yaml +30 -0
- package/engines/specs/soilgrids.yaml +25 -0
- package/engines/specs/sspai.yaml +36 -0
- package/engines/specs/stackexchange.yaml +46 -0
- package/engines/specs/std_samr.yaml +21 -0
- package/engines/specs/tass.yaml +43 -0
- package/engines/specs/tavily_free.yaml +56 -0
- package/engines/specs/tle_mirror.yaml +21 -0
- package/engines/specs/train.yaml +37 -0
- package/engines/specs/tvmaze.yaml +20 -0
- package/engines/specs/twitter_syndication.yaml +31 -0
- package/engines/specs/un_comtrade.yaml +23 -0
- package/engines/specs/unpaywall.yaml +54 -0
- package/engines/specs/vnpress.yaml +43 -0
- package/engines/specs/weather.yaml +32 -0
- package/engines/specs/who_don.yaml +21 -0
- package/engines/specs/who_gho.yaml +20 -0
- package/engines/specs/wikimedia_commons.yaml +34 -0
- package/engines/specs/wikisource.yaml +22 -0
- package/engines/specs/worms.yaml +19 -0
- package/engines/specs/x_trending.yaml +34 -0
- package/engines/specs/yna.yaml +43 -0
- package/engines/specs/ynet.yaml +43 -0
- package/engines/specs/yuanbao.yaml +93 -0
- package/engines/specs/zbmath.yaml +40 -0
- package/engines/specs/zdic.yaml +22 -0
- package/engines/specs/zenodo.yaml +27 -0
- package/engines/specs/zhihu_hot_app.yaml +35 -0
- package/mcp/clients.yaml +106 -0
- package/package.json +55 -12
- package/packages/dsh-plugin/README.md +152 -0
- package/packages/dsh-plugin/cordis.patch.yml +48 -0
- package/packages/dsh-plugin/dsh/client.js +1533 -0
- package/packages/dsh-plugin/dsh/diagnostics.js +54 -0
- package/packages/dsh-plugin/dsh/index.js +527 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +749 -0
- package/packages/dsh-plugin/dsh/runner.js +666 -0
- package/packages/dsh-plugin/dsh/wide-research.js +878 -0
- package/packages/dsh-plugin/package.json +38 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +70 -0
- package/packages/dsh-plugin/test/client.test.js +406 -0
- package/packages/dsh-plugin/test/config.test.js +30 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +28 -0
- package/packages/dsh-plugin/test/index.test.js +1382 -0
- package/references/query-templates.md +96 -0
- package/references/query-templates.yaml +118 -0
- package/scripts/ab_eval.py +219 -0
- package/scripts/ab_eval_p0p1.py +266 -0
- package/scripts/adaptive.py +294 -70
- package/scripts/answer.py +154 -0
- package/scripts/archive_run.py +591 -0
- package/scripts/argo_engine_registry.py +172 -0
- package/scripts/argo_paths.py +728 -0
- package/scripts/article.py +136 -0
- package/scripts/article_meta.py +131 -0
- package/scripts/arxiv_source.py +201 -0
- package/scripts/badcase_ledger.py +252 -0
- package/scripts/batch_probe.py +241 -0
- package/scripts/benchmark.py +19 -0
- package/scripts/bounded_run.py +144 -0
- package/scripts/browser_auth.py +323 -0
- package/scripts/budget.py +247 -0
- package/scripts/budget_cli.py +93 -0
- package/scripts/build_release_assets.sh +65 -0
- package/scripts/burstiness_detector.py +147 -0
- package/scripts/cache.py +1066 -67
- package/scripts/cache_guard.py +271 -0
- package/scripts/cache_key_vdom.py +56 -0
- package/scripts/cache_similarity.py +170 -0
- package/scripts/caliber_isolation.py +195 -0
- package/scripts/calibrate_lowquality.py +210 -0
- package/scripts/candidate_envelope.py +366 -0
- package/scripts/chrome_cdp.py +871 -0
- package/scripts/ci_drift_gate.py +90 -0
- package/scripts/circuit_breaker.py +389 -0
- package/scripts/citations.py +334 -0
- package/scripts/cite_cli.py +59 -0
- package/scripts/cjk_tokens.py +95 -0
- package/scripts/clarify.py +47 -24
- package/scripts/cli_io.py +240 -0
- package/scripts/config.py +683 -45
- package/scripts/config_cache.py +402 -0
- package/scripts/conn_pool.py +220 -0
- package/scripts/content_boundary.py +46 -0
- package/scripts/content_security.py +685 -0
- package/scripts/content_signals.py +751 -0
- package/scripts/crawl.py +74 -35
- package/scripts/cross_lingual_trace.py +293 -0
- package/scripts/daemon.py +866 -0
- package/scripts/digup_bridge.py +214 -0
- package/scripts/dispatch_result.py +98 -0
- package/scripts/engine_admission.py +366 -0
- package/scripts/engine_dispatch.py +982 -0
- package/scripts/engine_env.py +539 -0
- package/scripts/engine_failure.py +411 -0
- package/scripts/engine_families.py +738 -0
- package/scripts/engine_policy.py +218 -0
- package/scripts/engine_requires.py +190 -0
- package/scripts/engine_status.py +322 -0
- package/scripts/engine_validate.py +638 -0
- package/scripts/engines.py +799 -294
- package/scripts/engines_base.py +1521 -0
- package/scripts/engines_builders.py +310 -0
- package/scripts/engines_builders_batch10.py +204 -0
- package/scripts/engines_builders_batch11.py +174 -0
- package/scripts/engines_builders_batch12.py +103 -0
- package/scripts/engines_builders_batch13.py +340 -0
- package/scripts/engines_builders_batch14.py +656 -0
- package/scripts/engines_builders_batch15.py +249 -0
- package/scripts/engines_builders_batch9.py +1468 -0
- package/scripts/engines_builders_cn.py +2283 -0
- package/scripts/engines_builders_data.py +2923 -0
- package/scripts/engines_builders_data_macro.py +775 -0
- package/scripts/engines_builders_feeds.py +255 -0
- package/scripts/engines_builders_intl.py +1239 -0
- package/scripts/engines_builders_keyless.py +111 -0
- package/scripts/engines_builders_search.py +440 -0
- package/scripts/engines_builders_tech.py +1359 -0
- package/scripts/evidence.py +620 -166
- package/scripts/evidence_loop.py +624 -0
- package/scripts/evidence_tier.py +298 -0
- package/scripts/except_sets.py +25 -0
- package/scripts/extract.py +55 -16
- package/scripts/fact_align.py +207 -0
- package/scripts/fact_crosscheck.py +230 -0
- package/scripts/fetch.py +25 -12
- package/scripts/fetch_browser.py +87 -0
- package/scripts/fetch_jsrun.py +122 -0
- package/scripts/fetch_quality.py +225 -0
- package/scripts/fetch_render_tinyfish.py +117 -0
- package/scripts/fetch_v3.py +1804 -0
- package/scripts/focus_extract.py +350 -0
- package/scripts/fulltext_store.py +169 -0
- package/scripts/fxtwitter_api.py +325 -0
- package/scripts/gen_engine_catalog.py +364 -0
- package/scripts/gen_native_tools.py +91 -0
- package/scripts/gen_routing_snapshot.py +195 -0
- package/scripts/health_check.py +140 -402
- package/scripts/health_probe.py +23 -8
- package/scripts/hot_state.py +134 -0
- package/scripts/http_client.py +1053 -0
- package/scripts/image_ops.py +430 -0
- package/scripts/image_vision/vision_probe.swift +126 -0
- package/scripts/install.ps1 +166 -0
- package/scripts/install.sh +221 -0
- package/scripts/job.py +1186 -0
- package/scripts/jump_resolver.py +235 -0
- package/scripts/lang_capability.py +150 -0
- package/scripts/lang_detect.py +289 -0
- package/scripts/lang_matrix_probe.py +329 -0
- package/scripts/lang_pref.py +311 -0
- package/scripts/link_source.py +340 -0
- package/scripts/local_image.py +970 -0
- package/scripts/local_seek.py +402 -0
- package/scripts/macro_countries.py +97 -0
- package/scripts/matrix_search_eval.py +1187 -0
- package/scripts/mcp_compact.py +234 -0
- package/scripts/mcp_diag.py +8 -3
- package/scripts/mcp_handlers.py +492 -0
- package/scripts/mcp_handlers_surface.py +157 -0
- package/scripts/mcp_launch.sh +124 -0
- package/scripts/mcp_local.py +241 -0
- package/scripts/mcp_server.py +125 -419
- package/scripts/mcp_setup.py +431 -0
- package/scripts/mcp_tools.py +331 -0
- package/scripts/mcp_transport.py +191 -0
- package/scripts/mcp_warm.py +127 -0
- package/scripts/min_version_scan.py +335 -0
- package/scripts/net_proxy.py +258 -0
- package/scripts/network_aware.py +152 -0
- package/scripts/output_transparency.py +200 -0
- package/scripts/paid_policy.py +98 -0
- package/scripts/paper.py +274 -0
- package/scripts/pdf_extract.py +518 -0
- package/scripts/phrase_filter.py +66 -0
- package/scripts/plan.py +422 -0
- package/scripts/postprocess_signals.py +150 -0
- package/scripts/pre-commit +48 -0
- package/scripts/query_enhance.py +157 -0
- package/scripts/query_operators.py +196 -0
- package/scripts/query_rewriter.py +116 -7
- package/scripts/query_signals.py +300 -0
- package/scripts/query_templates.py +167 -0
- package/scripts/query_understanding.py +411 -0
- package/scripts/query_variants.py +298 -0
- package/scripts/quota.py +633 -76
- package/scripts/rank_signals.py +775 -0
- package/scripts/ranking_eval.py +319 -0
- package/scripts/readability_extract.py +433 -0
- package/scripts/recompute.py +415 -0
- package/scripts/recovery.py +616 -0
- package/scripts/recovery_l0.py +160 -0
- package/scripts/recovery_runner.py +150 -0
- package/scripts/redskill/redskill_engine.py +332 -0
- package/scripts/regression_p0p1.py +318 -0
- package/scripts/replay_eval.py +658 -0
- package/scripts/rerank_tfidf.py +225 -0
- package/scripts/research.py +607 -403
- package/scripts/research_cli.py +361 -0
- package/scripts/research_dossier.py +492 -0
- package/scripts/research_expand.py +169 -0
- package/scripts/research_gates.py +272 -0
- package/scripts/research_report.py +209 -0
- package/scripts/research_strategy.py +37 -0
- package/scripts/research_work_packages.py +195 -0
- package/scripts/result_lang.py +311 -0
- package/scripts/retry_policy.py +76 -0
- package/scripts/robots_guard.py +259 -0
- package/scripts/route.py +921 -254
- package/scripts/route_bangs.py +40 -0
- package/scripts/route_cache.py +243 -0
- package/scripts/route_combo.py +917 -0
- package/scripts/route_domains.py +341 -0
- package/scripts/route_lang.py +605 -0
- package/scripts/route_log.py +63 -0
- package/scripts/route_policy.py +250 -0
- package/scripts/rrf_classic.py +66 -0
- package/scripts/screenshot.py +73 -0
- package/scripts/search.py +886 -406
- package/scripts/search_attribution.py +185 -0
- package/scripts/search_benchmark.py +407 -0
- package/scripts/search_cli.py +640 -0
- package/scripts/search_entry.py +395 -0
- package/scripts/search_output.py +690 -0
- package/scripts/search_pipeline.py +926 -0
- package/scripts/search_rank.py +991 -0
- package/scripts/search_types.py +129 -16
- package/scripts/seek_locator.py +68 -0
- package/scripts/semantic_evidence.py +391 -0
- package/scripts/serp_guard.py +336 -0
- package/scripts/serp_kill_log.py +74 -0
- package/scripts/single_flight.py +120 -0
- package/scripts/social_engines/__init__.py +10 -0
- package/scripts/social_engines/bilibili_engine.py +131 -0
- package/scripts/social_engines/hackernews_engine.py +113 -0
- package/scripts/social_engines/reddit_engine.py +172 -0
- package/scripts/social_engines/twitter_engine.py +397 -0
- package/scripts/social_engines/v2ex_engine.py +101 -0
- package/scripts/social_engines/weibo_engine.py +128 -0
- package/scripts/social_engines/xiaohongshu_engine.py +137 -0
- package/scripts/social_engines/zhihu_engine.py +139 -0
- package/scripts/social_research.py +201 -0
- package/scripts/sogou_weixin_browser.py +318 -0
- package/scripts/source_ledger.py +249 -0
- package/scripts/stage_timing.py +58 -0
- package/scripts/stats_cli.py +107 -0
- package/scripts/straggler_policy.py +60 -0
- package/scripts/stylometry_detector.py +231 -0
- package/scripts/sync_backends.py +353 -0
- package/scripts/sync_installs.py +29 -0
- package/scripts/template_cli.py +127 -0
- package/scripts/text_lexicon.py +72 -0
- package/scripts/tfidf_router.py +109 -37
- package/scripts/time_utils.py +233 -0
- package/scripts/topic_research_profiles.py +643 -0
- package/scripts/train.py +737 -0
- package/scripts/tweet.py +596 -0
- package/scripts/url_canon.py +217 -0
- package/scripts/url_optimize.py +56 -0
- package/scripts/url_safety.py +236 -0
- package/scripts/usage_log.py +116 -0
- package/scripts/usage_log_clean.py +113 -0
- package/scripts/v2ex_nodes.py +311 -0
- package/scripts/variant_recall.py +188 -0
- package/scripts/watch.py +205 -0
- package/scripts/wechat_article.py +258 -0
- package/scripts/wide_research.py +447 -0
- package/scripts/wx.py +349 -0
- package/scripts/x_article_fetch.py +141 -0
- package/scripts/x_search.py +234 -0
- package/scripts/x_trending.py +189 -0
- package/scripts/yaml_load.py +67 -0
- package/scripts/zhihu_quota.py +139 -0
- package/sub-skills/ego-search/SKILL.md +253 -0
- package/sub-skills/ego-search/scripts/ego_search.py +800 -0
- package/sub-skills/ego-search/scripts/merge.py +226 -0
- package/sub-skills/ego-search/scripts/quality.py +64 -0
- package/sub-skills/ego-search/scripts/runtime.py +172 -0
- package/sub-skills/ego-search/scripts/safety.py +109 -0
- package/sub-skills/ego-search/scripts/serp_spec.py +109 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +374 -0
- package/sub-skills/js-run/SKILL.md +67 -0
- package/sub-skills/js-run/scripts/jsrun.py +112 -0
- package/sub-skills/js-run/scripts/shim.js +188 -0
- package/sub-skills/local-search/SKILL.md +50 -53
- package/sub-skills/local-search/bm25.py +186 -0
- package/sub-skills/local-search/cli_runner.py +331 -0
- package/sub-skills/local-search/config.yaml +152 -55
- package/sub-skills/local-search/engine_registry.py +91 -26
- package/sub-skills/local-search/{health_check.py → local_health_check.py} +140 -10
- package/sub-skills/local-search/local_search_adapter.py +13 -2
- package/sub-skills/local-search/parse_maps.yaml +40 -42
- package/sub-skills/local-search/parsers.py +328 -0
- package/sub-skills/local-search/search_v3.py +716 -242
- package/sub-skills/local-search/smart_router.py +47 -7
- package/sub-skills/local-seek/SKILL.md +110 -0
- package/sub-skills/local-seek/config/domains.yaml +20 -0
- package/sub-skills/local-seek/scripts/eval_rank.py +216 -0
- package/sub-skills/local-seek/scripts/eval_seek.py +224 -0
- package/sub-skills/local-seek/scripts/seek.py +1465 -0
- package/sub-skills/local-seek/scripts/seek_frecency.py +126 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +430 -0
- package/sub-skills/local-seek/scripts/seek_rank.py +197 -0
package/scripts/mcp_server.py
CHANGED
|
@@ -1,437 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""
|
|
3
|
-
mcp_server.py — Argo MCP
|
|
3
|
+
mcp_server.py — Argo MCP 服务入口(P2-4 拆分后为聚合薄壳)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
原 970 行单文件已拆为三模块,本文件只做聚合与兼容导出:
|
|
6
|
+
mcp_tools.py 工具 schema 唯一来源(14 个工具;tools/list 默认 CORE 3 个)
|
|
7
|
+
mcp_handlers.py 路径引导 + 延迟导入 + 结果压缩 + execute_tool + 预热
|
|
8
|
+
mcp_transport.py JSON-RPC 分发(handle_rpc)+ stdio 帧协议(run_stdio)
|
|
9
|
+
|
|
10
|
+
对外行为不变:`python3 mcp_server.py` 启动 stdio 服务,
|
|
11
|
+
`--test` 走本地测试;`from mcp_server import TOOLS/execute_tool/handle_rpc`
|
|
12
|
+
等历史 import 面照常可用。
|
|
7
13
|
|
|
8
14
|
用法:
|
|
9
15
|
python3 mcp_server.py # 启动 MCP stdio 服务
|
|
10
16
|
python3 mcp_server.py --test # 本地测试模式
|
|
17
|
+
python3 mcp_server.py --call <tool> '<json-args>'
|
|
18
|
+
# CLI 单发:与 stdio 共用 execute_tool
|
|
19
|
+
# (同引擎、同压缩、同守卫),供 DSH
|
|
20
|
+
# 原生工具等免帧协议调用方复用
|
|
11
21
|
"""
|
|
12
22
|
|
|
13
23
|
from __future__ import annotations
|
|
14
24
|
|
|
15
25
|
import json
|
|
16
26
|
import os
|
|
27
|
+
import subprocess # noqa: F401 — 兼容面:测试 monkeypatch mcp_server.subprocess.run
|
|
17
28
|
import sys
|
|
18
|
-
import traceback
|
|
19
|
-
from typing import Any
|
|
20
|
-
|
|
21
|
-
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
22
|
-
sys.path.insert(0, SCRIPT_DIR)
|
|
23
|
-
|
|
24
|
-
# 进程级共享缓存:同一 MCP 会话中 search/evidence/research 共用
|
|
25
|
-
_cache_instance = None
|
|
26
|
-
|
|
27
|
-
def _get_cache():
|
|
28
|
-
global _cache_instance
|
|
29
|
-
if _cache_instance is None:
|
|
30
|
-
from cache import SearchCache
|
|
31
|
-
_cache_instance = SearchCache()
|
|
32
|
-
return _cache_instance
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"minimum": 1,
|
|
58
|
-
"maximum": 20
|
|
59
|
-
},
|
|
60
|
-
"depth": {
|
|
61
|
-
"type": "string",
|
|
62
|
-
"enum": ["fast", "balanced", "deep"],
|
|
63
|
-
"description": "搜索深度(默认 fast)",
|
|
64
|
-
"default": "fast"
|
|
65
|
-
},
|
|
66
|
-
"mode": {
|
|
67
|
-
"type": "string",
|
|
68
|
-
"enum": ["fast", "auto", "deep", "budget"],
|
|
69
|
-
"description": "预算模式:fast=免费优先, auto=成本感知, deep=质量优先, budget=配额控制(默认 auto)",
|
|
70
|
-
"default": "auto"
|
|
71
|
-
},
|
|
72
|
-
"skip_cache": {
|
|
73
|
-
"type": "boolean",
|
|
74
|
-
"description": "跳过缓存(默认 false)",
|
|
75
|
-
"default": False
|
|
76
|
-
},
|
|
77
|
-
"summary": {
|
|
78
|
-
"type": "boolean",
|
|
79
|
-
"description": "精简模式:snippet 截断到 80 字符,节省 LLM token(默认 false)",
|
|
80
|
-
"default": False
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"required": ["query"]
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"name": "argo_research",
|
|
88
|
-
"description": "深度研究:将复杂查询分解为子问题,多源并行采集,输出综合报告+引用+知识缺口。适用于学术综述、事实核查、竞品分析、技术选型等需要多步搜索的场景。",
|
|
89
|
-
"inputSchema": {
|
|
90
|
-
"type": "object",
|
|
91
|
-
"properties": {
|
|
92
|
-
"query": {
|
|
93
|
-
"type": "string",
|
|
94
|
-
"description": "研究查询(可以是复杂的、多步骤的问题)"
|
|
95
|
-
},
|
|
96
|
-
"num_sub_queries": {
|
|
97
|
-
"type": "integer",
|
|
98
|
-
"description": "子查询数量(默认4,最大8)",
|
|
99
|
-
"default": 4,
|
|
100
|
-
"minimum": 2,
|
|
101
|
-
"maximum": 8
|
|
102
|
-
},
|
|
103
|
-
"max_results": {
|
|
104
|
-
"type": "integer",
|
|
105
|
-
"description": "每个子查询最大结果数(默认5)",
|
|
106
|
-
"default": 5
|
|
107
|
-
},
|
|
108
|
-
"depth": {
|
|
109
|
-
"type": "string",
|
|
110
|
-
"enum": ["fast", "balanced", "deep"],
|
|
111
|
-
"description": "搜索深度(默认balanced)",
|
|
112
|
-
"default": "balanced"
|
|
113
|
-
},
|
|
114
|
-
"mode": {
|
|
115
|
-
"type": "string",
|
|
116
|
-
"enum": ["fast", "auto", "deep", "budget"],
|
|
117
|
-
"description": "预算模式(默认auto)",
|
|
118
|
-
"default": "auto"
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
"required": ["query"]
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"name": "argo_evidence",
|
|
126
|
-
"description": "来源可信度评估:对搜索结果进行权威性+时效性+交叉验证的综合评分,输出每个结果的可信度分解。适用于事实核查、高后果决策、学术引用等需要评估来源可靠性的场景。",
|
|
127
|
-
"inputSchema": {
|
|
128
|
-
"type": "object",
|
|
129
|
-
"properties": {
|
|
130
|
-
"query": {
|
|
131
|
-
"type": "string",
|
|
132
|
-
"description": "搜索查询词(用于交叉验证)"
|
|
133
|
-
},
|
|
134
|
-
"results_json": {
|
|
135
|
-
"type": "string",
|
|
136
|
-
"description": "搜索结果 JSON 字符串(可选;为空时自动调用 super_search 搜索)。格式:{\"results\": [{\"title\": \"...\", \"url\": \"...\", \"snippet\": \"...\", \"source\": \"...\", \"score\": 0.8}]}"
|
|
137
|
-
},
|
|
138
|
-
"max_results": {
|
|
139
|
-
"type": "integer",
|
|
140
|
-
"description": "自动搜索时的最大结果数(默认 10,仅在 results_json 为空时有效)",
|
|
141
|
-
"default": 10
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
"required": ["query"]
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
"name": "argo_clarify",
|
|
149
|
-
"description": "意图消歧:分析查询中的歧义词、多义实体,给出意图分类和推荐搜索策略。适用于查询含歧义词(如「苹果」=公司/水果、「Python」=语言/蛇)或意图不明确的场景。",
|
|
150
|
-
"inputSchema": {
|
|
151
|
-
"type": "object",
|
|
152
|
-
"properties": {
|
|
153
|
-
"query": {
|
|
154
|
-
"type": "string",
|
|
155
|
-
"description": "需要消歧的搜索查询"
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
"required": ["query"]
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
"name": "argo_crawl",
|
|
163
|
-
"description": "站点级爬取:通过 sitemap.xml 或 BFS 策略批量抓取站点页面,输出页面 URL、正文片段和深度。适用于整站内容审计、站内多页对比、批量抓取等场景。",
|
|
164
|
-
"inputSchema": {
|
|
165
|
-
"type": "object",
|
|
166
|
-
"properties": {
|
|
167
|
-
"url": {
|
|
168
|
-
"type": "string",
|
|
169
|
-
"description": "目标站点根 URL(如 https://docs.python.org/)"
|
|
170
|
-
},
|
|
171
|
-
"strategy": {
|
|
172
|
-
"type": "string",
|
|
173
|
-
"enum": ["sitemap", "bfs"],
|
|
174
|
-
"description": "爬取策略(默认 bfs)",
|
|
175
|
-
"default": "bfs"
|
|
176
|
-
},
|
|
177
|
-
"max_pages": {
|
|
178
|
-
"type": "integer",
|
|
179
|
-
"description": "最大抓取页面数(默认 10,sitemap 策略默认 20)",
|
|
180
|
-
"default": 10,
|
|
181
|
-
"minimum": 1,
|
|
182
|
-
"maximum": 50
|
|
183
|
-
},
|
|
184
|
-
"max_depth": {
|
|
185
|
-
"type": "integer",
|
|
186
|
-
"description": "BFS 最大深度(默认 2)",
|
|
187
|
-
"default": 2,
|
|
188
|
-
"minimum": 1,
|
|
189
|
-
"maximum": 5
|
|
190
|
-
},
|
|
191
|
-
"timeout": {
|
|
192
|
-
"type": "integer",
|
|
193
|
-
"description": "单页超时秒数(默认 8)",
|
|
194
|
-
"default": 8,
|
|
195
|
-
"minimum": 3,
|
|
196
|
-
"maximum": 30
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
"required": ["url"]
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
"name": "argo_extract",
|
|
204
|
-
"description": "结构化数据提取:从页面 HTML 中抽取表格、<meta> 元数据、OpenGraph、JSON-LD 等结构化信息。适用于价格表抽取、SEO 元数据分析、富媒体结构化数据解析等场景。",
|
|
205
|
-
"inputSchema": {
|
|
206
|
-
"type": "object",
|
|
207
|
-
"properties": {
|
|
208
|
-
"url": {
|
|
209
|
-
"type": "string",
|
|
210
|
-
"description": "目标页面 URL"
|
|
211
|
-
},
|
|
212
|
-
"mode": {
|
|
213
|
-
"type": "string",
|
|
214
|
-
"enum": ["tables", "metadata", "jsonld", "all"],
|
|
215
|
-
"description": "提取模式(默认 all)",
|
|
216
|
-
"default": "all"
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
"required": ["url"]
|
|
220
|
-
}
|
|
221
|
-
},
|
|
30
|
+
from mcp_handlers import (
|
|
31
|
+
_module_cache,
|
|
32
|
+
_compact_research_result,
|
|
33
|
+
_compact_search_result,
|
|
34
|
+
_dumps,
|
|
35
|
+
_resolve_research_profile,
|
|
36
|
+
_search_social_platforms,
|
|
37
|
+
execute_tool,
|
|
38
|
+
)
|
|
39
|
+
from mcp_tools import TOOLS
|
|
40
|
+
from mcp_transport import handle_rpc, run_stdio
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"TOOLS",
|
|
44
|
+
"execute_tool",
|
|
45
|
+
"handle_rpc",
|
|
46
|
+
"run_stdio",
|
|
47
|
+
"_module_cache",
|
|
48
|
+
"_compact_search_result",
|
|
49
|
+
"_compact_research_result",
|
|
50
|
+
"_dumps",
|
|
51
|
+
"_resolve_research_profile",
|
|
52
|
+
"_search_social_platforms",
|
|
222
53
|
]
|
|
223
54
|
|
|
224
55
|
|
|
225
|
-
# ── 工具执行 ──────────────────────────────────────────────────────────────────
|
|
226
|
-
|
|
227
|
-
def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
228
|
-
"""执行 MCP 工具。"""
|
|
229
|
-
try:
|
|
230
|
-
if name == "argo_search":
|
|
231
|
-
from search import super_search
|
|
232
|
-
result = super_search(
|
|
233
|
-
query=arguments["query"],
|
|
234
|
-
engine=arguments.get("engine", "auto"),
|
|
235
|
-
n=arguments.get("max_results", 5),
|
|
236
|
-
skip_cache=arguments.get("skip_cache", False),
|
|
237
|
-
timeout=arguments.get("timeout", 10),
|
|
238
|
-
depth=arguments.get("depth", "fast"),
|
|
239
|
-
mode=arguments.get("mode", "auto"),
|
|
240
|
-
cache=_get_cache(),
|
|
241
|
-
)
|
|
242
|
-
# 精简模式:截断 snippet
|
|
243
|
-
if arguments.get("summary", False):
|
|
244
|
-
for r in result.get("results", []):
|
|
245
|
-
if r.get("snippet"):
|
|
246
|
-
r["snippet"] = r["snippet"][:80]
|
|
247
|
-
return {"content": [{"type": "text", "text": json.dumps(result, ensure_ascii=False, indent=2)}]}
|
|
248
|
-
|
|
249
|
-
elif name == "argo_research":
|
|
250
|
-
from research import deep_research
|
|
251
|
-
result = deep_research(
|
|
252
|
-
query=arguments["query"],
|
|
253
|
-
num_sub_queries=arguments.get("num_sub_queries", 4),
|
|
254
|
-
max_results=arguments.get("max_results", 5),
|
|
255
|
-
depth=arguments.get("depth", "balanced"),
|
|
256
|
-
mode=arguments.get("mode", "auto"),
|
|
257
|
-
)
|
|
258
|
-
return {"content": [{"type": "text", "text": json.dumps(result, ensure_ascii=False, indent=2)}]}
|
|
259
|
-
|
|
260
|
-
elif name == "argo_evidence":
|
|
261
|
-
from evidence import compute_credibility
|
|
262
|
-
results_json_str = arguments.get("results_json", "")
|
|
263
|
-
# results_json 为空时自动调用 super_search 获取结果
|
|
264
|
-
if not results_json_str or not results_json_str.strip():
|
|
265
|
-
from search import super_search
|
|
266
|
-
search_result = super_search(
|
|
267
|
-
query=arguments["query"],
|
|
268
|
-
n=arguments.get("max_results", 10),
|
|
269
|
-
depth="fast",
|
|
270
|
-
mode="auto",
|
|
271
|
-
cache=_get_cache(),
|
|
272
|
-
)
|
|
273
|
-
results = search_result.get("results", [])
|
|
274
|
-
else:
|
|
275
|
-
results_data = json.loads(results_json_str)
|
|
276
|
-
results = results_data.get("results", [])
|
|
277
|
-
result = compute_credibility(results, arguments["query"])
|
|
278
|
-
return {"content": [{"type": "text", "text": json.dumps(result, ensure_ascii=False, indent=2)}]}
|
|
279
|
-
|
|
280
|
-
elif name == "argo_clarify":
|
|
281
|
-
from clarify import analyze_query, recommend_routing
|
|
282
|
-
analysis = analyze_query(arguments["query"])
|
|
283
|
-
routing = recommend_routing(analysis)
|
|
284
|
-
analysis["routing"] = routing
|
|
285
|
-
return {"content": [{"type": "text", "text": json.dumps(analysis, ensure_ascii=False, indent=2)}]}
|
|
286
|
-
|
|
287
|
-
elif name == "argo_crawl":
|
|
288
|
-
from crawl import crawl_bfs, crawl_sitemap
|
|
289
|
-
strategy = arguments.get("strategy", "bfs")
|
|
290
|
-
max_pages = arguments.get("max_pages", 10)
|
|
291
|
-
max_depth = arguments.get("max_depth", 2)
|
|
292
|
-
timeout = arguments.get("timeout", 8)
|
|
293
|
-
if strategy == "sitemap":
|
|
294
|
-
result = crawl_sitemap(arguments["url"], max_pages=max_pages, timeout=timeout)
|
|
295
|
-
else:
|
|
296
|
-
result = crawl_bfs(arguments["url"], max_pages=max_pages, max_depth=max_depth, timeout=timeout)
|
|
297
|
-
return {"content": [{"type": "text", "text": json.dumps(result, ensure_ascii=False, indent=2)}]}
|
|
298
|
-
|
|
299
|
-
elif name == "argo_extract":
|
|
300
|
-
from extract import extract_tables, extract_metadata, extract_jsonld
|
|
301
|
-
from fetch import fetch_page
|
|
302
|
-
mode = arguments.get("mode", "all")
|
|
303
|
-
fetch_result = fetch_page(arguments["url"], max_chars=50000, timeout=15, raw=True)
|
|
304
|
-
if not fetch_result["success"]:
|
|
305
|
-
return {"content": [{"type": "text", "text": json.dumps({"error": fetch_result.get("error", "fetch failed")}, ensure_ascii=False)}], "isError": True}
|
|
306
|
-
html = fetch_result["html"]
|
|
307
|
-
output = {}
|
|
308
|
-
if mode in ("tables", "all"):
|
|
309
|
-
output["tables"] = extract_tables(html)
|
|
310
|
-
if mode in ("metadata", "all"):
|
|
311
|
-
output["metadata"] = extract_metadata(html)
|
|
312
|
-
if mode in ("jsonld", "all"):
|
|
313
|
-
output["jsonld"] = extract_jsonld(html)
|
|
314
|
-
output["url"] = fetch_result["url"]
|
|
315
|
-
return {"content": [{"type": "text", "text": json.dumps(output, ensure_ascii=False, indent=2)}]}
|
|
316
|
-
|
|
317
|
-
else:
|
|
318
|
-
return {"error": {"code": -32601, "message": f"Unknown tool: {name}"}}
|
|
319
|
-
|
|
320
|
-
except Exception as e:
|
|
321
|
-
return {
|
|
322
|
-
"content": [{"type": "text", "text": json.dumps({"error": {"code": -32000, "message": f"{type(e).__name__}: {e}"}}, ensure_ascii=False)}],
|
|
323
|
-
"isError": True
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
# ── MCP JSON-RPC 处理 ────────────────────────────────────────────────────────
|
|
328
|
-
|
|
329
|
-
def handle_rpc(method: str, params: dict[str, Any]) -> dict[str, Any]:
|
|
330
|
-
"""处理 JSON-RPC 请求。"""
|
|
331
|
-
if method == "initialize":
|
|
332
|
-
return {
|
|
333
|
-
"protocolVersion": "2024-11-05",
|
|
334
|
-
"capabilities": {"tools": {"listChanged": False}},
|
|
335
|
-
"serverInfo": {
|
|
336
|
-
"name": "argo",
|
|
337
|
-
"version": "1.0.1"
|
|
338
|
-
},
|
|
339
|
-
"instructions": "Argo MCP 提供 6 个工具:argo_search(47 引擎统一搜索)、argo_research(深度研究)、argo_evidence(可信度评估)、argo_clarify(意图消歧)、argo_crawl(站点爬取)、argo_extract(结构化数据提取)。底层使用 47 个搜索引擎的统一搜索基础设施,支持 TF-IDF 语义路由、RRF 多引擎融合、Bocha 语义精排、双层缓存和成本感知预算控制。"
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
elif method == "tools/list":
|
|
343
|
-
return {"tools": TOOLS}
|
|
344
|
-
|
|
345
|
-
elif method == "tools/call":
|
|
346
|
-
tool_name = params.get("name", "")
|
|
347
|
-
arguments = params.get("arguments", {})
|
|
348
|
-
return execute_tool(tool_name, arguments)
|
|
349
|
-
|
|
350
|
-
elif method == "ping":
|
|
351
|
-
return {}
|
|
352
|
-
|
|
353
|
-
elif method.startswith("notifications/"):
|
|
354
|
-
# 通知消息无需回复
|
|
355
|
-
return None
|
|
356
|
-
|
|
357
|
-
else:
|
|
358
|
-
return {"error": {"code": -32601, "message": f"Method not found: {method}"}}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
def run_stdio():
|
|
362
|
-
"""运行 MCP stdio 服务。MCP 帧协议:Content-Length: N\\r\\n\\r\\n{json}"""
|
|
363
|
-
import sys, os, time as _time
|
|
364
|
-
try:
|
|
365
|
-
with open(os.path.expanduser("~/.kimi/argo_diag.log"), "a") as _log:
|
|
366
|
-
_log.write(f"=== PID={os.getpid()} ENTER run_stdio {_time.strftime('%H:%M:%S')} ===\n")
|
|
367
|
-
_log.write(f"python={sys.executable} cwd={os.getcwd()}\n")
|
|
368
|
-
_log.flush()
|
|
369
|
-
except: pass
|
|
370
|
-
|
|
371
|
-
while True:
|
|
372
|
-
try:
|
|
373
|
-
# 读取 Content-Length 头
|
|
374
|
-
header = sys.stdin.buffer.readline()
|
|
375
|
-
if not header:
|
|
376
|
-
break # EOF
|
|
377
|
-
header_str = header.decode("utf-8", errors="replace").strip()
|
|
378
|
-
if not header_str:
|
|
379
|
-
continue
|
|
380
|
-
if not header_str.startswith("Content-Length:"):
|
|
381
|
-
# 兼容行模式(某些客户端不发 Content-Length)
|
|
382
|
-
try:
|
|
383
|
-
request = json.loads(header_str)
|
|
384
|
-
except json.JSONDecodeError:
|
|
385
|
-
_send_error(None, -32700, "Parse error")
|
|
386
|
-
continue
|
|
387
|
-
else:
|
|
388
|
-
length = int(header_str.split(":")[1].strip())
|
|
389
|
-
sys.stdin.buffer.readline() # skip blank line
|
|
390
|
-
body = sys.stdin.buffer.read(length).decode("utf-8")
|
|
391
|
-
request = json.loads(body)
|
|
392
|
-
|
|
393
|
-
method = request.get("method", "")
|
|
394
|
-
params = request.get("params", {})
|
|
395
|
-
request_id = request.get("id")
|
|
396
|
-
|
|
397
|
-
response = handle_rpc(method, params)
|
|
398
|
-
|
|
399
|
-
# 通知消息无需回复
|
|
400
|
-
if response is None:
|
|
401
|
-
continue
|
|
402
|
-
|
|
403
|
-
if request_id is not None:
|
|
404
|
-
response["jsonrpc"] = "2.0"
|
|
405
|
-
response["id"] = request_id
|
|
406
|
-
_send_response(response)
|
|
407
|
-
|
|
408
|
-
except json.JSONDecodeError:
|
|
409
|
-
_send_error(None, -32700, "Parse error")
|
|
410
|
-
except Exception as e:
|
|
411
|
-
_send_error(None, -32000, f"Internal error: {e}")
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
def _send_response(response: dict):
|
|
415
|
-
"""发送 MCP 帧响应。"""
|
|
416
|
-
data = json.dumps(response, ensure_ascii=False)
|
|
417
|
-
encoded = data.encode("utf-8")
|
|
418
|
-
sys.stdout.buffer.write(f"Content-Length: {len(encoded)}\r\n\r\n".encode())
|
|
419
|
-
sys.stdout.buffer.write(encoded)
|
|
420
|
-
sys.stdout.buffer.flush()
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
def _send_error(request_id, code: int, message: str):
|
|
424
|
-
"""发送 JSON-RPC 错误响应。"""
|
|
425
|
-
resp = {
|
|
426
|
-
"jsonrpc": "2.0",
|
|
427
|
-
"id": request_id,
|
|
428
|
-
"error": {"code": code, "message": message}
|
|
429
|
-
}
|
|
430
|
-
_send_response(resp)
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
# ── 测试模式 ──────────────────────────────────────────────────────────────────
|
|
434
|
-
|
|
435
56
|
def test_mode():
|
|
436
57
|
"""本地测试。"""
|
|
437
58
|
print("=== Argo MCP 工具测试 ===\n")
|
|
@@ -447,6 +68,18 @@ def test_mode():
|
|
|
447
68
|
print(result["content"][0]["text"][:500])
|
|
448
69
|
print()
|
|
449
70
|
|
|
71
|
+
# 测试 local search(本地文件)——路径用安装锚点(argo 根目录),
|
|
72
|
+
# 不写死 ~/.agents/skills 等主机路径(SKILL.md 禁止)。
|
|
73
|
+
argo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
74
|
+
print("--- argo_local_search 测试 ---")
|
|
75
|
+
result = execute_tool("argo_local_search", {
|
|
76
|
+
"query": "数据抓取",
|
|
77
|
+
"path": argo_root,
|
|
78
|
+
"max_results": 3,
|
|
79
|
+
})
|
|
80
|
+
print(result["content"][0]["text"][:500])
|
|
81
|
+
print()
|
|
82
|
+
|
|
450
83
|
# 测试 clarify
|
|
451
84
|
print("--- clarify 测试 ---")
|
|
452
85
|
result = execute_tool("argo_clarify", {"query": "Python 吞苹果 兼容吗"})
|
|
@@ -472,17 +105,90 @@ def test_mode():
|
|
|
472
105
|
sample_results = json.dumps({
|
|
473
106
|
"results": [
|
|
474
107
|
{"title": "Python docs", "url": "https://docs.python.org", "snippet": "Official Python documentation", "source": "wikipedia", "score": 0.9},
|
|
475
|
-
{"title": "Some blog", "url": "https://random-blog.com/python", "snippet": "Python tutorial", "source": "
|
|
108
|
+
{"title": "Some blog", "url": "https://random-blog.com/python", "snippet": "Python tutorial", "source": "byted", "score": 0.6},
|
|
476
109
|
]
|
|
477
110
|
})
|
|
478
111
|
result = execute_tool("argo_evidence", {"query": "Python tutorial", "results_json": sample_results})
|
|
479
112
|
print(result["content"][0]["text"][:500])
|
|
480
113
|
|
|
481
114
|
|
|
115
|
+
def call_mode(tool: str, payload: str) -> int:
|
|
116
|
+
"""CLI 单发(--call <tool> '<json-args>')。
|
|
117
|
+
|
|
118
|
+
与 stdio 服务共用 execute_tool,stdout 只输出结果 JSON(isError 时
|
|
119
|
+
退出码 1);不输出任何日志到 stdout,保证调用方解析不被污染。
|
|
120
|
+
"""
|
|
121
|
+
try:
|
|
122
|
+
arguments = json.loads(payload) if payload.strip() else {}
|
|
123
|
+
except json.JSONDecodeError as e:
|
|
124
|
+
print(_dumps({"error": f"invalid --call payload: {e}"}))
|
|
125
|
+
return 2
|
|
126
|
+
if not isinstance(arguments, dict):
|
|
127
|
+
print(_dumps({"error": "--call payload must be a JSON object"}))
|
|
128
|
+
return 2
|
|
129
|
+
result = execute_tool(tool, arguments)
|
|
130
|
+
print(_dumps(result))
|
|
131
|
+
# isError 是工具级错误;裸 {"error": {...}} 是协议级错误(如未知工具)。
|
|
132
|
+
# 两者都必须非零退出,否则调用方(如 DSH 原生工具)把错误当成功渲染。
|
|
133
|
+
is_error = bool(result.get("isError")) or (
|
|
134
|
+
isinstance(result.get("error"), dict) and "content" not in result)
|
|
135
|
+
return 1 if is_error else 0
|
|
136
|
+
|
|
137
|
+
|
|
482
138
|
# ── 入口 ──────────────────────────────────────────────────────────────────────
|
|
483
139
|
|
|
484
|
-
|
|
485
|
-
|
|
140
|
+
def main(argv: list[str] | None = None) -> int:
|
|
141
|
+
args = sys.argv[1:] if argv is None else argv
|
|
142
|
+
# Windows GBK 防线(PEP 540):非 UTF-8 模式直接跑本文件时,重新以
|
|
143
|
+
# -X utf8 启动自己,保证中文 JSON 读取与 stderr 输出不因控制台编码崩。
|
|
144
|
+
if not sys.flags.utf8_mode and os.name == "nt":
|
|
145
|
+
import subprocess as _sp
|
|
146
|
+
_rc = _sp.run(
|
|
147
|
+
[sys.executable, "-X", "utf8", __file__, *args],
|
|
148
|
+
env={**os.environ, "PYTHONUTF8": "1"},
|
|
149
|
+
).returncode
|
|
150
|
+
return _rc
|
|
151
|
+
# env 文件 → os.environ 同步(只填缺失,不覆盖已有值):非 mcp_launch.sh
|
|
152
|
+
# 启动(直跑本文件/裸宿主直连)时密钥仍能到位,读取方零改动
|
|
153
|
+
try:
|
|
154
|
+
from engine_env import sync_envfile_to_environ
|
|
155
|
+
sync_envfile_to_environ()
|
|
156
|
+
except Exception as e:
|
|
157
|
+
# 静默 pass 的代价:env 文件同步失败(权限/格式/IO)时,所有需密钥
|
|
158
|
+
# 的引擎在此长驻进程里静默返回空——正是 engine_env 注释反复警惕的
|
|
159
|
+
# 「装了没通电」形态。失败不阻断启动,但必须可见。
|
|
160
|
+
import logging
|
|
161
|
+
logging.getLogger("unified_search").warning(
|
|
162
|
+
"env 文件同步失败(%s):依赖密钥的引擎可能静默返回空——"
|
|
163
|
+
"请检查 ~/.config/argo/env 的权限与格式", e)
|
|
164
|
+
# 未知旗标显式报错(exit 2):此前任何拼错的 flag 都静默落进 stdio 模式
|
|
165
|
+
# ——stdio 挂着等 stdin,调用方看到的是「卡死」而不是「参数错了」。
|
|
166
|
+
_skip = 0
|
|
167
|
+
for _a in args:
|
|
168
|
+
if _skip:
|
|
169
|
+
_skip -= 1
|
|
170
|
+
continue
|
|
171
|
+
if _a == "--call":
|
|
172
|
+
_skip = 2 # 工具名与 JSON payload 是它的操作数
|
|
173
|
+
continue
|
|
174
|
+
if _a.startswith("-") and _a != "--test":
|
|
175
|
+
print(_dumps({"error": f"未知参数: {_a}(支持 --test / --call <tool> [json];无参数 = stdio 服务)"}))
|
|
176
|
+
return 2
|
|
177
|
+
if "--test" in args:
|
|
486
178
|
test_mode()
|
|
179
|
+
return 0
|
|
180
|
+
elif "--call" in args:
|
|
181
|
+
_i = args.index("--call")
|
|
182
|
+
_tool = args[_i + 1] if len(args) > _i + 1 else ""
|
|
183
|
+
if not _tool:
|
|
184
|
+
print(_dumps({"error": "usage: mcp_server.py --call <tool> [json-args]"}))
|
|
185
|
+
return 2
|
|
186
|
+
_payload = args[_i + 2] if len(args) > _i + 2 else "{}"
|
|
187
|
+
return call_mode(_tool, _payload)
|
|
487
188
|
else:
|
|
488
189
|
run_stdio()
|
|
190
|
+
return 0
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if __name__ == "__main__":
|
|
194
|
+
sys.exit(main())
|