diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..2b11178 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index bdd17b6..d1188c0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ __pycache__/ *.egg-info/ .venv/ +# Ruff +.ruff_cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6ed72bf --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.14.2 + hooks: + - id: ruff-check + - id: ruff-format + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-yaml + - id: check-json + - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: trailing-whitespace diff --git a/README.md b/README.md index 8a68ee9..cf1fb98 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ The MCP servers in this demo highlight how each tool can light up widgets by com - Node.js 18+ - pnpm (recommended) or npm/yarn - Python 3.10+ (for the Python MCP server) +- pre-commit for formatting ## Install dependencies @@ -40,6 +41,7 @@ Clone the repository and install the workspace dependencies: ```bash pnpm install +pre-commit install ``` > Using npm or yarn? Install the root dependencies with your preferred client and adjust the commands below accordingly. diff --git a/dev-all.mts b/dev-all.mts index ef7fff8..c8a7ff2 100644 --- a/dev-all.mts +++ b/dev-all.mts @@ -115,4 +115,3 @@ main().catch((e) => { console.error(e); process.exit(1); }); - diff --git a/pizzaz_server_python/main.py b/pizzaz_server_python/main.py index cda0812..477ea0a 100644 --- a/pizzaz_server_python/main.py +++ b/pizzaz_server_python/main.py @@ -86,15 +86,19 @@ def _load_widget_html(component_name: str) -> str: invoked="Served a fresh list", html=_load_widget_html("pizzaz-list"), response_text="Rendered a pizza list!", - ) + ), ] MIME_TYPE = "text/html+skybridge" -WIDGETS_BY_ID: Dict[str, PizzazWidget] = {widget.identifier: widget for widget in widgets} -WIDGETS_BY_URI: Dict[str, PizzazWidget] = {widget.template_uri: widget for widget in widgets} +WIDGETS_BY_ID: Dict[str, PizzazWidget] = { + widget.identifier: widget for widget in widgets +} +WIDGETS_BY_URI: Dict[str, PizzazWidget] = { + widget.template_uri: widget for widget in widgets +} class PizzaInput(BaseModel): @@ -138,7 +142,7 @@ def _tool_meta(widget: PizzazWidget) -> Dict[str, Any]: "openai/toolInvocation/invoking": widget.invoking, "openai/toolInvocation/invoked": widget.invoked, "openai/widgetAccessible": True, - "openai/resultCanProduceWidget": True + "openai/resultCanProduceWidget": True, } @@ -277,7 +281,7 @@ async def _call_tool_request(req: types.CallToolRequest) -> types.ServerResult: ) ], structuredContent={"pizzaTopping": topping}, - _meta=meta + _meta=meta, ) ) diff --git a/pizzaz_server_python/requirements.txt b/pizzaz_server_python/requirements.txt index 6eb7e58..5deee2d 100644 --- a/pizzaz_server_python/requirements.txt +++ b/pizzaz_server_python/requirements.txt @@ -1,3 +1,3 @@ -mcp[fastapi]>=0.1.0 fastapi>=0.115.0 +mcp[fastapi]>=0.1.0 uvicorn>=0.30.0 diff --git a/solar-system_server_python/main.py b/solar-system_server_python/main.py index d7b3cad..37c2a11 100644 --- a/solar-system_server_python/main.py +++ b/solar-system_server_python/main.py @@ -125,10 +125,10 @@ def _tool_meta(widget: SolarWidget) -> Dict[str, Any]: "openai/widgetAccessible": True, "openai/resultCanProduceWidget": True, "annotations": { - "destructiveHint": False, - "openWorldHint": False, - "readOnlyHint": True, - } + "destructiveHint": False, + "openWorldHint": False, + "readOnlyHint": True, + }, } @@ -152,10 +152,10 @@ def _normalize_planet(name: str) -> str | None: if not key: return DEFAULT_PLANET - clean = ''.join(ch for ch in key if ch.isalnum()) + clean = "".join(ch for ch in key if ch.isalnum()) for planet in PLANETS: - planet_key = ''.join(ch for ch in planet.lower() if ch.isalnum()) + planet_key = "".join(ch for ch in planet.lower() if ch.isalnum()) if clean == planet_key or key == planet.lower(): return planet @@ -164,7 +164,7 @@ def _normalize_planet(name: str) -> str | None: return alias for planet in PLANETS: - planet_key = ''.join(ch for ch in planet.lower() if ch.isalnum()) + planet_key = "".join(ch for ch in planet.lower() if ch.isalnum()) if planet_key.startswith(clean): return planet @@ -259,10 +259,7 @@ async def _call_tool_request(req: types.CallToolRequest) -> types.ServerResult: content=[ types.TextContent( type="text", - text=( - "Unknown planet. Provide one of: " - + ", ".join(PLANETS) - ), + text=("Unknown planet. Provide one of: " + ", ".join(PLANETS)), ) ], isError=True, diff --git a/solar-system_server_python/requirements.txt b/solar-system_server_python/requirements.txt index 1f3183e..9741e5f 100644 --- a/solar-system_server_python/requirements.txt +++ b/solar-system_server_python/requirements.txt @@ -1,4 +1,4 @@ +fastapi>=0.115.0 # Dependencies for the solar-system MCP demo server mcp[fastapi]>=0.1.0 -fastapi>=0.115.0 uvicorn>=0.30.0 diff --git a/src/pizzaz-albums/albums.json b/src/pizzaz-albums/albums.json index a8119f8..9c934ca 100644 --- a/src/pizzaz-albums/albums.json +++ b/src/pizzaz-albums/albums.json @@ -110,5 +110,3 @@ } ] } - - diff --git a/tsconfig.app.json b/tsconfig.app.json index 9c9df02..383081a 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -6,8 +6,6 @@ "lib": ["ES2022", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, - - /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": false, @@ -16,12 +14,8 @@ "jsx": "react-jsx", "jsxImportSource": "react", "types": ["vite/client", "@react-three/fiber"], - - // Helpful for TS resolving and editor tooling "baseUrl": ".", "paths": {}, - - /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, diff --git a/tsconfig.node.json b/tsconfig.node.json index 879d72c..531ead2 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -5,15 +5,11 @@ "lib": ["ES2023"], "module": "ESNext", "skipLibCheck": true, - - /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "moduleDetection": "force", "noEmit": true, - - /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true,