# LangSearch MCP Server - Tool Reference
## Tool 1: langsearch_web_search
Searches the web using LangSearch's powerful Web Search API.
### Input Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | The search query (max 400 characters, 50 words) |
| `freshness` | string | No | Filter by freshness: `noLimit` (default), `onLimit`, `day`, `week`, `month` |
| `summary` | boolean | No | Include full summaries in results (default: `true`) |
| `count` | number | No | Number of results (1-50, default: 10) |
### Output
Returns structured search results including:
- Original query context
- List of web pages with:
- Title
- URL
- Snippet
- Full summary (if requested)
- Metadata (publish date, crawl date)
- Search URL for reference
- Result statistics
### Example Usage
```json
{
"name": "langsearch_web_search",
"arguments": {
"query": "latest AI breakthroughs 2024",
"freshness": "month",
"summary": true,
"count": 5
}
}
```
### Use Cases
- Research current events and news
- Find technical documentation
- Gather information on specific topics
- Get comprehensive summaries of web content
- Filter results by recency
---
## Tool 2: langsearch_semantic_rerank
Reranks documents based on semantic relevance using LangSearch's Semantic Rerank API.
### Input Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `query` | string | Yes | The search query to compare against documents |
| `documents` | array[string] | Yes | List of document texts to rerank (at least 1) |
| `top_n` | number | No | Number of top results to return (default: all) |
| `return_documents` | boolean | No | Include document text in response (default: `true`) |
### Output
Returns reranked results including:
- Model name used
- List of results ordered by relevance:
- Original document index
- Relevance score (0-1, higher = more relevant)
- Document text (if requested)
### Example Usage
```json
{
"name": "langsearch_semantic_rerank",
"arguments": {
"query": "machine learning optimization techniques",
"documents": [
"Deep learning models require careful hyperparameter tuning.",
"The weather today is sunny and warm.",
"Gradient descent is fundamental to neural network training.",
"Pizza is a popular Italian dish."
],
"top_n": 2,
"return_documents": true
}
}
```
### Use Cases
- Improve search result quality
- Find most relevant content from a set of documents
- Rank candidate answers by relevance
- Filter out irrelevant content
- Enhance RAG (Retrieval-Augmented Generation) pipelines
---
## Workflow: Combining Both Tools
A powerful pattern is to use web search followed by semantic reranking:
1. **Search**: Use `langsearch_web_search` to gather initial results
2. **Extract**: Extract snippets or summaries from results
3. **Rerank**: Use `langsearch_semantic_rerank` to reorder by semantic relevance
4. **Present**: Show the most relevant results first
### Example Workflow
```javascript
// Step 1: Search for information
const searchResults = await langsearch_web_search({
query: "benefits of renewable energy",
count: 10,
summary: true
});
// Step 2: Extract summaries
const documents = searchResults.webPages.value.map(page =>
page.summary || page.snippet
);
// Step 3: Rerank by relevance to specific aspect
const rerankedResults = await langsearch_semantic_rerank({
query: "economic benefits of renewable energy",
documents: documents,
top_n: 3
});
// Step 4: Use top 3 most relevant results
```
---
## Error Handling
Both tools return errors in a consistent format:
```json
{
"content": [{
"type": "text",
"text": "Error description here"
}],
"isError": true
}
```
Common errors:
- Invalid API key
- Network connectivity issues
- Invalid parameters
- API rate limits
- Empty document arrays (rerank)
---
## Best Practices
### Web Search
- Be specific with queries for better results
- Use `freshness` filters for time-sensitive topics
- Enable `summary: true` for comprehensive content
- Adjust `count` based on your needs (higher = more thorough but slower)
### Semantic Rerank
- Provide clear, specific queries
- Ensure documents are relevant to the general topic
- Use `top_n` to limit results when you only need the best matches
- Consider the relevance score threshold (e.g., > 0.5 for strong matches)
### Performance
- Cache search results when possible
- Batch similar queries together
- Use appropriate `count` limits
- Monitor API usage and rate limits
---
## Rate Limits
Refer to your LangSearch API plan for rate limit details. The server handles rate limit errors gracefully.
## Support
- API Documentation: https://docs.langsearch.com/
- Web Search API: https://docs.langsearch.com/api/web-search-api
- Semantic Rerank API: https://docs.langsearch.com/api/semantic-rerank-api