-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
303 lines (252 loc) · 10 KB
/
Copy pathmodels.py
File metadata and controls
303 lines (252 loc) · 10 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
"""Pydantic input/output models for all MCP tools.
These models define the tool contracts. FastMCP auto-generates outputSchema
from BaseModel return types, providing structuredContent for free (SRVR-05).
"""
from __future__ import annotations
from typing import Literal
from pydantic import BaseModel, Field
# --- search_docs models ---
class SearchDocsInput(BaseModel):
"""Input parameters for search_docs tool."""
query: str = Field(
max_length=500,
description="Search query - Python symbol (asyncio.TaskGroup) or concept (parse json)",
)
version: str | None = Field(
default=None,
description="Python version (e.g. '3.13'). Defaults to latest.",
)
kind: Literal["auto", "page", "symbol", "section", "example"] = Field(
default="auto",
description=(
"Search type. Use 'symbol' for API lookups, "
"'example' for code samples, 'auto' otherwise."
),
)
max_results: int = Field(
default=5,
ge=1,
le=20,
description="Maximum number of results to return.",
)
class SymbolHit(BaseModel):
"""A single search result hit."""
uri: str = Field(description="Documentation URI path")
title: str = Field(description="Display title")
kind: str = Field(description="Hit type: class, function, method, module, etc.")
snippet: str = Field(default="", description="Brief excerpt or description")
score: float = Field(default=0.0, description="Relevance score")
version: str = Field(description="Python version this hit belongs to")
slug: str = Field(default="", description="Page slug for get_docs follow-up")
anchor: str | None = Field(
default=None,
description="Section anchor for get_docs follow-up; None for page-level hits",
)
class SearchDocsResult(BaseModel):
"""Output from search_docs tool."""
hits: list[SymbolHit] = Field(
default_factory=list,
description="Search result hits",
)
note: str | None = Field(
default=None,
description="Informational note (e.g., limited search mode)",
)
# --- get_docs models ---
class GetDocsInput(BaseModel):
"""Input parameters for get_docs tool."""
slug: str = Field(
max_length=500,
description="Page slug (e.g. 'library/asyncio-task.html')",
)
version: str | None = Field(
default=None,
description="Python version. Defaults to latest.",
)
anchor: str | None = Field(
default=None,
description="Section anchor for section-only retrieval",
)
max_chars: int = Field(
default=8000,
ge=100,
le=50000,
description="Maximum characters to return",
)
start_index: int = Field(
default=0,
ge=0,
description="Start position for pagination",
)
class GetDocsResult(BaseModel):
"""Output from get_docs tool."""
content: str = Field(description="Documentation content in markdown")
slug: str = Field(description="Page slug")
title: str = Field(description="Page or section title")
version: str = Field(description="Python version")
anchor: str | None = Field(
default=None,
description="Section anchor if section-level",
)
char_count: int = Field(description="Total character count of full content")
truncated: bool = Field(
default=False,
description="Whether content was truncated",
)
next_start_index: int | None = Field(
default=None,
description="Next start_index for pagination, if truncated",
)
# --- list_versions models ---
class VersionInfo(BaseModel):
"""Information about an available Python version."""
version: str = Field(description="Python version string (e.g. '3.13')")
language: str = Field(default="en", description="Documentation language")
label: str = Field(description="Display label")
is_default: bool = Field(description="Whether this is the default version")
built_at: str = Field(description="When this version's index was built")
class ListVersionsResult(BaseModel):
"""Output from list_versions tool."""
versions: list[VersionInfo] = Field(
description="Available documentation versions",
)
# --- detect_python_version models ---
class DetectPythonVersionResult(BaseModel):
"""Output from detect_python_version tool."""
detected_version: str = Field(
description="Python major.minor detected from the user's environment (e.g. '3.13')"
)
source: str = Field(
description=(
"How the version was detected: '.python-version file',"
" 'python3 in PATH', or 'server runtime'"
)
)
matched_index_version: str | None = Field(
default=None,
description="The detected version if it matches an indexed doc set, otherwise null",
)
is_default: bool = Field(
description="Whether this detected version is being used as the default for get_docs"
)
# --- lookup_package_docs models ---
# Bounded kind vocabulary: hardcoded values from `_source` calls plus the
# normalized members of `_ALLOWED` (with spaces → underscores) in
# services/package_docs.py. Keep these in sync.
PackageKind = Literal[
"pypi",
"docs",
"documentation",
"homepage",
"home_page",
"source",
"source_code",
"repository",
"repo",
]
class PackageDocsSource(BaseModel):
"""A package-declared documentation or project source URL."""
label: str = Field(description="Label from PyPI metadata or a normalized core metadata field")
url: str = Field(description="HTTP(S) URL declared by the package on PyPI")
kind: PackageKind = Field(
description="Source category: pypi, docs, documentation, homepage, home_page, "
"source, source_code, repository, or repo"
)
declared_by: str = Field(description="Where this source declaration came from")
class PackageDocsResult(BaseModel):
"""Output from lookup_package_docs tool."""
package: str = Field(description="Canonical package name returned by PyPI when available")
version: str = Field(description="Latest version reported by PyPI metadata")
summary: str = Field(default="", description="Package summary from PyPI metadata")
metadata_source: str = Field(description="Official PyPI JSON API URL used for lookup")
trust_boundary: Literal["pypi-declared-metadata"] = Field(
default="pypi-declared-metadata",
description="Indicates results are limited to PyPI/project-declared metadata",
)
sources: list[PackageDocsSource] = Field(
default_factory=list,
description="Package-declared PyPI, documentation, homepage, and source URLs",
)
note: str | None = Field(
default=None,
description="Controlled-scope note, for example skipped labels or not-found details",
)
# --- compare_versions models ---
ChangeKind = Literal["added", "removed", "changed", "unchanged"]
class CompareVersionsResult(BaseModel):
"""Output from compare_versions tool (CMPR-01, CMPR-03).
Typed contract returned by CompareService.compare and the source FastMCP
auto-derives the compare_versions outputSchema from. The four ``change``
cases (added / removed / changed / unchanged) all share this shape;
optional delta fields are ``None`` when they do not apply to the case,
keeping the JSON shape predictable and token-frugal (no full re-printing
of unchanged content, per CMPR-03).
"""
symbol: str = Field(description="Qualified symbol name being compared")
v1: str = Field(description="Source Python version")
v2: str = Field(description="Target Python version")
change: ChangeKind = Field(
description=(
"Diff discriminator: 'added' (symbol new in v2), 'removed' "
"(symbol absent in v2), 'changed' (symbol present in both with a "
"detected delta), or 'unchanged' (symbol present in both, no delta)"
)
)
new_in: str | None = Field(
default=None,
description=(
"Version string extracted from the v2 section text; populated when "
"change == 'added', and may also be set when change == 'changed' if "
"the v2 section carries a versionadded marker for a sub-feature"
),
)
removed_in: str | None = Field(
default=None,
description=(
"Version where the symbol is first absent; populated when "
"change == 'removed' (equals v2)"
),
)
changed_in: str | None = Field(
default=None,
description=(
"Version extracted from the v2 section; populated when "
"change == 'changed'"
),
)
deprecated_in: str | None = Field(
default=None,
description="Version extracted from a deprecation marker in the v2 section",
)
signature_delta: str | None = Field(
default=None,
description=(
"Best-effort heuristic: first non-empty diff line between v1 and v2 "
"section text. MAY be a docstring change or prose change rather than "
"a true signature change — treat as advisory, not authoritative."
),
)
see_also_added: list[str] = Field(
default_factory=list,
description="See-also link labels present in v2 but not v1",
)
see_also_removed: list[str] = Field(
default_factory=list,
description="See-also link labels present in v1 but not v2",
)
section_diff: str | None = Field(
default=None,
description=(
"Short unified-diff snippet (difflib.unified_diff), truncated to "
"honor the token budget; populated only when change == 'changed' and "
"the diff is non-trivially short"
),
)
note: str | None = Field(
default=None,
description=(
"Optional advisory note about result completeness, e.g. when docs "
"pages could not be fetched for one or both versions and the diff is "
"therefore based on symbol presence alone."
),
)