Skip to content

Instantly share code, notes, and snippets.

@ayoubzulfiqar
Last active June 18, 2025 09:30
Show Gist options
  • Save ayoubzulfiqar/f7c72a86d395d7bd23e9272d0a13f7b6 to your computer and use it in GitHub Desktop.
Save ayoubzulfiqar/f7c72a86d395d7bd23e9272d0a13f7b6 to your computer and use it in GitHub Desktop.
MCP Server with Gradio - Simple

MCP - LetterCounter

pip install "gradio[mcp]"
import gradio as gr


def letter_counter(word: str, letter: str) -> int:
    """
    Count the number of occurrences of a letter in a word or text.

    Args:
        word (str): The input text to search through
        letter (str): The letter to search for

    Returns:
        int: The number of times the letter appears in the text
    """
    word = word.lower()
    letter = letter.lower()
    count = word.count(letter)
    return count


# Create a standard Gradio interface
demo = gr.Interface(
    fn=letter_counter,
    inputs=["textbox", "textbox"],
    outputs="number",
    title="Letter Counter",
    description="Enter text and a letter to count how many times the letter appears in the text.",
)

# Launch both the Gradio web interface and the MCP server
if __name__ == "__main__":
    demo.launch(mcp_server=True)

Configs

{
  "mcpServers": {
    "gradio": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:9090/gradio_api/mcp/sse"]
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment