Files
Pietro Zullo be9942a4d4 feat/python/server (#559)
* feat: server first implementation

* docs: docs for server and images

* chore: locked langchain dependencies in pyproject.toml (#321)

* python/release/1.3.13

* catch uvicorn logs && log session id

* fix debug logic

* docs: logging update

* fix: icon of elicitation

* fix installation paths for local clones

* docs: minor restructuring

* docs: reorganization, killed non existing pages

* docs: beta tag on server

* chore: example servers

* feat: inspector autopopulated and client only

* feat: enhance MCP logging system with customizable formats and improved middleware

* feat: implement weather alert and forecast tools in FastMCP example server

* mcp path configurable

* fix inspector

* export as FastMCP too

* chore: update fastmcp migration example

* lock inspector version

* type runner

* unhide docs and remove dangers

* migration diff

* docs and context example

* export context

* logging improvement

* pretty JSON RPC

* autoConnect url param in inspecotr

* move logging

* type check

* Server Router

* show response logs

* fallback tool name to function name in router registration

* compatibility export

* Introduced ty and prek as type checker and precommit engine respectively - moved ruff config in pyproject toml

* add ty check

* ty runs only on staged files

* ty configuration fix

* move startup info in logging

* remove bug from action

* update claude rules

* fix resource serialization

* comments on inspector errors

* abstracted runner transports

* remove redunant call for network

* fix ip getter

* add inspector mcp path

* response limit logging

* disable ty check in action

* moved transport type to types

* support sse

* show transport type in logs

* change default transport

* refactored tests to use mcp server

* removed fastmcp

* file restructuring

* test table

* sampling, elicitation, tool disabling enabling

* deprecte sse server side

* simplified report

* fix action

* remove sse deprecated test

* move tests files to allow for server integration tests

* docs

* reorg integration test files

* api-reference-doxs

* fix broken links

* telemetry

* remove feature useage from scarf
2025-12-01 14:12:16 +01:00

54 lines
2.2 KiB
Python

import time
from typing import TYPE_CHECKING
from rich.console import Console
import mcp_use
from mcp_use.server.types import TransportType
from mcp_use.server.utils.utils import estimate_tokens, get_local_network_ip
if TYPE_CHECKING:
from mcp_use.server.server import MCPServer
async def display_startup_info(
server: "MCPServer", host: str, port: int, transport: TransportType | None = None, start_time: float = 0.0
) -> None:
"""Display Next.js-style startup information for the MCP server."""
console = Console()
startup_time = time.time() - start_time # ty error: assigning float to str
tools = await server.list_tools()
resources = await server.list_resources()
prompts = await server.list_prompts()
tools_tokens = sum(estimate_tokens(tool.model_dump_json()) for tool in tools)
resources_tokens = sum(estimate_tokens(resource.model_dump_json()) for resource in resources)
prompts_tokens = sum(estimate_tokens(prompt.model_dump_json()) for prompt in prompts)
total_tokens = tools_tokens + resources_tokens + prompts_tokens
network_ip = get_local_network_ip()
console.print(f"mcp-use Version: {mcp_use.__version__}")
console.print()
console.print(f"{server.name}")
console.print(f"[bright_black]{server.instructions}[/bright_black]")
stats = f"Tools: {len(tools)} | Resources: {len(resources)} | Prompts: {len(prompts)} | Tokens: {total_tokens}"
console.print(f"[bright_black]{stats}[/bright_black]")
console.print()
console.print(f"- Transport: {transport or 'Unknown'}")
console.print(f"- Local: http://{host}:{port}")
console.print(f"- MCP: http://{host}:{port}{server.mcp_path}")
if network_ip and network_ip != host and host == "0.0.0.0":
console.print(f"- Network: http://{network_ip}:{port}")
if server.debug_level >= 1:
console.print(f"- Docs: http://{host}:{port}{server.docs_path}")
console.print(f"- Inspector: http://{host}:{port}{server.inspector_path}")
console.print(f"- OpenMCP: http://{host}:{port}{server.openmcp_path}")
console.print()
console.print("[green]✓[/green] Starting...")
console.print(f"[green]✓[/green] Ready in {1000 * startup_time:.0f}ms")
console.print()