Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions its-a-smol-world-mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Outlines MCP Demo

This is a small update to the [It's a Smol World](https://github.com/dottxt-ai/demos/tree/main/its-a-smol-world) demo, adding Model Context Protocol (MCP) connectivity.

The core concept remains the same: using a small language model for function calling, but now the client can connect to any MCP-compatible server instead of just using local functions. This means you can leverage the efficiency of a small local model for routing while accessing powerful external tools through the MCP protocol.

## Installation

### Windows

```bash
uv venv --python 3.11
.venv\Scripts\activate
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
uv pip install -r requirements.txt
```

## Usage

```bash
python .\src\app.py mcp-server\server.py -d
```

## Test Examples

- "Add 5 and 7"
- "I'd like to order two coffees from starbucks"
- "I need a ride to SEATAC terminal A"
- "What's the weather in san francisco today?"
- "Text Remi and tell him the project is looking good"
1 change: 1 addition & 0 deletions its-a-smol-world-mcp/mcp-server/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Empty file.
6 changes: 6 additions & 0 deletions its-a-smol-world-mcp/mcp-server/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from mcp-server!")


if __name__ == "__main__":
main()
9 changes: 9 additions & 0 deletions its-a-smol-world-mcp/mcp-server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "mcp-server"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"mcp[cli]>=1.6.0",
]
50 changes: 50 additions & 0 deletions its-a-smol-world-mcp/mcp-server/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Demo")

# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b

# Add a text messaging tool
@mcp.tool()
def send_text(to: str, message: str) -> str:
"""Send a text message to a contact"""
# In a real application, this would integrate with a messaging service
return f"Message sent to {to}: {message}"

# Add a food ordering tool
@mcp.tool()
def order_food(restaurant: str, item: str, quantity: int) -> str:
"""Order food from a restaurant"""
# In a real application, this would integrate with a food ordering service
return f"Ordered {quantity} {item}(s) from {restaurant}."

# Add a ride ordering tool
@mcp.tool()
def order_ride(dest: str) -> str:
"""Order a ride from a ride sharing service"""
# In a real application, this would integrate with a ride sharing service
return f"Ride ordered to {dest}. Your driver will arrive in 5 minutes."

# Add a weather information tool
@mcp.tool()
def get_weather(city: str) -> str:
"""Get the weather for a city"""
# In a real application, this would integrate with a weather API
# Using placeholder response for demo purposes
weather_data = {
"New York": "Partly cloudy, 72°F",
"San Francisco": "Foggy, 58°F",
"Los Angeles": "Sunny, 82°F",
"Chicago": "Windy, 55°F",
"Miami": "Rainy, 80°F"
}
return weather_data.get(city, f"Weather information for {city} is not available.")

if __name__ == "__main__":
# Initialize and run the server
mcp.run(transport='stdio')
6 changes: 6 additions & 0 deletions its-a-smol-world-mcp/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
outlines==0.2.3
mcp==1.6.0
transformers
sentencepiece
datasets
accelerate>=0.26.0
Empty file.
74 changes: 74 additions & 0 deletions its-a-smol-world-mcp/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import time
import itertools
import threading
import sys
import argparse
import asyncio
from smol_mind import SmolMind
from constants import MODEL_NAME

# Thanks to @torymur for the bunny ascii art!
bunny_ascii = r"""
(\(\
( -.-)
o_(")(")
"""

def spinner(stop_event):
spinner = itertools.cycle(['-', '/', '|', '\\'])
while not stop_event.is_set():
sys.stdout.write(next(spinner))
sys.stdout.flush()
sys.stdout.write('\b')
time.sleep(0.1)

async def main():
# Add command-line argument parsing
parser = argparse.ArgumentParser(description="SmolMind MCP Client")
parser.add_argument('server_path', help='Path to the MCP server script (.py or .js)')
parser.add_argument('-d', '--debug', action='store_true', help='Enable debug mode')
args = parser.parse_args()

print("Loading SmolMind MCP client...")
sm = SmolMind(args.server_path, model_name=MODEL_NAME, debug=args.debug)

try:
# Connect to the server
tools = await sm.connect_to_server()
if args.debug:
print("Using model:", sm.model_name)
print("Debug mode:", "Enabled" if args.debug else "Disabled")
print(f"Available tools: {[tool.name for tool in tools]}")

print(bunny_ascii)
print("Welcome to the Bunny B1 MCP Client! What do you need?")

while True:
user_input = input("> ")
if user_input.lower() in ["exit", "quit"]:
print("Goodbye!")
break

# Create a shared event to stop the spinner
stop_event = threading.Event()

# Start the spinner in a separate thread
spinner_thread = threading.Thread(target=spinner, args=(stop_event,))
spinner_thread.daemon = True
spinner_thread.start()

try:
response = await sm.process_query(user_input)
finally:
# Stop the spinner
stop_event.set()
spinner_thread.join()
sys.stdout.write(' \b') # Erase the spinner

print(response)
finally:
# Ensure we close the connection
await sm.close()

if __name__ == "__main__":
asyncio.run(main())
3 changes: 3 additions & 0 deletions its-a-smol-world-mcp/src/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODEL_NAME = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
DEVICE = "cuda"
T_TYPE = "bfloat16"
Loading