npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

agent-conversation-logger

v1.0.8

Published

一个MCP服务,用于将与AI Agent的对话历史记录到Markdown文件中

Readme

Agent Conversation Logger

这是一个简单的 MCP (Model Context Protocol) 服务,用于将与 AI Agent 的对话历史记录到 Markdown 文件中。

功能特点

  • 将用户与 AI 的对话自动保存到 Markdown 文件
  • 支持自定义保存路径
  • 可配置时间戳记录
  • 支持创建新的对话会话
  • 符合 MCP 接口规范,可作为中间件使用
  • 支持作为 VSCode MCP 服务集成

安装

npm install agent-conversation-logger

使用方法

方法 1:直接使用 ConversationLogger

const { ConversationLogger } = require('agent-conversation-logger');

// 创建对话记录器实例
const logger = new ConversationLogger({
  filePath: './logs/conversation.md',  // 自定义文件保存路径
  appendTimestamp: true,              // 是否添加时间戳
  createIfNotExists: true             // 如果文件不存在是否创建
});

// 创建新的对话会话(可选)
logger.newSession('用户问题解答');

// 记录对话
logger.logHuman('你好,能帮我解答一个问题吗?');
logger.logAssistant('当然可以,请告诉我你的问题。');

方法 2:作为 MCP 服务使用

const { createMCPService } = require('agent-conversation-logger');

// 创建 MCP 服务实例
const mcpService = createMCPService({
  filePath: './logs/agent-conversations.md'
});

// 将服务集成到你的 AI 应用中
async function handleChatCompletion(req, res) {
  // 处理请求前记录对话
  const modifiedRequest = await mcpService.handleChatRequest(req.body);
  
  // 调用 AI 服务获取响应
  const aiResponse = await callAIService(modifiedRequest);
  
  // 处理响应并记录 AI 回复
  const loggedResponse = await mcpService.handleChatResponse(aiResponse);
  
  res.json(loggedResponse);
}

方法 3:在 VSCode 中配置使用

在 VSCode 的 settings.json 文件中,你可以添加以下配置来集成这个对话记录 MCP 服务:

{
  "mcp": {
    "servers": {
      "conversationLogger": {
        "command": "npx",
        "args": [
          "agent-conversation-logger",
          "--file",
          "${workspaceFolder}/conversation-history.md"
        ]
      }
    }
  }
}

你也可以全局安装后使用:

{
  "mcp": {
    "servers": {
      "conversationLogger": {
        "command": "agent-conversation-logger",
        "args": [
          "--file",
          "${workspaceFolder}/conversation-history.md"
        ]
      }
    }
  }
}

可用的命令行参数

  • --file, -f <路径>: 指定记录对话的Markdown文件路径
  • --no-timestamp: 不在对话中添加时间戳
  • --help, -h: 显示帮助信息

配置选项

可用的配置选项包括:

| 选项 | 类型 | 默认值 | 描述 | |------|------|--------|------| | filePath | string | './conversation-history.md' | Markdown 文件保存路径 | | createIfNotExists | boolean | true | 如果文件或目录不存在,是否自动创建 | | appendTimestamp | boolean | true | 是否在每次对话前添加时间戳 |

发布到 NPM

如果你想将此包发布到 NPM,请按照以下步骤操作:

  1. 确保你已经创建了 NPM 账号并登录
npm login
  1. 更新 package.json 中的个人信息

    • 修改 "author" 字段为你的名字和邮箱
    • 修改 "repository" 字段为你的 GitHub 仓库地址
  2. 发布包

npm publish

作为依赖集成到 Agent

要将此 MCP 服务集成到 AI Agent 系统中,你可以将其作为中间件添加到处理对话的流程中:

const { MCPService } = require('agent-conversation-logger');

// 配置 MCP 服务
const loggingService = new MCPService({
  filePath: './logs/agent-logs.md'
});

// AI 对话处理管道
async function processConversation(messages) {
  // 记录用户输入
  const processedRequest = await loggingService.handleChatRequest({ messages });
  
  // AI 生成回复
  const aiResponse = await generateAIResponse(processedRequest.messages);
  
  // 记录 AI 回复
  const processedResponse = await loggingService.handleChatResponse({
    message: {
      role: 'assistant',
      content: aiResponse
    }
  });
  
  return processedResponse.message.content;
}

示例

查看项目中的 example.js 文件获取更详细的使用示例。

许可证

MIT