Repository navigation
Expand file tree
/
Copy pathserver.py
More file actions
180 lines (162 loc) · 4.81 KB
/
Copy pathserver.py
File metadata and controls
180 lines (162 loc) · 4.81 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""Kitsune MCP — entry point and re-export facade.
All logic lives in the kitsune_mcp package. This file:
1. Loads .env before any kitsune_mcp imports read os.getenv() at module level.
2. Imports all modules so their @mcp.tool() decorators register with the shared mcp instance.
3. Prunes tools based on KITSUNE_TOOLS env var (default: lean profile).
4. Re-exports public names so existing tests (from server import ...) continue to work.
KITSUNE_TOOLS env var controls which tools are registered:
(not set) — lean profile: status, search, auth, shapeshift, call, auto,
connect, release, reload, test (10 tools, ~1,895 tokens overhead)
KITSUNE_TOOLS=all — all tools (forge / evaluator mode, ~3,510 tokens)
KITSUNE_TOOLS=shapeshift,call — exactly those tools
"""
import contextlib
import sys
from dotenv import load_dotenv
# Must run before kitsune_mcp.credentials is imported.
# Load order: project-local .env first (lower priority), then $KITSUNE_HOME/.env
# (higher priority — wins regardless of CWD so daemon launches work correctly).
from kitsune_mcp.paths import kitsune_home # noqa: E402
load_dotenv() # CWD .env (project-local)
load_dotenv(kitsune_home() / ".env", override=True) # canonical store wins
from kitsune_mcp.app import mcp # noqa: E402, F401
from kitsune_mcp.constants import * # noqa: E402, F401, F403
from kitsune_mcp.credentials import ( # noqa: E402, F401
ENV_PATH,
_credentials_guide,
_credentials_inspect_block,
_dotenv_revision,
_reload_dotenv,
_resolve_config,
_save_to_env,
_to_env_var,
)
from kitsune_mcp.gateway import ( # noqa: E402, F401
AbsorbedServer,
ClientConfig,
_find_mcp_configs,
_harvest_credentials,
_load_absorbed_servers,
_parse_mcp_servers,
_restore_config,
_save_absorbed_servers,
_to_server_info,
_write_exclusive_config,
_write_project_config,
)
from kitsune_mcp.official_registry import OfficialMCPRegistry # noqa: E402, F401
from kitsune_mcp.probe import ( # noqa: E402, F401
_ENV_VAR_RE,
_LOCAL_URL_RE,
_classify_provider,
_doc_uri_priority,
_format_setup_guide,
_probe_requirements,
)
from kitsune_mcp.registry import ( # noqa: E402, F401
_CACHE_TTL_SEARCH,
_CACHE_TTL_SERVER,
AbsorbedRegistry,
BaseRegistry,
GitHubRegistry,
GlamaRegistry,
McpRegistryIO,
MultiRegistry,
NpmRegistry,
PyPIRegistry,
ServerInfo,
_dedup_key,
_detect_github_install_cmd,
_registry,
_relevance_score,
_works_now_score,
)
from kitsune_mcp.session import ( # noqa: E402, F401
SKILLS_PATH,
_load_skills,
_restore_crafted_tools,
_save_skills,
_save_state,
session,
)
from kitsune_mcp.shapeshift import ( # noqa: E402, F401
_do_shed,
_json_type_to_py,
_make_proxy,
_register_proxy_prompts,
_register_proxy_resources,
_register_proxy_tools,
)
from kitsune_mcp.tools import ( # noqa: E402, F401
_BASE_TOOL_NAMES,
_state,
auth,
auto,
bench,
call,
compare,
connect,
craft,
fetch,
inspect,
key,
prewarm,
release,
run,
search,
setup,
shapeshift,
shiftback,
status,
test,
)
from kitsune_mcp.transport import ( # noqa: E402, F401
BaseTransport,
DockerTransport,
HTTPSSETransport,
PersistentStdioTransport,
StdioTransport,
WebSocketTransport,
_evict_stale_pool_entries,
_ping,
_PoolEntry,
_process_pool,
_read_stdio_response,
_validate_install_cmd,
)
from kitsune_mcp.utils import ( # noqa: E402, F401
_clean_response,
_estimate_tokens,
_extract_content,
_get_http_client,
_rss_mb,
_strip_html,
_truncate,
_try_axonmcp,
)
# ── Tool profile selection ────────────────────────────────────────────────────
# All tools registered above via @mcp.tool(). Prune to the requested profile.
_LEAN_TOOLS = _state._LEAN_TOOL_NAMES
_active_tools = _state._active_tool_names()
for _t in _BASE_TOOL_NAMES - _active_tools:
with contextlib.suppress(Exception):
mcp.remove_tool(_t)
_restore_crafted_tools()
def _first_run_hint() -> None:
"""Print a one-time star hint to stderr (stdout is the MCP stdio channel)."""
marker = kitsune_home() / ".first_run_done"
with contextlib.suppress(OSError):
if marker.exists():
return
marker.parent.mkdir(parents=True, exist_ok=True)
marker.touch()
print(
"🦊 Kitsune MCP is running. If it saves you a client restart, "
"a ⭐ helps others find it: https://github.com/kaiser-data/kitsune-mcp",
file=sys.stderr,
)
def main() -> None:
_first_run_hint()
mcp.run()
if __name__ == "__main__":
main()