forked from block/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecipe-inline-python.yaml
More file actions
87 lines (74 loc) · 2.73 KB
/
recipe-inline-python.yaml
File metadata and controls
87 lines (74 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
version: "1.0.0"
title: "Word Counter"
description: "A recipe that counts words in text using an inline Python extension"
instructions: |
This recipe provides a simple word counting tool. You can:
1. Count words in a text string
2. Get statistics about the text (unique words, average word length)
3. Generate word clouds from the text
parameters:
- key: text
input_type: string
requirement: required
description: "The text to analyze"
extensions:
- type: inline_python
name: word_counter
code: |
from mcp.server.fastmcp import FastMCP
import json
from collections import Counter
import numpy as np
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import base64
from io import BytesIO
mcp = FastMCP("word_counter")
@mcp.tool()
def count_words(text: str) -> str:
"""Count the number of words in a text string and generate statistics"""
words = text.split()
word_count = len(words)
unique_words = len(set(words))
avg_length = sum(len(word) for word in words) / word_count if word_count > 0 else 0
# Generate word cloud
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# Save word cloud to base64
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
# Save to bytes
buf = BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0)
buf.seek(0)
img_base64 = base64.b64encode(buf.getvalue()).decode()
plt.close()
result = {
"total_words": word_count,
"unique_words": unique_words,
"average_word_length": round(avg_length, 2),
"most_common": dict(Counter(words).most_common(5)),
"wordcloud_base64": img_base64
}
return json.dumps(result, indent=2)
if __name__ == "__main__":
mcp.run()
timeout: 300
description: "Count words and provide text statistics with visualization"
dependencies:
- "mcp"
- "numpy"
- "matplotlib"
- "wordcloud"
- "beautifulsoup4"
- "html2text"
- "requests"
prompt: |
You are a helpful assistant that can analyze text using word counting tools.
The user has provided the following text to analyze: {{ text }}
Use the word_counter__count_words tool to analyze this text and provide insights about:
- Total word count
- Number of unique words
- Average word length
- Most commonly used words
- A word cloud visualization of the text