correctly retrieve the script name

This commit is contained in:
David Soria Parra 2024-11-21 11:59:31 +00:00
commit 74a6e01a30
No known key found for this signature in database
3 changed files with 32 additions and 2 deletions

View file

@ -5,11 +5,25 @@ import sys
from pathlib import Path from pathlib import Path
import click import click
import toml
from packaging.version import parse from packaging.version import parse
MIN_UV_VERSION = "0.4.10" MIN_UV_VERSION = "0.4.10"
class PyProject:
def __init__(self, path: Path):
self.data = toml.load(path)
@property
def name(self) -> str:
return self.data["project"]["name"]
@property
def first_binary(self) -> str | None:
scripts = self.data["project"].get("scripts", {})
return next(iter(scripts.keys()), None)
def check_uv_version(required_version: str) -> str | None: def check_uv_version(required_version: str) -> str | None:
"""Check if uv is installed and has minimum version""" """Check if uv is installed and has minimum version"""
try: try:
@ -123,7 +137,11 @@ def copy_template(
("README.md.jinja2", "README.md", path), ("README.md.jinja2", "README.md", path),
] ]
pyproject = PyProject(path / "pyproject.toml")
bin_name = pyproject.first_binary
template_vars = { template_vars = {
"binary_name": bin_name,
"server_name": name, "server_name": name,
"server_version": version, "server_version": version,
"server_description": description, "server_description": description,
@ -237,6 +255,8 @@ def check_package_name(name: str) -> bool:
return True return True
@click.command() @click.command()
@click.option( @click.option(
"--path", "--path",

View file

@ -50,10 +50,20 @@ On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
Since MCP servers run over stdio, debugging can be challenging. For the best debugging Since MCP servers run over stdio, debugging can be challenging. For the best debugging
experience, we strongly recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). experience, we strongly recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector).
{% if binary_name %}
You can launch the MCP Inspector via [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) with this command: You can launch the MCP Inspector via [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) with this command:
```bash ```bash
npx @modelcontextprotocol/inspector uv --directory {{server_directory}} run {{server_name}} npx @modelcontextprotocol/inspector uv --directory {{server_directory}} run {{binary_name}}
```
{% else %}
This project does not contain a script to start. However, you can still use the MCP Inspector for debugging. To start the inspector, use the following general command structure:
```bash
npx @modelcontextprotocol/inspector <command-to-run-your-server>
``` ```
Replace `<command-to-run-your-server>` with the specific command you use to start your MCP server.
{% endif %}
Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging. Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.

2
uv.lock generated
View file

@ -24,7 +24,7 @@ wheels = [
[[package]] [[package]]
name = "create-mcp-server" name = "create-mcp-server"
version = "1.0.1.dev0" version = "1.0.3.dev0"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "click" }, { name = "click" },