rednote_analyze_content
Analyze content text to identify sentiment, extract keywords, and categorize information using multiple analysis types.
Instructions
分析内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | 内容文本 | |
| analysis_type | No | 分析类型 | all |
Implementation Reference
- src/tools/analysis.ts:12-44 (handler)The primary handler function for the 'rednote_analyze_content' tool. It validates input parameters and calls the RedNoteApi to perform the content analysis, then formats the response.async analyzeContent(params: any) { try { validateNotEmpty(params.content, 'content'); validateString(params.content, 'content'); if (params.analysis_type) { validateEnum(params.analysis_type, 'analysis_type', ['sentiment', 'keywords', 'category', 'all']); } logger.info('Executing analyze content tool', { contentLength: params.content.length, analysisType: params.analysis_type }); const result = await this.api.analyzeContent(params.content, params.analysis_type || 'all'); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { logger.error('Error in analyzeContent tool:', error); return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}` }], isError: true }; } }
- src/types/mcp.ts:127-146 (schema)The input schema definition for the 'rednote_analyze_content' tool, including properties for content and analysis_type.rednote_analyze_content: { name: 'rednote_analyze_content', description: '分析内容', inputSchema: { type: 'object', properties: { content: { type: 'string', description: '内容文本' }, analysis_type: { type: 'string', enum: ['sentiment', 'keywords', 'category', 'all'], description: '分析类型', default: 'all' } }, required: ['content'] } }
- src/server.ts:73-74 (registration)Switch case in the tool request handler that registers and dispatches calls to the 'rednote_analyze_content' tool handler.case 'rednote_analyze_content': return await this.analysisTools.analyzeContent(params);
- src/api/rednote.ts:94-121 (helper)Core implementation of content analysis logic, generating mock results for sentiment, keywords, and category based on the specified analysis_type.async analyzeContent(content: string, analysisType: string = 'all'): Promise<AnalysisResult> { logger.info('Analyzing content', { contentLength: content.length, analysisType }); try { const result: AnalysisResult = {}; if (analysisType === 'sentiment' || analysisType === 'all') { result.sentiment = { score: Math.random() * 2 - 1, label: Math.random() > 0.5 ? 'positive' : 'negative', confidence: Math.random() }; } if (analysisType === 'keywords' || analysisType === 'all') { result.keywords = this.extractKeywords(); } if (analysisType === 'category' || analysisType === 'all') { result.category = this.predictCategory(); } return result; } catch (error) { logger.error('Error analyzing content:', error); throw new Error(`Failed to analyze content: ${error}`); } }
- src/api/rednote.ts:178-186 (helper)Helper functions used by analyzeContent for extracting keywords and predicting category in a mock manner.private extractKeywords(): string[] { const commonWords = ['美食', '分享', '推荐', '好吃', '简单', '健康', '生活', '时尚', '美丽']; return commonWords.filter(() => Math.random() > 0.5).slice(0, 5); } private predictCategory(): string { const categories = ['美食', '时尚', '旅行', '生活', '美妆', '健身']; return categories[Math.floor(Math.random() * categories.length)]; }