mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-11-03 20:01:50 +00:00 
			
		
		
		
	Remove last empty line in GetFileContentFn (#80)
Normally, each file should be end with a blank line, but git does not consider it as a new line, so we should not return it to llm, or it may generate wrong information when editing the existing file. Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/80 Reviewed-by: hiifong <i@hiif.ong> Co-authored-by: yp05327 <576951401@qq.com> Co-committed-by: yp05327 <576951401@qq.com>
This commit is contained in:
		@@ -149,6 +149,16 @@ func GetFileContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo
 | 
			
		||||
			})
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		if err := scanner.Err(); err != nil {
 | 
			
		||||
			return to.ErrorResult(fmt.Errorf("scan content err: %v", err))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// remove the last blank line if exists
 | 
			
		||||
		// git does not consider the last line as a new line
 | 
			
		||||
		if contentLines[len(contentLines)-1].Content == "" {
 | 
			
		||||
			contentLines = contentLines[:len(contentLines)-1]
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		contentBytes, err := json.MarshalIndent(contentLines, "", "  ")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return to.ErrorResult(fmt.Errorf("marshal content lines err: %v", err))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user