Skip to content

Commit

Permalink
🎨 Improve MCP prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Jan 27, 2025
1 parent de017d3 commit 17d8b50
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 21 deletions.
130 changes: 112 additions & 18 deletions examples/html-extract/fetch-html.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,77 @@ long: |
and limiting the size of lists and tables. This is useful for getting a cleaner,
more readable version of web content.
The tool accepts input as JSON with the following structure:
```json
{
"urls": ["https://example.com", "https://another-site.com"],
"max_list_items": 4,
"max_table_rows": 4,
"remove_selectors": [
"div[role='banner']",
".usa-banner",
".navigation-menu",
"footer"
],
"keep_selectors": [
"article.main-content",
".article-body"
]
}
```
Examples:
1. Basic usage - fetch a single URL:
```json
{
"urls": ["https://example.com/article"]
}
```
2. Remove navigation and UI elements:
```json
{
"urls": ["https://news-site.com/story"],
"remove_selectors": [
"header",
"nav",
".sidebar",
".ads",
"footer",
".social-share"
]
}
```
3. Keep only main content:
```json
{
"urls": ["https://blog.com/post"],
"keep_selectors": [
"article.post-content",
".post-body"
]
}
```
4. Complex filtering with list limits:
```json
{
"urls": ["https://docs.example.com"],
"max_list_items": 5,
"max_table_rows": 3,
"remove_selectors": [
".navigation",
".search-box"
],
"keep_selectors": [
".documentation-content",
".code-examples"
]
}
```
flags:
- name: urls
type: stringList
Expand All @@ -18,24 +89,47 @@ flags:
type: int
help: Maximum number of rows to show in tables (0 for unlimited)
default: 4
- name: remove_selectors
type: stringList
help: CSS selectors for elements to remove
default: []
- name: keep_selectors
type: stringList
help: CSS selectors for elements to keep (everything else will be removed)
default: []


command:
- simplify-html
- simplify
- --urls
- "{{ range $i, $url := .Args.urls }}{{ if $i }},{{ end }}{{ $url }}{{ end }}"
- --max-list-items
- "{{ .Args.max_list_items }}"
- --max-table-rows
- "{{ .Args.max_table_rows }}"

# shell-script: |
shell-script: |
#!/bin/bash
set -euo pipefail
# Create temporary config file
CONFIG_FILE=$(mktemp)
trap 'rm -f "$CONFIG_FILE"' EXIT
# Generate filter config YAML
cat > "$CONFIG_FILE" << 'EOL'
selectors:
{{ range .Args.keep_selectors }}
- type: css
mode: select
selector: "{{ . }}"
{{ end }}
{{ range .Args.remove_selectors }}
- type: css
mode: filter
selector: "{{ . }}"
{{ end }}
EOL
# #!/bin/bash
# set -euo pipefail
export RUNTIME_TEMP_CONFIG_FILE="$CONFIG_FILE"
# # Process each URL
# for url in {{ range .Args.urls }}"{{ . }}" {{ end }}; do
# echo "Fetching $url..."
# simplify-html simplify --urls "$url" --max-list-items "{{ .Args.max_list_items }}" --max-table-rows "{{ .Args.max_table_rows }}"
# done
# Process each URL
for url in {{ range .Args.urls }}"{{ . }}" {{ end }}; do
echo "Fetching $url..."
simplify-html simplify \
--urls "$url" \
--max-list-items "{{ .Args.max_list_items }}" \
--max-table-rows "{{ .Args.max_table_rows }}" \
--config "$CONFIG_FILE"
done
14 changes: 11 additions & 3 deletions examples/html-extract/html-extraction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ flags:
default: false

shell-script: |
#!/bin/bash
set -euo pipefail
# Create temporary config file
CONFIG_FILE=$(mktemp)
trap 'rm -f $CONFIG_FILE' EXIT
echo '{{ .Args.config }}' > $CONFIG_FILE
trap 'rm -f "$CONFIG_FILE"' EXIT
# Generate config file with heredoc to handle special characters better
cat > "$CONFIG_FILE" << 'EOL'
{{ .Args.config }}
EOL
# Log config file with timestamp for replay
LOG_FILE="/tmp/html-extraction-$(date '+%Y-%m-%d-%H-%M-%S').yaml"
cp "$CONFIG_FILE" "$LOG_FILE"
html-selector select \
--urls {{ range .Args.urls }}{{ . }} {{ end }} \
--config $CONFIG_FILE \
--config "$CONFIG_FILE" \
{{ if .Args.show_context }}--show-context{{ end }} \
{{ if .Args.show_path }}--show-path{{ end }} \

0 comments on commit 17d8b50

Please sign in to comment.