π The fast, Pythonic way to build MCP servers and clients.
Add --skills to fastmcp list (#6073)
nate nowacka0b377a6a198
diff --git a/docs/cli/client.mdx b/docs/cli/client.mdxindex 153efff9a..e2f8ed6f0 100644--- a/docs/cli/client.mdx+++ b/docs/cli/client.mdx@@ -35,6 +35,12 @@ By default, only tools are shown. Add `--resources` or `--prompts` to include thfastmcp list server.py --resources --prompts```+`--skills` lists the server's [Skills extension](/servers/skills) entries with each skill's files. A server that doesn't advertise the extension shows no skills and says why.++```bash+fastmcp list server.py --skills+```+### Machine-Readable OutputThe `--json` flag switches to structured JSON with full schemas included. This is the format to use when feeding tool definitions to an LLM or building automation:@@ -51,6 +57,7 @@ fastmcp list server.py --json| Transport | `--transport`, `-t` | Force `http` or `sse` for URL targets || Resources | `--resources` | Include resources in output || Prompts | `--prompts` | Include prompts in output |+| Skills | `--skills` | Include Skills extension entries in output || Input Schema | `--input-schema` | Show full input schemas || Output Schema | `--output-schema` | Show full output schemas || JSON | `--json` | Structured JSON output |diff --git a/fastmcp_slim/fastmcp/cli/client.py b/fastmcp_slim/fastmcp/cli/client.pyindex 9a08f041a..8b5ccd5d1 100644--- a/fastmcp_slim/fastmcp/cli/client.py+++ b/fastmcp_slim/fastmcp/cli/client.py@@ -31,6 +31,8 @@ from fastmcp.client.transports.base import ClientTransportfrom fastmcp.client.transports.http import StreamableHttpTransportfrom fastmcp.client.transports.sse import SSETransportfrom fastmcp.client.transports.stdio import StdioTransport+from fastmcp.skills.client import SkillsClientExtension+from fastmcp.skills.models import MCPSkillfrom fastmcp.utilities.logging import get_loggerlogger = get_logger("cli.client")@@ -264,11 +266,13 @@ def _build_client(*,timeout: float | None = None,auth: str | None = None,+ skills: bool = False,) -> Client:"""Build a ``Client`` from a resolved server spec.Applies ``auth='oauth'`` automatically for HTTP-based targets unless- the caller explicitly passes ``--auth none`` to disable it.+ the caller explicitly passes ``--auth none`` to disable it. ``skills=True``+ opts the client into the Skills extension.``auth=None`` means "not specified" (use default), ``auth="none"``means "explicitly disabled".@@ -323,6 +327,7 @@ def _build_client(timeout=timeout,auth=effective_auth,elicitation_handler=_terminal_elicitation_handler,+ extensions=[SkillsClientExtension()] if skills else None,)@@ -755,6 +760,10 @@ async def list_command(bool,cyclopts.Parameter("--prompts", help="Also list prompts"),] = False,+ skills: Annotated[+ bool,+ cyclopts.Parameter("--skills", help="Also list Skills extension entries"),+ ] = False,input_schema: Annotated[bool,cyclopts.Parameter("--input-schema", help="Show full input schemas"),@@ -786,14 +795,22 @@ async def list_command(fastmcp list server.pyfastmcp list mcp.json --jsonfastmcp list --command 'npx -y @mcp/server' --resources+ fastmcp list server.py --skillsfastmcp list http://server/mcp --transport sse"""resolved = resolve_server_spec(server_spec, command=command, transport=transport)try:- client = _build_client(resolved, timeout=timeout, auth=auth)+ client = _build_client(resolved, timeout=timeout, auth=auth, skills=skills)async with client:tools = await client.list_tools()+ skill_entries: list[MCPSkill] = []+ skills_unavailable: str | None = None+ if skills:+ try:+ skill_entries = await client.list_skills()+ except RuntimeError as exc:+ skills_unavailable = str(exc)if json_output:data: dict[str, Any] = {"tools": _tools_to_json(tools)}@@ -818,6 +835,11 @@ async def list_command(}for p in prm]+ if skills:+ data["skills"] = [+ entry.model_dump(mode="json", by_alias=True, exclude_none=True)+ for entry in skill_entries+ ]console.print_json(json.dumps(data))return@@ -874,6 +896,27 @@ async def list_command(console.print(f" {_sanitize_untrusted_text(p.description)}")console.print()+ if skills:+ console.print(f"[bold]Skills ({len(skill_entries)})[/bold]")+ console.print()+ if skills_unavailable:+ console.print(f" [dim]{skills_unavailable}[/dim]")+ elif not skill_entries:+ console.print(" [dim]No skills found.[/dim]")+ for entry in skill_entries:+ console.print(+ f" [cyan]{_sanitize_untrusted_text(entry.uri)}[/cyan]"+ )+ description = entry.frontmatter.description+ console.print(f" {_sanitize_untrusted_text(description)}")+ if isinstance(entry.resources, list):+ for resource in entry.resources:+ line = f"{resource.uri} ({resource.size} bytes)"+ console.print(+ f" [dim]{_sanitize_untrusted_text(line)}[/dim]"+ )+ console.print()+except Exception as exc:console.print(f"[bold red]Error:[/bold red] {exc}")sys.exit(1)diff --git a/tests/cli/test_list_skills.py b/tests/cli/test_list_skills.pynew file mode 100644index 000000000..9db28ca9d--- /dev/null+++ b/tests/cli/test_list_skills.py@@ -0,0 +1,72 @@+import json+from typing import Any+from unittest.mock import patch++import pytest++from fastmcp import Client, FastMCP+from fastmcp.cli import client as client_module+from fastmcp.cli.client import list_command+from fastmcp.skills import Skill, SkillsClientExtension+from fastmcp.skills.provider import SkillCatalogProvider++REVIEW = Skill(+ name="review",+ description="Review changes",+ instructions="# Review\n",+ files={"notes.md": "notes\n"},+)+++def patch_client(server: FastMCP):+ def fake_build_client(resolved: Any, *, skills: bool = False, **_: Any) -> Client:+ extensions = [SkillsClientExtension()] if skills else None+ return Client(server, extensions=extensions)++ return (+ patch.object(client_module, "resolve_server_spec", return_value="fake"),+ patch.object(client_module, "_build_client", side_effect=fake_build_client),+ )+++async def test_list_skills_text(capsys: pytest.CaptureFixture[str]):+ resolve, build = patch_client(+ FastMCP("s", providers=[SkillCatalogProvider([REVIEW])])+ )+ with resolve, build:+ await list_command("fake", skills=True)+ out = capsys.readouterr().out+ assert "Skills (1)" in out+ assert "skill://review/SKILL.md" in out+ assert "Review changes" in out+ assert "skill://review/notes.md (6 bytes)" in out+++async def test_list_skills_json(capsys: pytest.CaptureFixture[str]):+ resolve, build = patch_client(+ FastMCP("s", providers=[SkillCatalogProvider([REVIEW])])+ )+ with resolve, build:+ await list_command("fake", skills=True, json_output=True)+ (entry,) = json.loads(capsys.readouterr().out)["skills"]+ assert entry == REVIEW.to_mcp_skill().model_dump(+ mode="json", by_alias=True, exclude_none=True+ )+++async def test_list_skills_without_server_support(capsys: pytest.CaptureFixture[str]):+ resolve, build = patch_client(FastMCP("plain"))+ with resolve, build:+ await list_command("fake", skills=True)+ out = capsys.readouterr().out+ assert "Skills (0)" in out+ assert "does not advertise the Skills extension" in out+++async def test_build_client_opts_into_skills():+ client = client_module._build_client(+ "http://localhost:8000/mcp", auth="none", skills=True+ )+ assert "io.modelcontextprotocol/skills" in (+ client._session_kwargs.get("extensions") or {}+ )