> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Formatters

> Log formatters for MCP servers API Documentation

export const RandomGradientBackground = ({className, color, children, grayscaled = false}) => {
  const saturation = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[1] || "0");
    }
    return grayscaled ? 0 : 0.2;
  }, [color, grayscaled]);
  const lightness = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[0] || "0.5");
    }
    return grayscaled ? 0.3 : 0.4;
  }, [color, grayscaled]);
  const randomHue = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[2] || "0");
    }
    return Math.floor(Math.random() * 360);
  }, [color]);
  const randomColor = useMemo(() => {
    if (color) {
      return color;
    }
    return `oklch(${Math.min(lightness, 1)} ${saturation} ${randomHue})`;
  }, [randomHue, saturation, lightness]);
  const lightColor = useMemo(() => {
    return `oklch(${Math.min(lightness * 2, 1)} ${saturation} ${randomHue})`;
  }, [randomHue, saturation, lightness, color]);
  const direction = useMemo(() => {
    return Math.floor(Math.random() * 360);
  }, [randomHue]);
  const brightnessFilter = useMemo(() => {
    return "1000%";
  }, []);
  return <div className={`relative overflow-hidden ${className || ""}`} style={{
    background: `${lightColor}`,
    minHeight: '100%',
    width: '100%'
  }}>
      <div className="absolute inset-0 w-full h-full" style={{
    background: `linear-gradient(${direction}deg, ${randomColor}, transparent), url(https://grainy-gradients.vercel.app/noise.svg)`,
    filter: `contrast(120%) brightness(${brightnessFilter})`,
    backgroundSize: 'cover',
    backgroundRepeat: 'no-repeat'
  }} />
      {children && <div className="relative z-10 w-full h-full">{children}</div>}
    </div>;
};

<Callout type="info" title="Source Code">
  View the source code for this module on GitHub: <a href="https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/logging/formatters.py" target="_blank" rel="noopener noreferrer">[https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp\_use/server/logging/formatters.py](https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/logging/formatters.py)</a>
</Callout>

Log formatters for MCP servers.

## ColoredFormatter

<div>
  <RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
    <div className="text-black">
      <div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> ColoredFormatter</div>

      Custom formatter with ANSI color codes.
    </div>
  </RandomGradientBackground>

  ```python theme={null}
  from mcp_use.server.logging.formatters import ColoredFormatter
  ```

  <Card type="info">
    ### `method` **init**

    **Parameters**

    > <ParamField body="fmt" default="None">   Parameter value </ParamField>
    > <ParamField body="datefmt" default="None">   Parameter value </ParamField>

    **Signature**

    ```python wrap theme={null}
    def __init__(fmt = None, datefmt = None):
    ```
  </Card>
</div>

## MCPAccessFormatter

<div>
  <RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
    <div className="text-black">
      <div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> MCPAccessFormatter</div>

      Enhanced Uvicorn access formatter that shows MCP method information.

      For MCP requests, enhances the log with JSON-RPC method info from thread-local storage.
    </div>
  </RandomGradientBackground>

  ```python theme={null}
  from mcp_use.server.logging.formatters import MCPAccessFormatter
  ```

  <Card type="info">
    ### `method` **init**

    **Parameters**

    > <ParamField body="kwargs" required="True">   Parameter value </ParamField>

    **Signature**

    ```python wrap theme={null}
    def __init__(kwargs):
    ```
  </Card>
</div>

## MCPErrorFormatter

<div>
  <RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
    <div className="text-black">
      <div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> MCPErrorFormatter</div>

      Custom error formatter with helpful messages.
    </div>
  </RandomGradientBackground>

  ```python theme={null}
  from mcp_use.server.logging.formatters import MCPErrorFormatter
  ```

  <Card type="info">
    ### `method` **init**

    Initialize the formatter with specified format strings.

    Initialize the formatter either with the specified format string, or a
    default as described above. Allow for specialized date formatting with
    the optional datefmt argument. If datefmt is omitted, you get an
    ISO8601-like (or RFC 3339-like) format.

    Use a style parameter of '%', '\{' or '\$' to specify that you want to
    use one of %-formatting, :meth:`str.format` (`\{\}`) formatting or
    :class:`string.Template` formatting in your format string.

    .. versionchanged:: 3.2
    Added the `style` parameter.

    **Parameters**

    > <ParamField body="fmt" default="None">   Parameter value </ParamField>
    > <ParamField body="datefmt" default="None">   Parameter value </ParamField>
    > <ParamField body="style" default="%">   Parameter value </ParamField>
    > <ParamField body="validate" default="True">   Parameter value </ParamField>
    > <ParamField body="defaults" default="None">   Parameter value </ParamField>

    **Signature**

    ```python wrap theme={null}
    def __init__(fmt = None, datefmt = None, style = "%", validate = True, defaults = None):
    ```
  </Card>
</div>

## UvicornAccessArgs

<div>
  <RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
    <div className="text-black">
      <div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> UvicornAccessArgs</div>

      Uvicorn access logs use a tuple format: (client\_addr, method, path, ...).

      This class provides named access to make the code more readable.
      See: [https://github.com/encode/uvicorn/blob/master/uvicorn/logging.py](https://github.com/encode/uvicorn/blob/master/uvicorn/logging.py)
    </div>
  </RandomGradientBackground>

  ```python theme={null}
  from mcp_use.server.logging.formatters import UvicornAccessArgs
  ```

  <Card type="info">
    **Attributes**

    >

    <ParamField body="client_addr" type="str" required="True">   MCP client instance </ParamField>
    <ParamField body="method" type="str" required="True">   String value </ParamField>
    <ParamField body="path" type="str" required="True">   File path </ParamField>
  </Card>

  <Card type="info">
    ### `method` **init**

    **Parameters**

    > <ParamField body="client_addr" type="str" required="True">   MCP client instance </ParamField>
    > <ParamField body="method" type="str" required="True">   String value </ParamField>
    > <ParamField body="path" type="str" required="True">   File path </ParamField>
    > <ParamField body="extra" type="tuple" required="True">   Parameter value </ParamField>

    **Signature**

    ```python wrap theme={null}
    def __init__(client_addr: str, method: str, path: str, extra: tuple):
    ```
  </Card>

  <Card type="info">
    ### `method` is\_mcp\_request

    Check if this is a POST request to the MCP endpoint.

    **Parameters**

    > <ParamField body="mcp_path" type="str" default="/mcp">   File path </ParamField>

    **Returns**

    >     <ResponseField name="returns" type="bool" />

    **Signature**

    ```python wrap theme={null}
    def is_mcp_request(mcp_path: str = "/mcp"):
    ```
  </Card>

  <Card type="info">
    ### `method` to\_tuple

    Convert back to tuple format for Uvicorn's formatter.

    **Parameters**

    > <ParamField body="path_override" type="str | None" default="None">   File path </ParamField>
    > <ParamField body="method_override" type="str | None" default="None">   String value </ParamField>

    **Returns**

    >     <ResponseField name="returns" type="tuple" />

    **Signature**

    ```python wrap theme={null}
    def to_tuple(path_override: str | None = None, method_override: str | None = None):
    ```
  </Card>
</div>
