Skip to content

Commit 0ef3994

Browse files
committed
Add parameter annotations with descriptions for tool
Signed-off-by: Gerald Venzl <[email protected]>
1 parent 24d305d commit 0ef3994

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

src/oracle-db-doc-mcp-server/oracle-db-doc-mcp-server.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from bs4 import BeautifulSoup
3131
from fastmcp import FastMCP
3232
from pocketsearch import PocketSearch, PocketWriter
33+
from pydantic import Field
34+
from typing import Annotated
3335

3436
# Working home directory
3537
HOME_DIR = Path.home().joinpath(PurePath(".oracle/oracle-db-doc-mcp-server"))
@@ -89,8 +91,8 @@
8991

9092
@mcp.tool()
9193
def search_oracle_database_documentation(
92-
search_query: str,
93-
max_results: int = 4,
94+
search_query: Annotated[str, Field(description="The search phrase to search for in the documentation.")],
95+
max_results: Annotated[int, Field(description="The maximum number of search results that should be returned, default 4.")] = 4
9496
) -> list[str]:
9597
"""Search for information about how to use Oracle Database for a query string
9698
and return a list of results.
@@ -193,20 +195,19 @@ def maintain_content(path: str) -> None:
193195
if location.is_file() and location.suffix == ".zip":
194196

195197
# Check if temp output directory exists and remove it
196-
zip_output = Path(ZIP_TEMP_OUTPUT)
197-
if zip_output.exists():
198-
logger.debug(f"Removing existing zip output directory: {zip_output}")
199-
shutil.rmtree(zip_output)
198+
if ZIP_TEMP_OUTPUT.exists():
199+
logger.debug(f"Removing existing zip output directory: {ZIP_TEMP_OUTPUT}")
200+
shutil.rmtree(ZIP_TEMP_OUTPUT)
200201

201-
logger.debug(f"Creating zip output directory: {zip_output}")
202-
zip_output.mkdir()
202+
logger.debug(f"Creating zip output directory: {ZIP_TEMP_OUTPUT}")
203+
ZIP_TEMP_OUTPUT.mkdir()
203204
with zipfile.ZipFile(location, "r") as zip_ref:
204-
logger.debug(f"Extracting zip file {location} to {zip_output}")
205+
logger.debug(f"Extracting zip file {location} to {ZIP_TEMP_OUTPUT}")
205206
zip_ref.extractall(ZIP_TEMP_OUTPUT)
206207

207-
logger.debug(f"Done creating zip output directory: {zip_output}")
208+
logger.debug(f"Done creating zip output directory: {ZIP_TEMP_OUTPUT}")
208209
# Set the location to the extracted output directory
209-
location = zip_output
210+
location = ZIP_TEMP_OUTPUT
210211

211212
logger.debug("Indexing all html files in the directory...")
212213

@@ -226,9 +227,9 @@ def maintain_content(path: str) -> None:
226227
write_file_content(INDEX_VERSION_FILE, INDEX_VERSION)
227228

228229
# Delete temporary zip output directory if it exists
229-
if Path(ZIP_TEMP_OUTPUT).exists():
230-
logger.debug(f"Removing temporary zip output directory: {zip_output}")
231-
shutil.rmtree(zip_output)
230+
if ZIP_TEMP_OUTPUT.exists():
231+
logger.debug(f"Removing temporary zip output directory: {ZIP_TEMP_OUTPUT}")
232+
shutil.rmtree(ZIP_TEMP_OUTPUT)
232233

233234

234235
def update_content(location: Path) -> None:
@@ -316,10 +317,7 @@ def convert_to_markdown_chunks(file: Path) -> list[str]:
316317
# Convert HTML to Markdown
317318
markdown = md.markdownify(html)
318319
if PREPROCESS != "NONE":
319-
markdown = markdown.replace(
320-
"Previous\nNext\n JavaScript must be enabled to correctly display this content",
321-
"",
322-
)
320+
# Remove URLs from markdown
323321
markdown = remove_markdown_urls(markdown)
324322

325323
# Split markdown into sections based on headings
@@ -423,6 +421,7 @@ def preprocess_html(html_content: str) -> str:
423421
# Remove common Oracle doc boilerplate text patterns
424422
boilerplate_patterns = [
425423
r"JavaScript.*(?:disabled|enabled).*browser",
424+
r"JavaScript must be enabled to correctly display this content",
426425
r"Skip navigation.*",
427426
r"Oracle®.*(?:Database.*)?(?:Reference|Guide|Manual|Documentation)",
428427
r"Release \d+[a-z]*[\s-]*[A-Z0-9-]*",
@@ -461,22 +460,22 @@ def build_folder_structure() -> None:
461460
RESOURCES_DIR.mkdir(parents=True)
462461

463462

464-
def get_file_content(path: str) -> str:
463+
def get_file_content(path: Path) -> str:
465464
"""Reads the content of a file and returns it or 'N/A' if the file does not exist.
466465
467466
Args:
468467
file (Path): The path to the file.
469468
"""
470-
if Path(path).exists():
471-
with Path(path).open("r") as f:
469+
if path.exists():
470+
with path.open("r") as f:
472471
return f.read().strip()
473472
else:
474473
return "N/A"
475474

476475

477-
def write_file_content(path: str, content: str) -> None:
476+
def write_file_content(path: Path, content: str) -> None:
478477
"""Writes the content to a file."""
479-
with Path(path).open("w") as f:
478+
with path.open("w") as f:
480479
f.write(content)
481480

482481

src/oracle-db-doc-mcp-server/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ dependencies = [
99
"fastmcp>=2.11.3",
1010
"markdownify>=1.2.0",
1111
"pocketsearch>=0.40.0",
12+
"pydantic>=2.12.3"
1213
]

src/oracle-db-doc-mcp-server/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ beautifulsoup4 >= 4.9.0
22
markdownify >= 1.2.0
33
fastmcp >= 2.11.3
44
pocketsearch >= 0.40.0
5+
pydantic>=2.12.3

0 commit comments

Comments
 (0)