Making an MCP server for the twitch-cli to aid developer experience
Simulate Twitch Event-Sub Events via Cursor with an MCP Server for the twitch-cli. When building Twitch integrations—like chat bots, overlays, or EventSub-powered features—testing can be painful without real user actions triggering events. That's where the Twitch CLI and fastmcp come in. In this post, I'll show how I set up a local MCP server using fastmcp, and how I use it to trigger events like a Twitch follow using twitch-cli. What Is an MCP Server? In the context of tools like Cursor (and possibly other AI IDEs), an MCP server lets you define custom “tools” in code—these tools can then be called by the AI as part of its workflow. It’s a simple protocol: your server runs locally and exposes functions with structured inputs/outputs over Server-Sent Events (SSE). When the AI tool calls one of your functions, it hits your server and gets the result. Using fastmcp to Build a Local MCP Server for Cursor AI + Twitch CLI Integration If you're using an AI coding tool like Cursor, you might've come across their support for MCP (Model Context Protocol) servers—a way to define your own tools that the AI can invoke directly while coding. In this post, I’ll show how I’m using fastmcp to set up a local MCP server, which I’ve wired up to Twitch CLI. With this, I can write prompts in Cursor like: Project Structure I have the following in my repo: ./cursor/mcp.json This config tells cursor to use my local MCP server: { "mcpServers": { "test": { "url": "http://127.0.0.1:8000/sse/", "disabled": false, "autoApprove": [] } } } MCP Server code server.py from fastmcp import FastMCP, Context from typing import Dict, Any import os import subprocess import shlex mcp = FastMCP("twitch-cli") @mcp.tool("trigger_twitch_follow_event") async def trigger_twitch_follow_event(user_id: str, ctx: Context) -> Dict[str, Any]: """ Trigger a Twitch follow event for a specific user ID. Args: user_id (str): The Twitch user ID to trigger the follow event for Returns: Dict[str, Any]: Command output or error message """ domain = os.getenv("DOMAIN") password = os.getenv("TWITCH_EVENTSUB_SECRET") command = f'twitch event trigger follow -t {user_id} -s {password} -F "https://{domain}/twitch-eventsub"' try: # Split the command into a list of arguments args = shlex.split(command) # Execute the command and capture output result = subprocess.run( args, capture_output=True, text=True, check=True ) return { "success": True, "stdout": result.stdout, "stderr": result.stderr, "return_code": result.returncode } except subprocess.CalledProcessError as e: return { "success": False, "error": str(e), "stdout": e.stdout, "stderr": e.stderr, "return_code": e.returncode } if __name__ == "__main__": mcp.run(transport="sse")` Running locally export DOMAIN=https://example.com export TWITCH_EVENTSUB_SECRET=xxx python server.py ask your ide AI code agent “Trigger a Twitch follow event for user 12345” Images Final Thoughts This workflow has been game-changing for building Twitch integrations. I can now prototype and test my EventSub logic without writing manual cli commands, rather just describe the desired event and targeted Twitch user I want in the Cursor AI Chat agent, and it triggers the action via my local tool. If you're building tools that benefit from programmatic APIs, local scripts, or devops integrations, fastmcp + Cursor’s tool-calling support is an incredibly powerful setup.**

Simulate Twitch Event-Sub Events via Cursor with an MCP Server for the twitch-cli
.
When building Twitch integrations—like chat bots, overlays, or EventSub-powered features—testing can be painful without real user actions triggering events. That's where the Twitch CLI and fastmcp come in.
In this post, I'll show how I set up a local MCP server using fastmcp
, and how I use it to trigger events like a Twitch follow using twitch-cli
.
What Is an MCP Server?
In the context of tools like Cursor (and possibly other AI IDEs), an MCP server lets you define custom “tools” in code—these tools can then be called by the AI as part of its workflow.
It’s a simple protocol: your server runs locally and exposes functions with structured inputs/outputs over Server-Sent Events (SSE). When the AI tool calls one of your functions, it hits your server and gets the result.
Using fastmcp
to Build a Local MCP Server for Cursor AI + Twitch CLI Integration
If you're using an AI coding tool like Cursor, you might've come across their support for MCP (Model Context Protocol) servers—a way to define your own tools that the AI can invoke directly while coding.
In this post, I’ll show how I’m using fastmcp
to set up a local MCP server, which I’ve wired up to Twitch CLI. With this, I can write prompts in Cursor like:
Project Structure
I have the following in my repo:
./cursor/mcp.json
This config tells cursor to use my local MCP server:
{
"mcpServers": {
"test": {
"url": "http://127.0.0.1:8000/sse/",
"disabled": false,
"autoApprove": []
}
}
}
MCP Server code
server.py
from fastmcp import FastMCP, Context
from typing import Dict, Any
import os
import subprocess
import shlex
mcp = FastMCP("twitch-cli")
@mcp.tool("trigger_twitch_follow_event")
async def trigger_twitch_follow_event(user_id: str, ctx: Context) -> Dict[str, Any]:
"""
Trigger a Twitch follow event for a specific user ID.
Args:
user_id (str): The Twitch user ID to trigger the follow event for
Returns:
Dict[str, Any]: Command output or error message
"""
domain = os.getenv("DOMAIN")
password = os.getenv("TWITCH_EVENTSUB_SECRET")
command = f'twitch event trigger follow -t {user_id} -s {password} -F "https://{domain}/twitch-eventsub"'
try:
# Split the command into a list of arguments
args = shlex.split(command)
# Execute the command and capture output
result = subprocess.run(
args,
capture_output=True,
text=True,
check=True
)
return {
"success": True,
"stdout": result.stdout,
"stderr": result.stderr,
"return_code": result.returncode
}
except subprocess.CalledProcessError as e:
return {
"success": False,
"error": str(e),
"stdout": e.stdout,
"stderr": e.stderr,
"return_code": e.returncode
}
if __name__ == "__main__":
mcp.run(transport="sse")`
Running locally
export DOMAIN=https://example.com
export TWITCH_EVENTSUB_SECRET=xxx
python server.py
ask your ide AI code agent “Trigger a Twitch follow event for user 12345”
Images
Final Thoughts
This workflow has been game-changing for building Twitch integrations. I can now prototype and test my EventSub logic without writing manual cli commands, rather just describe the desired event and targeted Twitch user I want in the Cursor AI Chat agent, and it triggers the action via my local tool.
If you're building tools that benefit from programmatic APIs, local scripts, or devops integrations, fastmcp + Cursor’s tool-calling support is an incredibly powerful setup.**